2022-07-18 22:24:37 +02:00
|
|
|
import 'react-native-url-polyfill/auto'
|
2023-11-01 16:15:37 +01:00
|
|
|
import 'lib/sentry' // must be near top
|
2024-03-21 01:26:38 +01:00
|
|
|
import 'view/icons'
|
2023-11-01 16:15:37 +01:00
|
|
|
|
2024-03-21 01:26:38 +01:00
|
|
|
import React, {useEffect, useState} from 'react'
|
2023-03-20 00:53:57 +01:00
|
|
|
import {GestureHandlerRootView} from 'react-native-gesture-handler'
|
2024-05-20 04:25:49 +02:00
|
|
|
import {KeyboardProvider} from 'react-native-keyboard-controller'
|
2024-03-21 01:26:38 +01:00
|
|
|
import {RootSiblingParent} from 'react-native-root-siblings'
|
2023-12-14 21:48:40 +01:00
|
|
|
import {
|
|
|
|
initialWindowMetrics,
|
2024-03-21 01:26:38 +01:00
|
|
|
SafeAreaProvider,
|
2023-12-14 21:48:40 +01:00
|
|
|
} from 'react-native-safe-area-context'
|
2024-03-21 01:26:38 +01:00
|
|
|
import * as SplashScreen from 'expo-splash-screen'
|
|
|
|
import {msg} from '@lingui/macro'
|
|
|
|
import {useLingui} from '@lingui/react'
|
2023-11-01 16:15:37 +01:00
|
|
|
|
2024-06-18 20:48:34 +02:00
|
|
|
import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
|
|
|
|
import {QueryProvider} from '#/lib/react-query'
|
2024-06-17 20:21:09 +02:00
|
|
|
import {
|
|
|
|
initialize,
|
|
|
|
Provider as StatsigProvider,
|
|
|
|
tryFetchGates,
|
|
|
|
} from '#/lib/statsig/statsig'
|
2024-06-18 20:48:34 +02:00
|
|
|
import {s} from '#/lib/styles'
|
|
|
|
import {ThemeProvider} from '#/lib/ThemeContext'
|
2024-07-25 21:41:50 +02:00
|
|
|
import I18nProvider from '#/locale/i18nProvider'
|
2024-05-02 19:17:53 +02:00
|
|
|
import {logger} from '#/logger'
|
2024-06-21 00:06:57 +02:00
|
|
|
import {Provider as A11yProvider} from '#/state/a11y'
|
2024-06-18 20:48:34 +02:00
|
|
|
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
|
|
|
|
import {Provider as DialogStateProvider} from '#/state/dialogs'
|
2024-07-25 21:41:50 +02:00
|
|
|
import {listenSessionDropped} from '#/state/events'
|
2024-06-18 20:48:34 +02:00
|
|
|
import {Provider as InvitesStateProvider} from '#/state/invites'
|
|
|
|
import {Provider as LightboxStateProvider} from '#/state/lightbox'
|
2024-05-08 03:25:58 +02:00
|
|
|
import {MessagesProvider} from '#/state/messages'
|
2024-06-18 20:48:34 +02:00
|
|
|
import {Provider as ModalStateProvider} from '#/state/modals'
|
2023-11-07 23:06:17 +01:00
|
|
|
import {init as initPersistedState} from '#/state/persisted'
|
2024-06-18 20:48:34 +02:00
|
|
|
import {Provider as PrefsStateProvider} from '#/state/preferences'
|
2024-03-21 01:26:38 +01:00
|
|
|
import {Provider as LabelDefsProvider} from '#/state/preferences/label-defs'
|
2024-05-01 06:06:51 +02:00
|
|
|
import {Provider as ModerationOptsProvider} from '#/state/preferences/moderation-opts'
|
2024-06-18 20:48:34 +02:00
|
|
|
import {Provider as UnreadNotifsProvider} from '#/state/queries/notifications/unread'
|
2023-11-10 00:14:51 +01:00
|
|
|
import {
|
|
|
|
Provider as SessionProvider,
|
2024-05-02 19:17:53 +02:00
|
|
|
SessionAccount,
|
2023-11-10 00:14:51 +01:00
|
|
|
useSession,
|
|
|
|
useSessionApi,
|
2024-06-18 20:48:34 +02:00
|
|
|
} from '#/state/session'
|
|
|
|
import {readLastActiveAccount} from '#/state/session/util'
|
|
|
|
import {Provider as ShellStateProvider} from '#/state/shell'
|
|
|
|
import {Provider as LoggedOutViewProvider} from '#/state/shell/logged-out'
|
2024-07-04 04:05:19 +02:00
|
|
|
import {Provider as ProgressGuideProvider} from '#/state/shell/progress-guide'
|
2024-06-18 20:48:34 +02:00
|
|
|
import {Provider as SelectedFeedProvider} from '#/state/shell/selected-feed'
|
2024-06-22 06:38:04 +02:00
|
|
|
import {Provider as StarterPackProvider} from '#/state/shell/starter-pack'
|
2024-08-22 04:20:45 +02:00
|
|
|
import {Provider as HiddenRepliesProvider} from '#/state/threadgate-hidden-replies'
|
2024-06-18 20:48:34 +02:00
|
|
|
import {TestCtrls} from '#/view/com/testing/TestCtrls'
|
2024-08-28 17:46:47 +02:00
|
|
|
import {Provider as ActiveVideoProvider} from '#/view/com/util/post-embeds/ActiveVideoNativeContext'
|
2024-06-18 20:48:34 +02:00
|
|
|
import * as Toast from '#/view/com/util/Toast'
|
|
|
|
import {Shell} from '#/view/shell'
|
2024-03-21 01:26:38 +01:00
|
|
|
import {ThemeProvider as Alf} from '#/alf'
|
|
|
|
import {useColorModeTheme} from '#/alf/util/useColorModeTheme'
|
2024-06-22 06:38:04 +02:00
|
|
|
import {useStarterPackEntry} from '#/components/hooks/useStarterPackEntry'
|
New component library based on ALF (#2459)
* Install on native as well
* Add button and link components
* Comments
* Use new prop
* Add some form elements
* Add labels to input
* Fix line height, add suffix
* Date inputs
* Autofill styles
* Clean up InputDate types
* Improve types for InputText, value handling
* Enforce a11y props on buttons
* Add Dialog, Portal
* Dialog contents
* Native dialog
* Clean up
* Fix animations
* Improvements to web modal, exiting still broken
* Clean up dialog types
* Add Prompt, Dialog refinement, mobile refinement
* Integrate new design tokens, reorg storybook
* Button colors
* Dim mode
* Reorg
* Some styles
* Toggles
* Improve a11y
* Autosize dialog, handle max height, Dialog.ScrolLView not working
* Try to use BottomSheet's own APIs
* Scrollable dialogs
* Add web shadow
* Handle overscroll
* Styles
* Dialog text input
* Shadows
* Button focus states
* Button pressed states
* Gradient poc
* Gradient colors and hovers
* Add hrefAttrs to Link
* Some more a11y
* Toggle invalid states
* Update dialog descriptions for demo
* Icons
* WIP Toggle cleanup
* Refactor toggle to not rely on immediate children
* Make Toggle controlled
* Clean up Toggles storybook
* ToggleButton styles
* Improve a11y labels
* ToggleButton hover darkmode
* Some i18n
* Refactor input
* Allow extension of input
* Remove old input
* Improve icons, add CalendarDays
* Refactor DateField, web done
* Add label example
* Clean up old InputDate, DateField android, text area example
* Consistent imports
* Button context, icons
* Add todo
* Add closeAllDialogs control
* Alignment
* Expand color palette
* Hitslops, add shortcut to Storybook in dev
* Fix multiline on ios
* Mark dialog close button as unused
2024-01-19 03:28:04 +01:00
|
|
|
import {Provider as PortalProvider} from '#/components/Portal'
|
2024-03-21 01:26:38 +01:00
|
|
|
import {Splash} from '#/Splash'
|
2024-05-15 20:49:07 +02:00
|
|
|
import {BackgroundNotificationPreferencesProvider} from '../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider'
|
2024-08-09 23:35:26 +02:00
|
|
|
import {AudioCategory, PlatformInfo} from '../modules/expo-bluesky-swiss-army'
|
2022-06-09 20:03:25 +02:00
|
|
|
|
2023-05-08 22:05:36 +02:00
|
|
|
SplashScreen.preventAutoHideAsync()
|
|
|
|
|
2023-11-16 21:53:43 +01:00
|
|
|
function InnerApp() {
|
2024-05-02 19:17:53 +02:00
|
|
|
const [isReady, setIsReady] = React.useState(false)
|
|
|
|
const {currentAccount} = useSession()
|
2024-05-08 04:30:55 +02:00
|
|
|
const {resumeSession} = useSessionApi()
|
2024-02-06 20:43:51 +01:00
|
|
|
const theme = useColorModeTheme()
|
2024-01-09 23:37:15 +01:00
|
|
|
const {_} = useLingui()
|
2024-04-04 00:53:44 +02:00
|
|
|
|
2024-02-27 19:35:38 +01:00
|
|
|
useIntentHandler()
|
2024-06-22 06:38:04 +02:00
|
|
|
const hasCheckedReferrer = useStarterPackEntry()
|
2022-06-09 20:03:25 +02:00
|
|
|
|
|
|
|
// init
|
2023-11-10 00:14:51 +01:00
|
|
|
useEffect(() => {
|
2024-05-08 04:30:55 +02:00
|
|
|
async function onLaunch(account?: SessionAccount) {
|
2024-05-02 19:17:53 +02:00
|
|
|
try {
|
|
|
|
if (account) {
|
2024-05-08 04:30:55 +02:00
|
|
|
await resumeSession(account)
|
2024-06-17 20:21:09 +02:00
|
|
|
} else {
|
|
|
|
await initialize()
|
|
|
|
await tryFetchGates(undefined, 'prefer-fresh-gates')
|
2024-05-02 19:17:53 +02:00
|
|
|
}
|
|
|
|
} catch (e) {
|
2024-05-08 04:30:55 +02:00
|
|
|
logger.error(`session: resume failed`, {message: e})
|
2024-05-02 19:17:53 +02:00
|
|
|
} finally {
|
|
|
|
setIsReady(true)
|
|
|
|
}
|
|
|
|
}
|
2024-04-25 17:35:21 +02:00
|
|
|
const account = readLastActiveAccount()
|
2024-05-08 04:30:55 +02:00
|
|
|
onLaunch(account)
|
|
|
|
}, [resumeSession])
|
2024-05-02 19:17:53 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
return listenSessionDropped(() => {
|
2024-07-23 16:01:04 +02:00
|
|
|
Toast.show(
|
|
|
|
_(msg`Sorry! Your session expired. Please log in again.`),
|
|
|
|
'info',
|
|
|
|
)
|
2024-05-02 19:17:53 +02:00
|
|
|
})
|
|
|
|
}, [_])
|
2023-11-10 00:14:51 +01:00
|
|
|
|
2023-11-07 23:06:17 +01:00
|
|
|
return (
|
2023-12-14 21:48:40 +01:00
|
|
|
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
|
New component library based on ALF (#2459)
* Install on native as well
* Add button and link components
* Comments
* Use new prop
* Add some form elements
* Add labels to input
* Fix line height, add suffix
* Date inputs
* Autofill styles
* Clean up InputDate types
* Improve types for InputText, value handling
* Enforce a11y props on buttons
* Add Dialog, Portal
* Dialog contents
* Native dialog
* Clean up
* Fix animations
* Improvements to web modal, exiting still broken
* Clean up dialog types
* Add Prompt, Dialog refinement, mobile refinement
* Integrate new design tokens, reorg storybook
* Button colors
* Dim mode
* Reorg
* Some styles
* Toggles
* Improve a11y
* Autosize dialog, handle max height, Dialog.ScrolLView not working
* Try to use BottomSheet's own APIs
* Scrollable dialogs
* Add web shadow
* Handle overscroll
* Styles
* Dialog text input
* Shadows
* Button focus states
* Button pressed states
* Gradient poc
* Gradient colors and hovers
* Add hrefAttrs to Link
* Some more a11y
* Toggle invalid states
* Update dialog descriptions for demo
* Icons
* WIP Toggle cleanup
* Refactor toggle to not rely on immediate children
* Make Toggle controlled
* Clean up Toggles storybook
* ToggleButton styles
* Improve a11y labels
* ToggleButton hover darkmode
* Some i18n
* Refactor input
* Allow extension of input
* Remove old input
* Improve icons, add CalendarDays
* Refactor DateField, web done
* Add label example
* Clean up old InputDate, DateField android, text area example
* Consistent imports
* Button context, icons
* Add todo
* Add closeAllDialogs control
* Alignment
* Expand color palette
* Hitslops, add shortcut to Storybook in dev
* Fix multiline on ios
* Mark dialog close button as unused
2024-01-19 03:28:04 +01:00
|
|
|
<Alf theme={theme}>
|
2024-05-03 17:36:58 +02:00
|
|
|
<ThemeProvider theme={theme}>
|
2024-06-22 06:38:04 +02:00
|
|
|
<Splash isReady={isReady && hasCheckedReferrer}>
|
2024-07-25 21:41:50 +02:00
|
|
|
<ActiveVideoProvider>
|
|
|
|
<RootSiblingParent>
|
|
|
|
<React.Fragment
|
|
|
|
// Resets the entire tree below when it changes:
|
|
|
|
key={currentAccount?.did}>
|
|
|
|
<QueryProvider currentDid={currentAccount?.did}>
|
|
|
|
<StatsigProvider>
|
|
|
|
<MessagesProvider>
|
|
|
|
{/* LabelDefsProvider MUST come before ModerationOptsProvider */}
|
|
|
|
<LabelDefsProvider>
|
|
|
|
<ModerationOptsProvider>
|
|
|
|
<LoggedOutViewProvider>
|
|
|
|
<SelectedFeedProvider>
|
2024-08-22 04:20:45 +02:00
|
|
|
<HiddenRepliesProvider>
|
|
|
|
<UnreadNotifsProvider>
|
|
|
|
<BackgroundNotificationPreferencesProvider>
|
|
|
|
<MutedThreadsProvider>
|
2024-08-29 19:57:36 +02:00
|
|
|
<ProgressGuideProvider>
|
|
|
|
<GestureHandlerRootView
|
|
|
|
style={s.h100pct}>
|
|
|
|
<TestCtrls />
|
|
|
|
<Shell />
|
|
|
|
</GestureHandlerRootView>
|
|
|
|
</ProgressGuideProvider>
|
2024-08-22 04:20:45 +02:00
|
|
|
</MutedThreadsProvider>
|
|
|
|
</BackgroundNotificationPreferencesProvider>
|
|
|
|
</UnreadNotifsProvider>
|
|
|
|
</HiddenRepliesProvider>
|
2024-07-25 21:41:50 +02:00
|
|
|
</SelectedFeedProvider>
|
|
|
|
</LoggedOutViewProvider>
|
|
|
|
</ModerationOptsProvider>
|
|
|
|
</LabelDefsProvider>
|
|
|
|
</MessagesProvider>
|
|
|
|
</StatsigProvider>
|
|
|
|
</QueryProvider>
|
|
|
|
</React.Fragment>
|
|
|
|
</RootSiblingParent>
|
|
|
|
</ActiveVideoProvider>
|
2024-05-03 17:36:58 +02:00
|
|
|
</Splash>
|
|
|
|
</ThemeProvider>
|
New component library based on ALF (#2459)
* Install on native as well
* Add button and link components
* Comments
* Use new prop
* Add some form elements
* Add labels to input
* Fix line height, add suffix
* Date inputs
* Autofill styles
* Clean up InputDate types
* Improve types for InputText, value handling
* Enforce a11y props on buttons
* Add Dialog, Portal
* Dialog contents
* Native dialog
* Clean up
* Fix animations
* Improvements to web modal, exiting still broken
* Clean up dialog types
* Add Prompt, Dialog refinement, mobile refinement
* Integrate new design tokens, reorg storybook
* Button colors
* Dim mode
* Reorg
* Some styles
* Toggles
* Improve a11y
* Autosize dialog, handle max height, Dialog.ScrolLView not working
* Try to use BottomSheet's own APIs
* Scrollable dialogs
* Add web shadow
* Handle overscroll
* Styles
* Dialog text input
* Shadows
* Button focus states
* Button pressed states
* Gradient poc
* Gradient colors and hovers
* Add hrefAttrs to Link
* Some more a11y
* Toggle invalid states
* Update dialog descriptions for demo
* Icons
* WIP Toggle cleanup
* Refactor toggle to not rely on immediate children
* Make Toggle controlled
* Clean up Toggles storybook
* ToggleButton styles
* Improve a11y labels
* ToggleButton hover darkmode
* Some i18n
* Refactor input
* Allow extension of input
* Remove old input
* Improve icons, add CalendarDays
* Refactor DateField, web done
* Add label example
* Clean up old InputDate, DateField android, text area example
* Consistent imports
* Button context, icons
* Add todo
* Add closeAllDialogs control
* Alignment
* Expand color palette
* Hitslops, add shortcut to Storybook in dev
* Fix multiline on ios
* Mark dialog close button as unused
2024-01-19 03:28:04 +01:00
|
|
|
</Alf>
|
2023-12-14 21:48:40 +01:00
|
|
|
</SafeAreaProvider>
|
2023-11-07 23:06:17 +01:00
|
|
|
)
|
2023-11-16 21:53:43 +01:00
|
|
|
}
|
2023-11-07 23:06:17 +01:00
|
|
|
|
|
|
|
function App() {
|
|
|
|
const [isReady, setReady] = useState(false)
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
2024-08-09 23:35:26 +02:00
|
|
|
PlatformInfo.setAudioCategory(AudioCategory.Ambient)
|
2024-08-12 23:58:41 +02:00
|
|
|
PlatformInfo.setAudioActive(false)
|
2023-11-07 23:06:17 +01:00
|
|
|
initPersistedState().then(() => setReady(true))
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
if (!isReady) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-11-14 23:54:02 +01:00
|
|
|
/*
|
|
|
|
* NOTE: only nothing here can depend on other data or session state, since
|
|
|
|
* that is set up in the InnerApp component above.
|
|
|
|
*/
|
2022-06-09 20:03:25 +02:00
|
|
|
return (
|
2024-08-31 01:26:03 +02:00
|
|
|
<A11yProvider>
|
|
|
|
<KeyboardProvider enabled={false} statusBarTranslucent={true}>
|
|
|
|
<SessionProvider>
|
|
|
|
<PrefsStateProvider>
|
|
|
|
<I18nProvider>
|
|
|
|
<ShellStateProvider>
|
2024-08-30 19:26:40 +02:00
|
|
|
<InvitesStateProvider>
|
|
|
|
<ModalStateProvider>
|
|
|
|
<DialogStateProvider>
|
|
|
|
<LightboxStateProvider>
|
2024-06-21 00:06:57 +02:00
|
|
|
<PortalProvider>
|
2024-06-22 06:38:04 +02:00
|
|
|
<StarterPackProvider>
|
|
|
|
<InnerApp />
|
|
|
|
</StarterPackProvider>
|
2024-06-21 00:06:57 +02:00
|
|
|
</PortalProvider>
|
2024-08-30 19:26:40 +02:00
|
|
|
</LightboxStateProvider>
|
|
|
|
</DialogStateProvider>
|
|
|
|
</ModalStateProvider>
|
|
|
|
</InvitesStateProvider>
|
2024-08-31 01:26:03 +02:00
|
|
|
</ShellStateProvider>
|
|
|
|
</I18nProvider>
|
|
|
|
</PrefsStateProvider>
|
|
|
|
</SessionProvider>
|
|
|
|
</KeyboardProvider>
|
|
|
|
</A11yProvider>
|
2022-06-09 20:03:25 +02:00
|
|
|
)
|
2023-11-07 23:06:17 +01:00
|
|
|
}
|
2022-06-09 20:03:25 +02:00
|
|
|
|
2023-11-07 05:30:00 +01:00
|
|
|
export default App
|