1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Rewrite timeline logic

This commit is contained in:
Zhiyuan Zheng
2021-02-27 16:33:54 +01:00
parent 45681fc1f5
commit f3fa6bc662
67 changed files with 1980 additions and 1395 deletions

View File

@ -15,16 +15,47 @@ import { getInstanceActive } from '@utils/slices/instancesSlice'
import { useTheme } from '@utils/styles/ThemeManager'
import { themes } from '@utils/styles/themes'
import * as Analytics from 'expo-firebase-analytics'
// import { addScreenshotListener } from 'expo-screen-capture'
import * as Notifications from 'expo-notifications'
import { addScreenshotListener } from 'expo-screen-capture'
import React, { createRef, useCallback, useEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { Platform, StatusBar } from 'react-native'
import { Alert, Linking, Platform, StatusBar } from 'react-native'
import { createNativeStackNavigator } from 'react-native-screens/native-stack'
import Toast from 'react-native-toast-message'
import { useDispatch, useSelector } from 'react-redux'
import * as Sentry from 'sentry-expo'
const Stack = createNativeStackNavigator<Nav.RootStackParamList>()
const linking = {
prefixes: ['tooot://', 'https://tooot.app'],
config: {
screens: {
'Screen-Tabs': {
screens: {
'Tab-Notifications': 'push/:id'
}
}
}
},
subscribe (listener: (arg0: string) => any) {
const onReceiveURL = ({ url }: { url: string }) => listener(url)
Linking.addEventListener('url', onReceiveURL)
const subscription = Notifications.addNotificationResponseReceivedListener(
response => {
const url = response.notification.request.content.data.url
console.log(url)
url && typeof url === 'string' && listener(url)
}
)
return () => {
Linking.removeEventListener('url', onReceiveURL)
subscription.remove()
}
}
}
export interface Props {
localCorrupt?: string
}
@ -57,15 +88,15 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
// }, [isConnected, firstRender])
// Prevent screenshot alert
// useEffect(() => {
// const screenshotListener = addScreenshotListener(() =>
// Alert.alert(t('screenshot.title'), t('screenshot.message'), [
// { text: t('screenshot.button'), style: 'destructive' }
// ])
// )
// Platform.OS === 'ios' && screenshotListener
// return () => screenshotListener.remove()
// }, [])
useEffect(() => {
const screenshotListener = addScreenshotListener(() =>
Alert.alert(t('screenshot.title'), t('screenshot.message'), [
{ text: t('screenshot.button'), style: 'destructive' }
])
)
Platform.select({ ios: screenshotListener })
return () => screenshotListener.remove()
}, [])
// On launch display login credentials corrupt information
useEffect(() => {
@ -127,6 +158,10 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
if (previousRouteName !== currentRouteName) {
Analytics.setCurrentScreen(currentRouteName)
Sentry.Native.setContext('page', {
previous: previousRouteName,
current: currentRouteName
})
}
routeNameRef.current = currentRouteName
@ -140,6 +175,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
theme={themes[mode]}
onReady={navigationContainerOnReady}
onStateChange={navigationContainerOnStateChange}
linking={linking}
>
<Stack.Navigator initialRouteName='Screen-Tabs'>
<Stack.Screen
@ -185,9 +221,9 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
/>
</Stack.Navigator>
{Platform.OS === 'ios' ? (
<Toast ref={Toast.setRef} config={toastConfig} />
) : null}
{Platform.select({
ios: <Toast ref={Toast.setRef} config={toastConfig} />
})}
</NavigationContainer>
</>
)