-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rework app bootstrap and locale initialization (#403)
- Loading branch information
Showing
13 changed files
with
104 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,33 @@ | ||
import { Logger } from '$core/logger'; | ||
|
||
import { Analytics } from './analytics'; | ||
import { Attribution } from './attribution'; | ||
import { initDateLocale } from './date'; | ||
import { getSupportedDateLocale } from './i18n'; | ||
import { getSavedAppLocale } from './i18n/utils/languageDetector'; | ||
import { getSupportedLocale } from './i18n'; | ||
import { ErrorMonitoring } from './monitoring'; | ||
import { Notifications } from './notifications'; | ||
import { Purchase } from './purchase'; | ||
|
||
const initAnalyticsAndAttribution = () => { | ||
Analytics.init() | ||
.then(() => { | ||
Attribution.init().catch((error: unknown) => { | ||
Logger.error({ | ||
error, | ||
message: 'Failed to initialize AppsFlyer', | ||
}); | ||
}); | ||
}) | ||
.catch((error: unknown) => { | ||
Logger.error({ | ||
error, | ||
message: 'Failed to initialize Amplitude', | ||
}); | ||
}); | ||
}; | ||
|
||
const initNotifications = () => { | ||
const initNotifications = (locale: string) => { | ||
Notifications.init(); | ||
|
||
const locale = getSavedAppLocale(); | ||
|
||
if (locale) Notifications.setUserLanguage(locale); | ||
Notifications.setUserLanguage(locale); | ||
}; | ||
|
||
const initDateLib = () => { | ||
const localeToUse = getSupportedDateLocale(); | ||
|
||
initDateLocale(localeToUse); | ||
const initDateLib = (locale: string) => { | ||
initDateLocale(locale); | ||
}; | ||
|
||
export const bootstrapExternalSdks = () => { | ||
export const bootstrapExternalSdks = async () => { | ||
// Core services to init first in a specific order | ||
ErrorMonitoring.init(); | ||
initAnalyticsAndAttribution(); | ||
await Analytics.init(); | ||
await Attribution.init(); | ||
|
||
// Misc | ||
const localeToUse = getSupportedLocale(); | ||
|
||
// All other core services | ||
initNotifications(localeToUse); | ||
initDateLib(localeToUse); | ||
|
||
// Used SDKs | ||
Purchase.init(); | ||
initNotifications(); | ||
initDateLib(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { i18n } from './i18n'; | ||
export { changeLanguage } from './utils/languageSwitcher'; | ||
export { getSupportedDateLocale } from './utils/detectLocaleToUse'; | ||
export { getSupportedLocale } from './utils/detectLocaleToUse'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/shared/components/splashscreen/hooks/useBootstrapApp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import * as SplashScreen from 'expo-splash-screen'; | ||
import { useCallback } from 'react'; | ||
|
||
import { bootstrapExternalSdks } from '$core/bootstrapExternalSdks'; | ||
import { Logger } from '$core/logger'; | ||
import { checkForOtaUpdate } from '$shared/utils/checkForAppUpdates'; | ||
|
||
SplashScreen.preventAutoHideAsync().catch((error: unknown) => { | ||
Logger.error({ | ||
message: 'Failed to persist the SplashScreen', | ||
error, | ||
}); | ||
}); | ||
|
||
export const useBootstrapApp = () => { | ||
const onLayoutRootView = useCallback(() => { | ||
(async () => { | ||
await bootstrapExternalSdks(); | ||
await checkForOtaUpdate(); | ||
})() | ||
.finally(() => { | ||
SplashScreen.hideAsync().catch((error: unknown) => { | ||
Logger.error({ | ||
message: 'Failed to hide the SplashScreen', | ||
error, | ||
}); | ||
}); | ||
}) | ||
.catch((error: unknown) => { | ||
Logger.error({ | ||
message: 'Failed to bootstrap app SDKs or check for OTA update', | ||
error, | ||
}); | ||
}); | ||
}, []); | ||
|
||
return { | ||
onLayoutRootView, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters