App : écran de mise à jour (barre de progression et pourcentage) puis invitation à relancer l'application
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
dd629b6af2
commit
0452865b82
4 changed files with 101 additions and 3 deletions
|
|
@ -72,7 +72,9 @@ L'adresse de l'API utilisée est celle du fichier `pro/.env`.
|
||||||
## Mettre à jour l'app sans recompiler (EAS Update)
|
## Mettre à jour l'app sans recompiler (EAS Update)
|
||||||
|
|
||||||
Depuis l'ajout d'`expo-updates`, les modifications du code de l'app (écrans, textes, icônes, corrections) se publient
|
Depuis l'ajout d'`expo-updates`, les modifications du code de l'app (écrans, textes, icônes, corrections) se publient
|
||||||
**sans nouvelle compilation** : l'app télécharge la mise à jour à son ouverture et l'applique au lancement suivant.
|
**sans nouvelle compilation**. Au lancement, l'app vérifie s'il existe une nouvelle version : si oui, elle affiche
|
||||||
|
l'écran « Mise à jour en cours » avec une barre de progression et le pourcentage, puis « Mise à jour installée » avec
|
||||||
|
le bouton « Relancer l'application ». Sans mise à jour ou sans réseau, rien ne s'affiche et l'app démarre normalement.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npx eas-cli update --channel production --message "Description courte du changement"
|
npx eas-cli update --channel production --message "Description courte du changement"
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,9 @@
|
||||||
"policy": "appVersion"
|
"policy": "appVersion"
|
||||||
},
|
},
|
||||||
"updates": {
|
"updates": {
|
||||||
"url": "https://u.expo.dev/2ac42d3a-9ded-4115-a8f5-0d3dbc9fe9ad"
|
"url": "https://u.expo.dev/2ac42d3a-9ded-4115-a8f5-0d3dbc9fe9ad",
|
||||||
|
"checkAutomatically": "NEVER",
|
||||||
|
"fallbackToCacheTimeout": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import {
|
||||||
} from '@expo-google-fonts/figtree';
|
} from '@expo-google-fonts/figtree';
|
||||||
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||||
import { SessionProvider, useSession } from '../src/session';
|
import { SessionProvider, useSession } from '../src/session';
|
||||||
|
import { UpdateGate } from '../src/UpdateGate';
|
||||||
import { font, useColors } from '../src/theme';
|
import { font, useColors } from '../src/theme';
|
||||||
|
|
||||||
SplashScreen.preventAutoHideAsync();
|
SplashScreen.preventAutoHideAsync();
|
||||||
|
|
@ -66,7 +67,9 @@ export default function RootLayout() {
|
||||||
<SafeAreaProvider>
|
<SafeAreaProvider>
|
||||||
<SessionProvider>
|
<SessionProvider>
|
||||||
<StatusBar style="auto" />
|
<StatusBar style="auto" />
|
||||||
<Navigator />
|
<UpdateGate>
|
||||||
|
<Navigator />
|
||||||
|
</UpdateGate>
|
||||||
</SessionProvider>
|
</SessionProvider>
|
||||||
</SafeAreaProvider>
|
</SafeAreaProvider>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
91
pro/src/UpdateGate.tsx
Normal file
91
pro/src/UpdateGate.tsx
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
import { ReactNode, useEffect, useState } from 'react';
|
||||||
|
import { StyleSheet, View } from 'react-native';
|
||||||
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||||
|
import * as Updates from 'expo-updates';
|
||||||
|
import { Icon } from './icons';
|
||||||
|
import { BrandSymbol, Button, T } from './ui';
|
||||||
|
import { font, useColors } from './theme';
|
||||||
|
|
||||||
|
type Phase = 'idle' | 'downloading' | 'ready';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mises à jour à distance (EAS Update) : au lancement, si une nouvelle version existe, elle est téléchargée
|
||||||
|
* avec une barre de progression, puis l'app demande à être relancée pour l'appliquer.
|
||||||
|
* Sans mise à jour, en développement ou en cas d'erreur réseau : rien ne s'affiche, l'app démarre normalement.
|
||||||
|
*/
|
||||||
|
export function UpdateGate({ children }: { children: ReactNode }) {
|
||||||
|
const c = useColors();
|
||||||
|
const { downloadProgress } = Updates.useUpdates();
|
||||||
|
const [phase, setPhase] = useState<Phase>('idle');
|
||||||
|
const [restarting, setRestarting] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (__DEV__ || !Updates.isEnabled) return;
|
||||||
|
let cancelled = false;
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const check = await Updates.checkForUpdateAsync();
|
||||||
|
if (cancelled || !check.isAvailable) return;
|
||||||
|
setPhase('downloading');
|
||||||
|
const result = await Updates.fetchUpdateAsync();
|
||||||
|
if (!cancelled) setPhase(result.isNew ? 'ready' : 'idle');
|
||||||
|
} catch {
|
||||||
|
// Pas de réseau ou serveur indisponible : l'app continue avec la version installée.
|
||||||
|
if (!cancelled) setPhase('idle');
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
async function restart() {
|
||||||
|
setRestarting(true);
|
||||||
|
try {
|
||||||
|
await Updates.reloadAsync();
|
||||||
|
} catch {
|
||||||
|
setRestarting(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const percent = Math.max(0, Math.min(100, Math.round((downloadProgress ?? 0) * 100)));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={{ flex: 1 }}>
|
||||||
|
{children}
|
||||||
|
{phase !== 'idle' && (
|
||||||
|
<View style={[StyleSheet.absoluteFill, { backgroundColor: c.bg }]} accessibilityViewIsModal>
|
||||||
|
<SafeAreaView style={{ flex: 1, padding: 28, justifyContent: 'center', gap: 28 }}>
|
||||||
|
<View style={{ alignItems: 'center', gap: 16 }}>
|
||||||
|
<View style={{ width: 96, height: 96, borderRadius: 28, backgroundColor: c.primarySoft, alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
{phase === 'ready' ? <Icon name="checkCircle" size={52} color={c.primary} /> : <BrandSymbol size={60} />}
|
||||||
|
</View>
|
||||||
|
<T v="h1" accessibilityRole="header" style={{ textAlign: 'center' }}>
|
||||||
|
{phase === 'ready' ? 'Mise à jour installée' : 'Mise à jour en cours'}
|
||||||
|
</T>
|
||||||
|
<T v="muted" style={{ textAlign: 'center' }}>
|
||||||
|
{phase === 'ready'
|
||||||
|
? 'Une nouvelle version de MonEspacePro a été installée. Relancez l’application pour l’utiliser.'
|
||||||
|
: 'Une nouvelle version de MonEspacePro est disponible. Ne fermez pas l’application pendant le téléchargement.'}
|
||||||
|
</T>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
{phase === 'downloading' ? (
|
||||||
|
<View style={{ gap: 10 }} accessibilityRole="progressbar" accessibilityValue={{ min: 0, max: 100, now: percent, text: `${percent} %` }}>
|
||||||
|
<View style={{ height: 14, borderRadius: 7, backgroundColor: c.surface2, overflow: 'hidden' }}>
|
||||||
|
<View style={{ width: `${percent}%`, height: '100%', borderRadius: 7, backgroundColor: c.primary }} />
|
||||||
|
</View>
|
||||||
|
<View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
|
||||||
|
<T v="muted" style={{ fontSize: 14 }}>Téléchargement…</T>
|
||||||
|
<T style={{ fontFamily: font.bold, fontSize: 14, color: c.primary }}>{percent} %</T>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
) : (
|
||||||
|
<Button large label="Relancer l’application" onPress={restart} loading={restarting} />
|
||||||
|
)}
|
||||||
|
</SafeAreaView>
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue