Skip to content

Commit

Permalink
feat: Upgrade react-native-bootsplash
Browse files Browse the repository at this point in the history
`react-native-bootsplash` has been upgraded to retrieve a fix that
ensures the `show` and `hide` methods always resolve their promises

Related PR: cozy/react-native-bootsplash#4
  • Loading branch information
Ldoppea committed Feb 28, 2024
1 parent eee3901 commit 5300ad3
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/app/theme/SplashScreenService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { AppState } from 'react-native'
import RNBootSplash, { VisibilityStatus } from 'react-native-bootsplash'
import RNBootSplash, {
ResultStatus,
VisibilityStatus
} from 'react-native-bootsplash'

import Minilog from 'cozy-minilog'

Expand Down Expand Up @@ -48,7 +51,7 @@ export const getSplashScreenStatus = (): Promise<VisibilityStatus> => {
*/
export const showSplashScreen = async (
bootsplashName: SplashScreenEnum | undefined = splashScreens.GLOBAL
): Promise<void> => {
): Promise<ResultStatus> => {
splashScreenLogger.debug(
`Attempting to show splash screen "${bootsplashName}"`
)
Expand All @@ -65,14 +68,18 @@ export const showSplashScreen = async (
setTimeoutForSplashScreen(bootsplashName)

try {
await RNBootSplash.show({ fade: true, bootsplashName })
return splashScreenLogger.info(`Splash screen shown "${bootsplashName}"`)
const result = await RNBootSplash.show({ fade: true, bootsplashName })
splashScreenLogger.info(
`Splash screen shown "${bootsplashName}" (${result.toString()})`
)
return result
} catch (error) {
splashScreenLogger.error(
`Error showing splash screen: ${bootsplashName}`,
error
)
logToSentry(error)
return false
}
}

Expand All @@ -84,7 +91,7 @@ export const showSplashScreen = async (
*/
export const hideSplashScreen = async (
bootsplashName: SplashScreenEnum | undefined = splashScreens.GLOBAL
): Promise<void> => {
): Promise<ResultStatus> => {
splashScreenLogger.debug(
`Attempting to hide splash screen "${bootsplashName}"`
)
Expand All @@ -96,14 +103,18 @@ export const hideSplashScreen = async (
)

try {
await manageTimersAndHideSplashScreen(bootsplashName)
return splashScreenLogger.info(`Splash screen hidden "${bootsplashName}"`)
const result = await manageTimersAndHideSplashScreen(bootsplashName)
splashScreenLogger.info(
`Splash screen hidden "${bootsplashName}" (${result.toString()})`
)
return result
} catch (error) {
splashScreenLogger.error(
`Error hiding splash screen: ${bootsplashName}`,
error
)
logToSentry(error)
return false
}
}

Expand Down Expand Up @@ -143,18 +154,19 @@ export const setTimeoutForSplashScreen = (
const manageTimersAndHideSplashScreen = async (
bootsplashName: SplashScreenEnum | undefined = splashScreens.GLOBAL,
fromTimeout = false
): Promise<void> => {
): Promise<ResultStatus> => {
if (bootsplashName !== splashScreens.SECURE_BACKGROUND)
destroyTimer(bootsplashName, fromTimeout)

try {
await RNBootSplash.hide({ fade: true, bootsplashName })
return await RNBootSplash.hide({ fade: true, bootsplashName })
} catch (error) {
splashScreenLogger.error(
`Error managing timers and hiding splash screen "${bootsplashName}"`,
error
)
logToSentry(error)
return false
}
}

Expand Down

0 comments on commit 5300ad3

Please sign in to comment.