Skip to content

Commit 0069f4a

Browse files
fix: Splash Screen loading for Codepush
1 parent b6e6ea4 commit 0069f4a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

template/metro.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
12
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config')
23

34
/**

template/src/screens/SplashScreen.tsx

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import React, {useEffect, useState} from 'react'
2-
import {StyleSheet, View} from 'react-native'
2+
import {StyleSheet, Text, View} from 'react-native'
33
import CodePush from 'react-native-code-push'
4-
import Progress from 'react-native-progress'
4+
import * as Progress from 'react-native-progress'
55
import {ScreenContainer} from '../components'
66
import configs from '../constants/configs'
77
import {appActions} from '../store/reducers/app'
88
import {useAppDispatch} from '../store/store'
9-
import {colors, deviceWidth, responsiveHeight} from '../themes'
9+
import {colors, deviceWidth, metrics, responsiveHeight} from '../themes'
1010

1111
const codePushOptions = {
1212
installMode: CodePush.InstallMode.IMMEDIATE,
1313
deploymentKey: configs.codePushKey,
1414
}
1515

16+
const STATUS = {
17+
check: 'Checking for update',
18+
download: 'Downloading...',
19+
done: 'Done',
20+
}
21+
1622
const SplashScreen = () => {
1723
const dispatch = useAppDispatch()
1824
const [updatePercent, setUpdatePercent] = useState(0)
25+
const [statusText, setStatusText] = useState('')
1926

2027
useEffect(() => {
2128
CodePush.sync(
@@ -26,11 +33,22 @@ const SplashScreen = () => {
2633
case CodePush.SyncStatus.UNKNOWN_ERROR:
2734
dispatch(appActions.getSettings())
2835
break
36+
case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
37+
case CodePush.SyncStatus.INSTALLING_UPDATE:
38+
case CodePush.SyncStatus.SYNC_IN_PROGRESS:
39+
setStatusText(STATUS.download)
40+
break
41+
default:
42+
setStatusText(STATUS.check)
2943
}
3044
},
3145
({receivedBytes, totalBytes}) => {
46+
const percent = receivedBytes / totalBytes
3247
if (totalBytes > 0) {
33-
setUpdatePercent(receivedBytes / totalBytes)
48+
setUpdatePercent(percent)
49+
}
50+
if (percent === 1) {
51+
setStatusText(STATUS.done)
3452
}
3553
},
3654
).catch(() => {
@@ -43,6 +61,7 @@ const SplashScreen = () => {
4361
{updatePercent > 0 ? (
4462
<View style={styles.progressBar}>
4563
<Progress.Bar progress={updatePercent} color={colors.primary} width={deviceWidth() * 0.6} />
64+
<Text style={styles.progressText}>{statusText}</Text>
4665
</View>
4766
) : null}
4867
</ScreenContainer>
@@ -58,6 +77,11 @@ const styles = StyleSheet.create({
5877
position: 'absolute',
5978
bottom: responsiveHeight(40),
6079
alignSelf: 'center',
80+
alignItems: 'center',
81+
},
82+
progressText: {
83+
color: colors.primary,
84+
paddingTop: metrics.xxs,
6185
},
6286
})
6387

0 commit comments

Comments
 (0)