a712100cfc
Closes #1500 Closes #1210 Closes #1244 Closes #1110
123 lines
3.0 KiB
TypeScript
123 lines
3.0 KiB
TypeScript
import 'react-native-url-polyfill/auto';
|
|
import { enableFreeze } from 'react-native-screens';
|
|
|
|
enableFreeze(true);
|
|
|
|
import React, { useEffect } from 'react';
|
|
import { StatusBar, StyleSheet } from 'react-native';
|
|
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
import LottieSplashScreen from 'react-native-lottie-splash-screen';
|
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
import { Provider as PaperProvider } from 'react-native-paper';
|
|
import * as Notifications from 'expo-notifications';
|
|
|
|
import AppErrorBoundary, {
|
|
ErrorFallback,
|
|
} from '@components/AppErrorBoundary/AppErrorBoundary';
|
|
import { useDatabaseInitialization } from '@hooks';
|
|
|
|
import Main from './src/navigators/Main';
|
|
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
|
|
|
|
Notifications.setNotificationHandler({
|
|
handleNotification: async () => {
|
|
return {
|
|
shouldPlaySound: false,
|
|
shouldSetBadge: false,
|
|
shouldShowBanner: true,
|
|
shouldShowList: true,
|
|
};
|
|
},
|
|
});
|
|
|
|
Notifications.setNotificationCategoryAsync('TTS_CONTROLS', [
|
|
{
|
|
identifier: 'TTS_PLAY_PAUSE',
|
|
buttonTitle: '▶️ Play',
|
|
options: {
|
|
opensAppToForeground: false,
|
|
},
|
|
},
|
|
{
|
|
identifier: 'TTS_STOP',
|
|
buttonTitle: '⏹️ Stop',
|
|
options: {
|
|
opensAppToForeground: false,
|
|
},
|
|
},
|
|
{
|
|
identifier: 'TTS_NEXT',
|
|
buttonTitle: '⏭️ Next',
|
|
options: {
|
|
opensAppToForeground: false,
|
|
},
|
|
},
|
|
]);
|
|
|
|
Notifications.setNotificationChannelAsync('tts-controls', {
|
|
name: 'TTS Controls',
|
|
description: 'Text-to-Speech playback controls',
|
|
importance: Notifications.AndroidImportance.HIGH,
|
|
vibrationPattern: [],
|
|
enableLights: false,
|
|
enableVibrate: false,
|
|
});
|
|
|
|
const App = () => {
|
|
const { isDbReady, dbError, retryInitialization } =
|
|
useDatabaseInitialization();
|
|
|
|
useEffect(() => {
|
|
if (isDbReady || dbError) {
|
|
LottieSplashScreen.hide();
|
|
}
|
|
}, [isDbReady, dbError]);
|
|
|
|
useEffect(() => {
|
|
const subscription = Notifications.addNotificationResponseReceivedListener(
|
|
response => {
|
|
const actionIdentifier = response.actionIdentifier;
|
|
if (actionIdentifier.startsWith('TTS_')) {
|
|
const { setTTSAction } = require('@utils/ttsNotification');
|
|
setTTSAction(actionIdentifier);
|
|
}
|
|
},
|
|
);
|
|
|
|
return () => {
|
|
subscription.remove();
|
|
};
|
|
}, []);
|
|
|
|
if (dbError) {
|
|
return <ErrorFallback error={dbError} resetError={retryInitialization} />;
|
|
}
|
|
|
|
if (!isDbReady) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<GestureHandlerRootView style={styles.flex}>
|
|
<AppErrorBoundary>
|
|
<SafeAreaProvider>
|
|
<PaperProvider>
|
|
<BottomSheetModalProvider>
|
|
<StatusBar translucent={true} backgroundColor="transparent" />
|
|
<Main />
|
|
</BottomSheetModalProvider>
|
|
</PaperProvider>
|
|
</SafeAreaProvider>
|
|
</AppErrorBoundary>
|
|
</GestureHandlerRootView>
|
|
);
|
|
};
|
|
|
|
export default App;
|
|
|
|
const styles = StyleSheet.create({
|
|
flex: {
|
|
flex: 1,
|
|
},
|
|
});
|