aboutsummaryrefslogtreecommitdiff
path: root/src/AppView.tsx
blob: 2f8e0b2b35e4c7e2aa2610cd04ae75528455f072 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import React, {useEffect, useState} from 'react';
import Swiper from 'react-native-swiper';
import {AppList} from './screens/AppList';
import {Home} from './screens/Home';
import {useInstalledApps} from './hooks/useInstalledApps';
import {BackHandler} from 'react-native';

const screens = [
  {id: 'home', component: Home},
  {id: 'appList', component: AppList},
];

export const AppView: React.FC = React.memo(() => {
  const {refreshApps} = useInstalledApps();
  const [screenIndex, setScreenIndex] = useState(0);

  // Refresh app list when switching between screens
  useEffect(() => {
    refreshApps();
  }, [screenIndex, refreshApps]);

  // Disable back button
  useEffect(() => {
    const sub = BackHandler.addEventListener('hardwareBackPress', () => {
      return true;
    });
    return () => sub.remove();
  }, []);

  return (
    <Swiper
      horizontal
      autoplay={false}
      loop={false}
      dot={<></>}
      activeDot={<></>}
      onIndexChanged={setScreenIndex}>
      {screens.map(({id, component: Screen}, i) => (
        <Screen key={id} active={screenIndex === i} />
      ))}
    </Swiper>
  );
});