11import React , { useEffect , useState } from 'react'
2- import { StyleSheet , View } from 'react-native'
2+ import { StyleSheet , Text , View } from 'react-native'
33import CodePush from 'react-native-code-push'
4- import Progress from 'react-native-progress'
4+ import * as Progress from 'react-native-progress'
55import { ScreenContainer } from '../components'
66import configs from '../constants/configs'
77import { appActions } from '../store/reducers/app'
88import { useAppDispatch } from '../store/store'
9- import { colors , deviceWidth , responsiveHeight } from '../themes'
9+ import { colors , deviceWidth , metrics , responsiveHeight } from '../themes'
1010
1111const 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+
1622const 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