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
+2 -2
View File
@@ -1,3 +1,3 @@
import {GooglePlayReferrerModule} from './src/ExpoGooglePlayReferrerModule'
import {GooglePlayReferrer} from './src/ExpoGooglePlayReferrerModule'
export default GooglePlayReferrerModule
export default GooglePlayReferrer
@@ -1,8 +1,10 @@
export type GooglePlayReferrerInfo = {
installReferrer: string
clickTimestamp: number
installTimestamp: number
}
export type GooglePlayReferrerInfo =
| {
installReferrer?: string
clickTimestamp?: number
installTimestamp?: number
}
| undefined
export type ExpoGooglePlayReferrerModule = {
getReferrerInfoAsync(): Promise<GooglePlayReferrerInfo>
@@ -2,5 +2,5 @@ import {requireNativeModule} from 'expo-modules-core'
import {ExpoGooglePlayReferrerModule} from './ExpoGooglePlayReferrer.types'
export const BackgroundNotificationHandler =
export const GooglePlayReferrer =
requireNativeModule<ExpoGooglePlayReferrerModule>('ExpoGooglePlayReferrer')
@@ -3,7 +3,7 @@ import {
GooglePlayReferrerInfo,
} from './ExpoGooglePlayReferrer.types'
export const GooglePlayReferrerModule = {
export const GooglePlayReferrer = {
getReferrerInfoAsync(): Promise<GooglePlayReferrerInfo> {
console.error('getReferrerInfoAsync is only available on Android')
return Promise.reject('getReferrerInfoAsync is only available on Android')
+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
}