grab referrer before loading

This commit is contained in:
Hailey
2024-06-12 09:39:38 -07:00
parent 8cc9ecbe05
commit 3f87e899fc
8 changed files with 65 additions and 10 deletions
+3 -1
View File
@@ -46,6 +46,7 @@ import * as Toast from 'view/com/util/Toast'
import {Shell} from 'view/shell'
import {ThemeProvider as Alf} from '#/alf'
import {useColorModeTheme} from '#/alf/util/useColorModeTheme'
import {useStarterPackEntry} from '#/components/hooks/useStarterPackEntry'
import {Provider as PortalProvider} from '#/components/Portal'
import {Splash} from '#/Splash'
import {BackgroundNotificationPreferencesProvider} from '../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider'
@@ -62,6 +63,7 @@ function InnerApp() {
const {_} = useLingui()
useIntentHandler()
const hasCheckedReferrer = useStarterPackEntry()
// init
useEffect(() => {
@@ -90,7 +92,7 @@ function InnerApp() {
<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<Alf theme={theme}>
<ThemeProvider theme={theme}>
<Splash isReady={isReady}>
<Splash isReady={isReady && hasCheckedReferrer}>
<RootSiblingParent>
<React.Fragment
// Resets the entire tree below when it changes:
@@ -0,0 +1,35 @@
import React from 'react'
import {useSetUsedStarterPack} from 'state/preferences/starter-pack'
import GooglePlayReferrer from '../../../modules/expo-google-play-referrer'
export function useStarterPackEntry() {
const [ready, setReady] = React.useState(false)
const setUsedStarterPack = useSetUsedStarterPack()
React.useEffect(() => {
;(async () => {
const res = await GooglePlayReferrer.getReferrerInfoAsync()
if (
res &&
res.installReferrer &&
res.installReferrer.startsWith('https://bsky.app/start/')
) {
const [_, _start, name, rkey] = new URL(
res.installReferrer,
).pathname.split('/')
if (name && rkey) {
setUsedStarterPack({
uri: res.installReferrer,
})
}
}
setReady(true)
})()
}, [setUsedStarterPack])
return ready
}
@@ -0,0 +1,13 @@
import React from 'react'
export function useStarterPackEntry() {
const [ready, setReady] = React.useState(false)
React.useEffect(() => {
;(async () => {
setReady(true)
})()
}, [])
return ready
}
@@ -0,0 +1,3 @@
export function useStarterPackEntry() {
return true
}