diff --git a/App.tsx b/App.tsx index c945896..075e9c6 100644 --- a/App.tsx +++ b/App.tsx @@ -1,73 +1,329 @@ -import React, {useEffect, useState} from 'react'; -import {View, Text, Alert, BackHandler} from 'react-native'; -// import CodePush from '@chlee1001/react-native-code-push'; -import {version as currentVersion} from './package.json'; -import CodePush from '@chlee1001/react-native-code-push'; +import React, { useState, useEffect } from 'react'; +import { + View, + Text, + StyleSheet, + TouchableOpacity, + ScrollView, + Alert, + SafeAreaView, + StatusBar, + LogBox, +} from 'react-native'; +import { colors } from './src/theme/colors'; +import { spacing } from './src/theme/spacing'; +import { typography } from './src/theme/typography'; +import Button from './src/components/buttons/Button'; +import Card from './src/components/cards/Card'; +import { analyticsService } from './src/utils/analytics'; +import { version as currentVersion } from './package.json'; +import CodePush from '@appcircle/react-native-code-push'; import Snackbar from './src/components/common/snackbar'; -// import Snackbar from './src/components/common/snackbar.tsx'; -// import CodePush from '@chlee1001/react-native-code-push'; -// import { useCodePush } from './src/hooks/useCodePush.ts'; +import { featureFlagsService } from './src/utils/featureFlags'; + +// Ignore specific LogBox warnings +LogBox.ignoreLogs([ + 'VirtualizedLists should never be nested', + 'Warning: componentWillReceiveProps has been renamed', +]); + +type TabType = 'home' | 'feed' | 'notifications' | 'profile'; const App: React.FC = () => { + const [activeTab, setActiveTab] = useState('home'); const [snackbarVisible, setSnackbarVisible] = useState(false); - // const {isUpdateDownloaded} = useCodePush(); + const [updateAvailable, setUpdateAvailable] = useState(false); - useEffect(() => { + const handleCodePushSync = (showAlerts = false) => { CodePush.sync( { installMode: CodePush.InstallMode.ON_NEXT_RESTART, }, (syncStatus) => { - // Güncelleme yüklendiyse snackbar'ı göster - if (syncStatus === CodePush.SyncStatus.UPDATE_INSTALLED) { - setSnackbarVisible(true); + switch(syncStatus) { + case CodePush.SyncStatus.CHECKING_FOR_UPDATE: + if (showAlerts) Alert.alert('Checking for updates...'); + setUpdateAvailable(true); + break; + case CodePush.SyncStatus.DOWNLOADING_PACKAGE: + if (showAlerts) Alert.alert('Downloading update...'); + break; + case CodePush.SyncStatus.INSTALLING_UPDATE: + if (showAlerts) Alert.alert('Installing update...'); + break; + case CodePush.SyncStatus.UPDATE_INSTALLED: + if (showAlerts) { + Alert.alert( + 'Update Installed', + 'The app has been updated. Would you like to restart now?', + [ + { + text: 'Later', + style: 'cancel' + }, + { + text: 'Restart Now', + onPress: () => CodePush.restartApp() + } + ] + ); + } + break; + case CodePush.SyncStatus.UP_TO_DATE: + if (showAlerts) Alert.alert('App is up to date!'); + setUpdateAvailable(false); + break; + case CodePush.SyncStatus.UNKNOWN_ERROR: + if (showAlerts) Alert.alert('An error occurred while checking for updates'); + break; } } ); - }, []); + }; - // Press the back button to exit the app useEffect(() => { - const backAction = () => { - Alert.alert('알림', '앱 종료', [ - { - text: '취소', - onPress: () => null, - style: 'cancel', - }, - {text: '확인', onPress: () => BackHandler.exitApp()}, - ]); - return true; - }; - const backHandler = BackHandler.addEventListener( - 'hardwareBackPress', - backAction, - ); - return () => backHandler.remove(); + try { + // Initialize analytics + analyticsService.startNewSession(); + analyticsService.setEnabled(featureFlagsService.isEnabled('enableAnalytics')); + analyticsService.trackEvent('app_launched'); + + // Check for CodePush updates + handleCodePushSync(); + + // Check update status + const checkUpdateStatus = async () => { + try { + const update = await CodePush.getUpdateMetadata(); + if (update) { + analyticsService.trackEvent('codepush_update_status', { + label: update.label, + description: update.description, + isFirstRun: update.isFirstRun, + }); + } + } catch (error) { + console.error('Error checking update status:', error); + } + }; + + checkUpdateStatus(); + } catch (error) { + console.error('Error in app initialization:', error); + } }, []); + const handleTabChange = (tab: TabType) => { + setActiveTab(tab); + analyticsService.trackEvent('tab_change', { tab }); + }; + + const checkForUpdates = () => { + handleCodePushSync(true); + analyticsService.trackEvent('check_for_updates'); + }; + + const renderHomeScreen = () => ( + + + Welcome to CodePush 16 may test 3 + Current Version: {currentVersion} + +