-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9dc23b
commit 9c9ddcf
Showing
3 changed files
with
70 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,37 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { Button, Modal, Text, View } from 'react-native'; | ||
|
||
import { translate } from 'localization/hooks'; | ||
import { isUpdated, openStore } from 'hooks/force-update'; | ||
|
||
import { isUpdated, openStore } from 'network/services/force-update'; | ||
import { translate } from 'localization/hooks'; | ||
|
||
import { styles } from './force-update-modal.styles'; | ||
|
||
interface ForceUpdateProps {} | ||
|
||
const ForceUpdateModal = ({}: ForceUpdateProps) => ( | ||
<Modal animationType="slide" transparent={true} visible={isUpdated()}> | ||
<View style={styles.centeredView}> | ||
<View style={styles.modalView}> | ||
<Text style={styles.modalText}>{translate('alert.update')}</Text> | ||
<Button title={translate('buttons.ok')} onPress={openStore} /> | ||
const ForceUpdateModal = ({}: ForceUpdateProps) => { | ||
const [showModal, setShowModal] = useState(false); | ||
|
||
useEffect(() => { | ||
const checkAndUpdate = async () => { | ||
const updated = await isUpdated(); | ||
if (!updated) { | ||
setShowModal(true); | ||
} | ||
}; | ||
checkAndUpdate(); | ||
}, []); | ||
|
||
return ( | ||
<Modal animationType="slide" transparent={true} visible={showModal}> | ||
<View style={styles.centeredView}> | ||
<View style={styles.modalView}> | ||
<Text style={styles.modalText}>{translate('alert.update')}</Text> | ||
<Button title={translate('buttons.ok')} onPress={openStore} /> | ||
</View> | ||
</View> | ||
</View> | ||
</Modal> | ||
); | ||
</Modal> | ||
); | ||
}; | ||
|
||
export { ForceUpdateModal }; |
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,44 @@ | ||
import { Linking, Platform } from 'react-native'; | ||
import DeviceInfo from 'react-native-device-info'; | ||
|
||
import remoteConfig from '@react-native-firebase/remote-config'; | ||
|
||
export const isUpdated = async (): Promise<boolean> => { | ||
remoteConfig().setDefaults({ | ||
minimum_version: '', | ||
}); | ||
|
||
const fetchedRemotely = await remoteConfig().fetchAndActivate(); | ||
|
||
if (fetchedRemotely) { | ||
const remoteVersion = remoteConfig().getValue('').asString(); | ||
const localVersion = DeviceInfo.getVersion(); | ||
return compareVersions(localVersion, remoteVersion); | ||
} | ||
return true; | ||
}; | ||
|
||
export const openStore = () => { | ||
Platform.select({ | ||
ios: Linking.openURL(''), | ||
android: Linking.openURL(''), | ||
}); | ||
}; | ||
|
||
function compareVersions(local: string, remote: string): boolean { | ||
const localVersion = local.split('.').map(versionNumber => parseInt(versionNumber, 10)); | ||
const remoteVersion = remote.split('.').map(versionNumber => parseInt(versionNumber, 10)); | ||
|
||
for (let i = 0; i < Math.max(localVersion.length, remoteVersion.length); i++) { | ||
const localVersionComponent = localVersion[i] || 0; | ||
const remoteVersionComponent = remoteVersion[i] || 0; | ||
|
||
if (localVersionComponent < remoteVersionComponent) { | ||
return false; | ||
} else if (localVersionComponent > remoteVersionComponent) { | ||
return true; | ||
} | ||
} | ||
|
||
return true; | ||
} |
This file was deleted.
Oops, something went wrong.