mirror of
https://github.com/tooot-app/app
synced 2025-03-04 19:47:49 +01:00
Use splash screen
Fetch account preferences again after logging in
This commit is contained in:
parent
8ed008b961
commit
ce7563ecbc
30
App.tsx
30
App.tsx
@ -1,4 +1,5 @@
|
|||||||
import React from 'react'
|
import * as SplashScreen from 'expo-splash-screen'
|
||||||
|
import React, { useEffect, useState } from 'react'
|
||||||
import { AppearanceProvider } from 'react-native-appearance'
|
import { AppearanceProvider } from 'react-native-appearance'
|
||||||
import { QueryCache, ReactQueryCacheProvider, setConsole } from 'react-query'
|
import { QueryCache, ReactQueryCacheProvider, setConsole } from 'react-query'
|
||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
@ -26,6 +27,30 @@ setConsole({
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
const App: React.FC = () => {
|
const App: React.FC = () => {
|
||||||
|
const [appLoaded, setAppLoaded] = useState(false)
|
||||||
|
useEffect(() => {
|
||||||
|
const delaySplash = async () => {
|
||||||
|
try {
|
||||||
|
await SplashScreen.preventAutoHideAsync()
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delaySplash()
|
||||||
|
}, [])
|
||||||
|
useEffect(() => {
|
||||||
|
const hideSplash = async () => {
|
||||||
|
try {
|
||||||
|
await SplashScreen.hideAsync()
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (appLoaded) {
|
||||||
|
hideSplash()
|
||||||
|
}
|
||||||
|
}, [appLoaded])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppearanceProvider>
|
<AppearanceProvider>
|
||||||
<ReactQueryCacheProvider queryCache={queryCache}>
|
<ReactQueryCacheProvider queryCache={queryCache}>
|
||||||
@ -33,6 +58,7 @@ const App: React.FC = () => {
|
|||||||
<PersistGate persistor={persistor}>
|
<PersistGate persistor={persistor}>
|
||||||
{bootstrapped => {
|
{bootstrapped => {
|
||||||
if (bootstrapped) {
|
if (bootstrapped) {
|
||||||
|
setAppLoaded(true)
|
||||||
require('@root/i18n/i18n')
|
require('@root/i18n/i18n')
|
||||||
return (
|
return (
|
||||||
<ThemeManager>
|
<ThemeManager>
|
||||||
@ -40,7 +66,7 @@ const App: React.FC = () => {
|
|||||||
</ThemeManager>
|
</ThemeManager>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
return <></>
|
return null
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
</PersistGate>
|
</PersistGate>
|
||||||
|
@ -70,4 +70,4 @@
|
|||||||
"typescript": "~4.0.0"
|
"typescript": "~4.0.0"
|
||||||
},
|
},
|
||||||
"private": true
|
"private": true
|
||||||
}
|
}
|
@ -3,7 +3,7 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
|
|||||||
import { NavigationContainer } from '@react-navigation/native'
|
import { NavigationContainer } from '@react-navigation/native'
|
||||||
import { enableScreens } from 'react-native-screens'
|
import { enableScreens } from 'react-native-screens'
|
||||||
|
|
||||||
import React from 'react'
|
import React, { useEffect } from 'react'
|
||||||
import { StatusBar } from 'react-native'
|
import { StatusBar } from 'react-native'
|
||||||
import Toast from 'react-native-toast-message'
|
import Toast from 'react-native-toast-message'
|
||||||
import { Feather } from '@expo/vector-icons'
|
import { Feather } from '@expo/vector-icons'
|
||||||
@ -18,8 +18,12 @@ import { useTheme } from '@utils/styles/ThemeManager'
|
|||||||
import getCurrentTab from '@utils/getCurrentTab'
|
import getCurrentTab from '@utils/getCurrentTab'
|
||||||
import { toastConfig } from '@components/toast'
|
import { toastConfig } from '@components/toast'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useSelector } from 'react-redux'
|
import { useDispatch, useSelector } from 'react-redux'
|
||||||
import { getLocalUrl } from './utils/slices/instancesSlice'
|
import {
|
||||||
|
getLocalToken,
|
||||||
|
getLocalUrl,
|
||||||
|
updateLocal
|
||||||
|
} from './utils/slices/instancesSlice'
|
||||||
|
|
||||||
enableScreens()
|
enableScreens()
|
||||||
const Tab = createBottomTabNavigator<RootStackParamList>()
|
const Tab = createBottomTabNavigator<RootStackParamList>()
|
||||||
@ -33,7 +37,9 @@ export type RootStackParamList = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Index: React.FC = () => {
|
export const Index: React.FC = () => {
|
||||||
|
const dispatch = useDispatch()
|
||||||
const localInstance = useSelector(getLocalUrl)
|
const localInstance = useSelector(getLocalUrl)
|
||||||
|
const localToken = useSelector(getLocalToken)
|
||||||
const { i18n } = useTranslation()
|
const { i18n } = useTranslation()
|
||||||
const { mode, theme } = useTheme()
|
const { mode, theme } = useTheme()
|
||||||
enum barStyle {
|
enum barStyle {
|
||||||
@ -41,11 +47,18 @@ export const Index: React.FC = () => {
|
|||||||
dark = 'light-content'
|
dark = 'light-content'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (localInstance && localToken) {
|
||||||
|
dispatch(updateLocal({ url: localInstance, token: localToken }))
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<StatusBar barStyle={barStyle[mode]} />
|
<StatusBar barStyle={barStyle[mode]} />
|
||||||
<NavigationContainer theme={themes[mode]} key={i18n.language}>
|
<NavigationContainer theme={themes[mode]} key={i18n.language}>
|
||||||
<Tab.Navigator
|
<Tab.Navigator
|
||||||
|
initialRouteName={localInstance ? 'Screen-Local' : 'Screen-Public'}
|
||||||
screenOptions={({ route }) => ({
|
screenOptions={({ route }) => ({
|
||||||
tabBarIcon: ({ focused, color, size }) => {
|
tabBarIcon: ({ focused, color, size }) => {
|
||||||
let name: any
|
let name: any
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
import React, {
|
import React, { useCallback, useEffect, useState } from 'react'
|
||||||
createRef,
|
|
||||||
useCallback,
|
|
||||||
useEffect,
|
|
||||||
useRef,
|
|
||||||
useState
|
|
||||||
} from 'react'
|
|
||||||
import {
|
import {
|
||||||
Animated,
|
|
||||||
Dimensions,
|
Dimensions,
|
||||||
Image,
|
Image,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
@ -18,7 +11,6 @@ import { useQuery } from 'react-query'
|
|||||||
import { debounce } from 'lodash'
|
import { debounce } from 'lodash'
|
||||||
|
|
||||||
import { instanceFetch } from '@utils/fetches/instanceFetch'
|
import { instanceFetch } from '@utils/fetches/instanceFetch'
|
||||||
import client from '@api/client'
|
|
||||||
import * as AuthSession from 'expo-auth-session'
|
import * as AuthSession from 'expo-auth-session'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { updateLocal } from '@utils/slices/instancesSlice'
|
import { updateLocal } from '@utils/slices/instancesSlice'
|
||||||
@ -110,7 +102,7 @@ const Login: React.FC = () => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
dispatch(updateLocal({ url: instanceDomain, token: accessToken }))
|
dispatch(updateLocal({ url: instanceDomain, token: accessToken }))
|
||||||
navigation.navigate('Screen-Local-Root')
|
navigation.navigate('Screen-Local')
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
}, [response])
|
}, [response])
|
||||||
|
@ -163,10 +163,7 @@ const composeInitialState: ComposeState = {
|
|||||||
},
|
},
|
||||||
attachments: { sensitive: false, uploads: [] },
|
attachments: { sensitive: false, uploads: [] },
|
||||||
attachmentUploadProgress: undefined,
|
attachmentUploadProgress: undefined,
|
||||||
visibility:
|
visibility: 'public',
|
||||||
getLocalAccountPreferences(store.getState())[
|
|
||||||
'posting:default:visibility'
|
|
||||||
] || 'public',
|
|
||||||
visibilityLock: false,
|
visibilityLock: false,
|
||||||
replyToStatus: undefined,
|
replyToStatus: undefined,
|
||||||
textInputFocus: {
|
textInputFocus: {
|
||||||
@ -220,7 +217,12 @@ const composeExistingState = ({
|
|||||||
uploads: incomingStatus.media_attachments
|
uploads: incomingStatus.media_attachments
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
visibility: incomingStatus.visibility
|
visibility:
|
||||||
|
incomingStatus.visibility ||
|
||||||
|
getLocalAccountPreferences(store.getState())[
|
||||||
|
'posting:default:visibility'
|
||||||
|
],
|
||||||
|
...(incomingStatus.visibility === 'direct' && { visibilityLock: true })
|
||||||
}
|
}
|
||||||
case 'reply':
|
case 'reply':
|
||||||
case 'conversation':
|
case 'conversation':
|
||||||
@ -337,7 +339,12 @@ const Compose: React.FC<Props> = ({ route: { params } }) => {
|
|||||||
type: params.type,
|
type: params.type,
|
||||||
incomingStatus: params.incomingStatus
|
incomingStatus: params.incomingStatus
|
||||||
})
|
})
|
||||||
: composeInitialState
|
: {
|
||||||
|
...composeInitialState,
|
||||||
|
visibility: getLocalAccountPreferences(store.getState())[
|
||||||
|
'posting:default:visibility'
|
||||||
|
] as ComposeState['visibility']
|
||||||
|
}
|
||||||
)
|
)
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
|
|
||||||
|
@ -2775,6 +2775,13 @@ expand-brackets@^2.1.4:
|
|||||||
snapdragon "^0.8.1"
|
snapdragon "^0.8.1"
|
||||||
to-regex "^3.0.1"
|
to-regex "^3.0.1"
|
||||||
|
|
||||||
|
expo-app-loading@^1.0.1:
|
||||||
|
version "1.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/expo-app-loading/-/expo-app-loading-1.0.1.tgz#a2ef73235c5dd0a99c0319ad9d3f4d278237564c"
|
||||||
|
integrity sha512-qgsystchwMHep43YMAMHJAD5bRUikolQpb1d+ySWF4ZFTtNInmLAPqiBcVSey5taRuHD3cAvEijx3wc0W/HfVw==
|
||||||
|
dependencies:
|
||||||
|
expo-splash-screen "0.8.1"
|
||||||
|
|
||||||
expo-application@~2.4.1:
|
expo-application@~2.4.1:
|
||||||
version "2.4.1"
|
version "2.4.1"
|
||||||
resolved "https://registry.yarnpkg.com/expo-application/-/expo-application-2.4.1.tgz#f8eb4a3a05a0b8a8f38f2e981f587a815945b685"
|
resolved "https://registry.yarnpkg.com/expo-application/-/expo-application-2.4.1.tgz#f8eb4a3a05a0b8a8f38f2e981f587a815945b685"
|
||||||
@ -2908,7 +2915,7 @@ expo-secure-store@~9.3.0:
|
|||||||
resolved "https://registry.yarnpkg.com/expo-secure-store/-/expo-secure-store-9.3.0.tgz#b716d5d115cc50a34037d1afef84fe4b8ea0745c"
|
resolved "https://registry.yarnpkg.com/expo-secure-store/-/expo-secure-store-9.3.0.tgz#b716d5d115cc50a34037d1afef84fe4b8ea0745c"
|
||||||
integrity sha512-dNhKcoUUn+1kmEfFVxSU7h+YsqODqlExZQJcQgxgeiuCeeDvJWkE10t3jjrO6aNfrdM5i/X2l3oh401EDslWsQ==
|
integrity sha512-dNhKcoUUn+1kmEfFVxSU7h+YsqODqlExZQJcQgxgeiuCeeDvJWkE10t3jjrO6aNfrdM5i/X2l3oh401EDslWsQ==
|
||||||
|
|
||||||
expo-splash-screen@~0.8.1:
|
expo-splash-screen@0.8.1, expo-splash-screen@~0.8.1:
|
||||||
version "0.8.1"
|
version "0.8.1"
|
||||||
resolved "https://registry.yarnpkg.com/expo-splash-screen/-/expo-splash-screen-0.8.1.tgz#de4a018c82af879eeaa9b697013ef37d9567453a"
|
resolved "https://registry.yarnpkg.com/expo-splash-screen/-/expo-splash-screen-0.8.1.tgz#de4a018c82af879eeaa9b697013ef37d9567453a"
|
||||||
integrity sha512-7NQo8OgkfQ4sv4mIHE58fkiQTGyl5dOP70uAUTb5YXC/QUsHIqEpKQ6ZXDpkLU1cbZ32c8Vtok4r2FRIUrzxcg==
|
integrity sha512-7NQo8OgkfQ4sv4mIHE58fkiQTGyl5dOP70uAUTb5YXC/QUsHIqEpKQ6ZXDpkLU1cbZ32c8Vtok4r2FRIUrzxcg==
|
||||||
|
Loading…
x
Reference in New Issue
Block a user