2024-09-09 14:27:20 +05:30
|
|
|
import { COLORS } from '@rn-ui-lib/colors';
|
|
|
|
|
import ProgressBar from './ProgressBar';
|
|
|
|
|
import React, { forwardRef, useImperativeHandle, useState } from 'react';
|
2024-09-21 10:20:12 +05:30
|
|
|
import { View, StyleSheet, ActivityIndicator } from 'react-native';
|
2024-09-09 14:27:20 +05:30
|
|
|
import { DownloadProgress } from 'react-native-code-push';
|
|
|
|
|
import ModalWrapperForAlfredV2 from '@common/ModalWrapperForAlfredV2';
|
|
|
|
|
import Text from '@rn-ui-lib/components/Text';
|
|
|
|
|
import NaviLogoWithTextIcon from '@rn-ui-lib/icons/NaviLogoWithTextIcon';
|
2024-09-20 16:47:57 +05:30
|
|
|
import { GenericStyles } from '@rn-ui-lib/styles';
|
2024-09-09 14:27:20 +05:30
|
|
|
|
|
|
|
|
export interface CodePushLoadingModalRef {
|
|
|
|
|
show: () => void;
|
|
|
|
|
hide: () => void;
|
|
|
|
|
updateProgress: (progress: DownloadProgress) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const CodePushLoadingModal = forwardRef<CodePushLoadingModalRef>((_, ref) => {
|
|
|
|
|
const [visible, setVisible] = useState(false);
|
|
|
|
|
const [progress, setProgress] = useState<DownloadProgress>();
|
|
|
|
|
|
|
|
|
|
useImperativeHandle(ref, () => ({
|
|
|
|
|
show: () => setVisible(true),
|
|
|
|
|
hide: () => setVisible(false),
|
|
|
|
|
updateProgress: (downloadProgress: DownloadProgress) => setProgress(downloadProgress),
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
const getInMb = (progress: number) => {
|
|
|
|
|
if (progress) return `${(progress / 1024 / 1024).toFixed(2)} MB`;
|
|
|
|
|
return '-';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ModalWrapperForAlfredV2 visible={visible} animationType="fade">
|
|
|
|
|
<View style={styles.modalContainer}>
|
|
|
|
|
<View style={styles.modalContent}>
|
2024-09-20 16:25:11 +05:30
|
|
|
<View style={styles.LottieContainerStyles}>
|
2024-09-21 10:20:12 +05:30
|
|
|
<ActivityIndicator size={'large'} color={COLORS.BASE.BLUE} />
|
2024-09-09 14:27:20 +05:30
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
{progress ? (
|
|
|
|
|
<View>
|
2024-09-09 14:28:08 +05:30
|
|
|
<Text style={styles.header}>Updating to a newer version...</Text>
|
2024-09-09 14:27:20 +05:30
|
|
|
<ProgressBar progress={progress?.receivedBytes / progress?.totalBytes} />
|
|
|
|
|
<Text style={styles.progressText}>
|
|
|
|
|
{getInMb(progress?.receivedBytes)} / {getInMb(progress?.totalBytes)}
|
|
|
|
|
</Text>
|
|
|
|
|
</View>
|
|
|
|
|
) : null}
|
|
|
|
|
</View>
|
2024-09-20 16:25:11 +05:30
|
|
|
<View style={GenericStyles.alignCenter}>
|
2024-09-09 14:27:20 +05:30
|
|
|
<NaviLogoWithTextIcon />
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
</ModalWrapperForAlfredV2>
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2024-09-20 16:25:11 +05:30
|
|
|
LottieContainerStyles: {
|
|
|
|
|
alignItems: 'center',
|
2024-09-20 16:47:57 +05:30
|
|
|
marginBottom: 24,
|
2024-09-20 16:25:11 +05:30
|
|
|
},
|
|
|
|
|
LottieStyles: {
|
|
|
|
|
height: 140,
|
2024-09-20 16:47:57 +05:30
|
|
|
width: 140,
|
2024-09-20 16:25:11 +05:30
|
|
|
},
|
|
|
|
|
header: {
|
|
|
|
|
color: COLORS.TEXT.BLACK_24,
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
paddingBottom: 6,
|
|
|
|
|
paddingTop: 24,
|
|
|
|
|
},
|
2024-09-09 14:27:20 +05:30
|
|
|
modalContainer: {
|
|
|
|
|
flex: 1,
|
|
|
|
|
padding: 20,
|
|
|
|
|
},
|
|
|
|
|
modalContent: {
|
|
|
|
|
flex: 1,
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
},
|
2024-09-20 16:25:11 +05:30
|
|
|
progressBar: {
|
|
|
|
|
height: 2,
|
|
|
|
|
marginTop: 10,
|
|
|
|
|
width: '100%',
|
2024-09-09 14:27:20 +05:30
|
|
|
},
|
|
|
|
|
progressText: {
|
|
|
|
|
color: COLORS.TEXT.BLACK_24,
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
fontWeight: '700',
|
|
|
|
|
marginTop: 6,
|
2024-09-20 16:47:57 +05:30
|
|
|
},
|
2024-09-09 14:27:20 +05:30
|
|
|
});
|
|
|
|
|
|
2024-09-20 16:25:11 +05:30
|
|
|
CodePushLoadingModal.displayName = 'codepush-loading-modal';
|
2024-09-09 14:27:20 +05:30
|
|
|
export default CodePushLoadingModal;
|