Skip to content

Commit

Permalink
handle expo updates
Browse files Browse the repository at this point in the history
  • Loading branch information
OverGlass committed Jul 25, 2024
1 parent 0005a7d commit 024eccf
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 17 deletions.
3 changes: 2 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@
"typedRoutes": true
},
"updates": {
"url": "https://u.expo.dev/3b41ebc2-860e-4ccb-a101-5edc6b0c7558"
"url": "https://u.expo.dev/3b41ebc2-860e-4ccb-a101-5edc6b0c7558",
"checkAutomatically": "NEVER"
}
}
}
6 changes: 4 additions & 2 deletions app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function Root() {
const [isFontsLoaded] = useImportFont()
useRegisterRoutingInstrumentation()
const insets = useSafeAreaInsets()
const { isBuildUpdateAvailable, checkForUpdate } = useAppUpdate()
const { isBuildUpdateAvailable, checkForUpdate, isUpdateAvailable } = useAppUpdate()

useEffect(() => {
const subscription = AppState.addEventListener('change', (nextAppState) => {
Expand All @@ -103,7 +103,9 @@ function Root() {
<SessionProvider>
<VoxToast />
<ToastViewport flexDirection="column" top={getTokenValue('$4', 'space') + insets.top} left={insets.left} right={insets.right} />
<WaitingRoomHoc isLoading={!isFontsLoaded}>{isBuildUpdateAvailable && !isWeb ? <UpdateScreen /> : <Slot />}</WaitingRoomHoc>
<WaitingRoomHoc isLoading={!isFontsLoaded}>
{(isBuildUpdateAvailable || isUpdateAvailable) && !isWeb ? <UpdateScreen isBuildUpdate={isBuildUpdateAvailable} /> : <Slot />}
</WaitingRoomHoc>
</SessionProvider>
</PortalProvider>
</ThemeProvider>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"expo-sharing": "~12.0.1",
"expo-splash-screen": "~0.27.4",
"expo-status-bar": "~1.12.1",
"expo-updates": "~0.25.20",
"expo-updates": "~0.25.21",
"expo-web-browser": "~13.0.3",
"firebase": "^10.7.1",
"formik": "^2.4.5",
Expand Down
20 changes: 19 additions & 1 deletion src/hooks/useAppUpdate.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { useEffect, useState } from 'react'
import { Platform } from 'react-native'
import { checkVersion } from 'react-native-check-version'
import { ErrorMonitor } from '@/utils/ErrorMonitor'
import { nativeApplicationVersion } from 'expo-application'
import { checkForUpdateAsync, fetchUpdateAsync, useUpdates } from 'expo-updates'
import { isWeb } from 'tamagui'

const updates = useUpdates()

export default function useAppUpdate() {
const [isBuildUpdateAvailable, setIsBuildUpdateAvailable] = useState(false)

Expand All @@ -23,7 +27,20 @@ export default function useAppUpdate() {
setIsBuildUpdateAvailable(true)
}
}
return checkStoreUpdate()

const checkExpoUpdate = async () => {
try {
const update = await checkForUpdateAsync()

if (update.isAvailable) {
await fetchUpdateAsync()
}
} catch (error) {
ErrorMonitor.log('Expo update failed', error)
}
}

return Promise.allSettled([checkExpoUpdate(), checkStoreUpdate()])
}

useEffect(() => {
Expand All @@ -33,5 +50,6 @@ export default function useAppUpdate() {
return {
isBuildUpdateAvailable,
checkForUpdate,
...updates,
}
}
17 changes: 14 additions & 3 deletions src/screens/update/updateScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@ import { useCallback } from 'react'
import Text from '@/components/base/Text'
import Title from '@/components/Title/Title'
import redirectToStore from '@/helpers/redirectToStore'
import useAppUpdate from '@/hooks/useAppUpdate'
import useAsyncFn from '@/hooks/useAsyncFn'
import { reloadAsync } from 'expo-updates'
import { Button, Image, Spinner, View, YStack } from 'tamagui'

export default function UpdateScreen() {
interface Props {
isBuildUpdate?: boolean
}

export default function UpdateScreen({ isBuildUpdate = false }: Props) {
const { isDownloading } = useAppUpdate()
const { isProcessing, trigger: onUpdate } = useAsyncFn(
useCallback(async () => {
await redirectToStore()
if (isBuildUpdate) {
await redirectToStore()
} else {
await reloadAsync()
}
}, []),
)

const isDisabled = isProcessing
const isDisabled = isProcessing || isDownloading

return (
<View height="100%">
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1403,10 +1403,10 @@
dotenv-expand "~11.0.6"
getenv "^1.0.0"

"@expo/fingerprint@^0.10.1":
version "0.10.1"
resolved "https://registry.yarnpkg.com/@expo/fingerprint/-/fingerprint-0.10.1.tgz#12055d425425884258b69e4cd6bbeed35fd2a6e8"
integrity sha512-0d0lniPAm6tOZinoj6d8JPozdeaYL12hNW2lZy76YaRRfBoAVGD1xwx6pilRumgKJGFL2SxOGnRoC4ZarZel4g==
"@expo/fingerprint@^0.10.2":
version "0.10.2"
resolved "https://registry.yarnpkg.com/@expo/fingerprint/-/fingerprint-0.10.2.tgz#120a0d030dfa7b8c317cf5dc55379d06548e82f8"
integrity sha512-q75zb4AeB08efofCnEJIddS7kCe0TX8YjHSat204mq1RLUJjv2JAN1Zgyk5HW/4i8b/sMYst0HX+BLCtszb+2A==
dependencies:
"@expo/spawn-async" "^1.7.2"
chalk "^4.1.2"
Expand Down Expand Up @@ -11761,15 +11761,15 @@ expo-updates-interface@~0.16.2:
resolved "https://registry.yarnpkg.com/expo-updates-interface/-/expo-updates-interface-0.16.2.tgz#ad1ac2ca8ee5a8cc84052ea3c18a11da64da569b"
integrity sha512-929XBU70q5ELxkKADj1xL0UIm3HvhYhNAOZv5DSk7rrKvLo7QDdPyl+JVnwZm9LrkNbH4wuE2rLoKu1KMgZ+9A==

expo-updates@~0.25.20:
version "0.25.20"
resolved "https://registry.yarnpkg.com/expo-updates/-/expo-updates-0.25.20.tgz#a3a597260e8a4c792ef5b4dd5aa8aba671228265"
integrity sha512-EfxRZDPNUWFXTsjn4Ii+AwIp/KLHXGKG59R8kyWzz/nHeMxXqGUDQF79qcgXcaq5lOMUpeGNlZqOBGho9cvUEg==
expo-updates@~0.25.21:
version "0.25.21"
resolved "https://registry.yarnpkg.com/expo-updates/-/expo-updates-0.25.21.tgz#4b117ee23261e386382c24154600d782b6b0765b"
integrity sha512-eNElrzLFHky2au0H8MqdAJdqh40412PHCdANdXtB/P/XIS1xVte74T9rUf053iPswnLLuQfCUpZYSfRKTcsDlg==
dependencies:
"@expo/code-signing-certificates" "0.0.5"
"@expo/config" "~9.0.0-beta.0"
"@expo/config-plugins" "~8.0.8"
"@expo/fingerprint" "^0.10.1"
"@expo/fingerprint" "^0.10.2"
"@expo/spawn-async" "^1.7.2"
arg "4.1.0"
chalk "^4.1.2"
Expand Down

0 comments on commit 024eccf

Please sign in to comment.