forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
The app detects a new version, downloads it, and when it loses focus and comes back, the update takes effect — the title changes to “Boa Tarde".
However, when we restart the app, it reverts to the previous titles instead of keeping “Boa tarde”.
react-native-code-push: "^8.3.1"
I check for a new version in my AfterSplash (i alredy tried with the codePush.notifyAppReady() on my useEffect, above of checkForUpdate() and the result its the same):
import React from 'react';
import { UIBlock } from '@/components/UI/Block';
import { useAuthentication, useCodePush } from '@/hooks';
export const AfterSplash = () => {
const { checkIsAuthenticated } = useAuthentication();
const { checkForUpdate } = useCodePush();
React.useEffect(() => {
checkForUpdate();
checkIsAuthenticated();
}, [checkForUpdate, checkIsAuthenticated]);
return <UIBlock />;
};
My custom hook:
import React, { useCallback } from 'react';
import { useCodePushStore } from '@/stores';
import { useNavigation } from '@react-navigation/native';
import CodePush from 'react-native-code-push';
export const useCodePush = () => {
const { goBack } = useNavigation();
const {
updateInfo,
updateAvailable,
installProgress,
setInstallProgress,
checkingForUpdate,
setCheckingForUpdate,
setUpdateInfo,
isInstalling,
setIsInstalling,
} = useCodePushStore();
const checkForUpdate = useCallback(async () => {
setCheckingForUpdate(true);
try {
const update = await CodePush.checkForUpdate();
if (update) {
setUpdateInfo(update);
installUpdate();
}
} catch (error) {
console.error('[CodePush] Error checking for update:', error);
} finally {
setCheckingForUpdate(false);
}
}, [installUpdate, setCheckingForUpdate, setUpdateInfo]);
const installUpdate = useCallback(async () => {
try {
setIsInstalling(true);
setInstallProgress(0);
await CodePush.sync(
{
installMode: CodePush.InstallMode.ON_NEXT_SUSPEND,
mandatoryInstallMode: CodePush.InstallMode.ON_NEXT_SUSPEND,
},
status => {
switch (status) {
case CodePush.SyncStatus.UPDATE_INSTALLED:
setIsInstalling(false);
break;
case CodePush.SyncStatus.UP_TO_DATE:
break;
}
},
({ receivedBytes, totalBytes }) => {
const progress = (receivedBytes / totalBytes) * 100;
setInstallProgress(progress);
},
);
} catch (error) {
console.error('[CodePush] Error during background sync:', error);
setIsInstalling(false);
}
}, [setInstallProgress, setIsInstalling]);
const updateCompleted = React.useMemo(() => {
return installProgress === 100 && !isInstalling;
}, [installProgress, isInstalling]);
const cancelUpdate = useCallback(() => {
goBack();
}, [goBack]);
return {
updateAvailable,
updateInfo,
installProgress,
isInstalling,
checkingForUpdate,
cancelUpdate,
checkForUpdate,
updateCompleted,
};
};
Metadata
Metadata
Assignees
Labels
No labels