From 59724a0947c25bfa3aa16bd4a97bd5449e87bbcd Mon Sep 17 00:00:00 2001
From: Akshay Nair <phenax5@gmail.com>
Date: Sat, 5 Oct 2024 23:27:42 +0530
Subject: Refactor app view screens

---
 src/AppView.tsx | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

(limited to 'src/AppView.tsx')

diff --git a/src/AppView.tsx b/src/AppView.tsx
index cca64f6..2f8e0b2 100644
--- a/src/AppView.tsx
+++ b/src/AppView.tsx
@@ -3,15 +3,30 @@ 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
@@ -20,8 +35,9 @@ export const AppView: React.FC = React.memo(() => {
       dot={<></>}
       activeDot={<></>}
       onIndexChanged={setScreenIndex}>
-      <Home active={screenIndex === 0} />
-      <AppList active={screenIndex === 1} />
+      {screens.map(({id, component: Screen}, i) => (
+        <Screen key={id} active={screenIndex === i} />
+      ))}
     </Swiper>
   );
 });
-- 
cgit v1.3.1

