-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: misc screens UI and logic updates (#361)
* feat: misc screens UI and logic updates * chore: add translation to update cta * test: fix tests due to component updates
- Loading branch information
Showing
15 changed files
with
325 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
getBundleId: jest.fn(), | ||
getVersion: jest.fn(), | ||
}; |
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
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
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
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
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,4 @@ | ||
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
jest.mock('react-native-safe-area-context', () => mockSafeAreaContext); |
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
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,22 +1,39 @@ | ||
import React from 'react'; | ||
import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
|
||
import { config } from '$core/constants'; | ||
import { StoreUpdateBanner } from '$shared/components/StoreUpdateBanner'; | ||
import { Box, Text } from '$shared/uiKit/primitives'; | ||
|
||
export function Version() { | ||
if (!config.version || !config.buildNumber) { | ||
const insets = useSafeAreaInsets(); | ||
|
||
if (!config.version) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Box alignItems="flex-end" pt="spacing_32"> | ||
<Text variant="small"> | ||
{`Version: v${config.version}:${config.buildNumber}`} | ||
</Text> | ||
<Box | ||
pb="spacing_8" | ||
style={{ | ||
marginBottom: insets.bottom, | ||
}} | ||
> | ||
<Box px="spacing_24"> | ||
<StoreUpdateBanner /> | ||
</Box> | ||
|
||
<Box alignItems="flex-end" pt="spacing_32" px="spacing_24"> | ||
<Text variant="small"> | ||
{`Version: v${config.version}${ | ||
config.buildNumber ? `:${config.buildNumber}` : '' | ||
}`} | ||
</Text> | ||
|
||
{typeof config.runtimeVersion === 'string' && ( | ||
<Text variant="small">{`Runtime: v${config.runtimeVersion}`}</Text> | ||
)} | ||
{typeof config.runtimeVersion === 'string' && ( | ||
<Text variant="small">{`Runtime: v${config.runtimeVersion}`}</Text> | ||
)} | ||
</Box> | ||
</Box> | ||
); | ||
} |
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
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
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
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,63 @@ | ||
import React, { useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { Logger } from '$core/logger'; | ||
import { useRunOnMount } from '$shared/hooks/useRunOnMount'; | ||
import { Button } from '$shared/uiKit/button'; | ||
import { Box, Text } from '$shared/uiKit/primitives'; | ||
import { checkForNativeUpdate } from '$shared/utils/checkForAppUpdates'; | ||
|
||
type UpdateStatus = { | ||
shouldUpdate: boolean; | ||
startUpdate: () => Promise<void>; | ||
storeVersion: string | null; | ||
currentVersion: string | null; | ||
}; | ||
|
||
export function StoreUpdateBanner() { | ||
const [updateStatus, setUpdateStatus] = useState<UpdateStatus>(); | ||
|
||
const { t } = useTranslation('settings'); | ||
|
||
useRunOnMount(() => { | ||
checkForNativeUpdate({ | ||
title: t('updateAvailable.nativePrompt.title'), | ||
message: t('updateAvailable.nativePrompt.message'), | ||
buttonUpgradeText: t('updateAvailable.nativePrompt.updateCta'), | ||
buttonCancelText: t('cancel', { | ||
ns: 'common', | ||
}), | ||
}) | ||
.then((status) => { | ||
setUpdateStatus(status); | ||
}) | ||
.catch((error: Error) => { | ||
Logger.error({ | ||
error, | ||
level: 'warning', | ||
message: 'Failed to check for native update', | ||
}); | ||
}); | ||
}); | ||
|
||
if (!updateStatus?.shouldUpdate) return null; | ||
|
||
return ( | ||
<Box bg="yellow" borderRadius="radius_8" px="spacing_16" py="spacing_8"> | ||
<Text textAlign="center"> | ||
{updateStatus.storeVersion | ||
? t('updateAvailable.banner.compareVersions', { | ||
currentVersion: updateStatus.currentVersion, | ||
storeVersion: updateStatus.storeVersion, | ||
}) | ||
: t('updateAvailable.banner.defaultTitle')} | ||
</Text> | ||
|
||
<Box alignItems="center" pt="spacing_8"> | ||
<Button.Text onPress={updateStatus.startUpdate}> | ||
{t('updateAvailable.banner.updateCta')} | ||
</Button.Text> | ||
</Box> | ||
</Box> | ||
); | ||
} |
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
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,64 @@ | ||
import * as Application from 'expo-application'; | ||
import * as Updates from 'expo-updates'; | ||
import type { StartUpdateOptions } from 'sp-react-native-in-app-updates'; | ||
import SpInAppUpdates, { IAUUpdateKind } from 'sp-react-native-in-app-updates'; | ||
|
||
import { config, isAndroid } from '$core/constants'; | ||
import { Logger } from '$core/logger'; | ||
|
||
import { sleep } from './sleep'; | ||
|
||
export const checkForOtaUpdate = async () => { | ||
try { | ||
const update = await Updates.checkForUpdateAsync(); | ||
|
||
if (update.isAvailable) { | ||
const ONE_SECOND = 1_000; | ||
|
||
await Updates.fetchUpdateAsync(); | ||
await Updates.reloadAsync(); | ||
await sleep(ONE_SECOND); | ||
} | ||
} catch (error) { | ||
Logger.error({ | ||
error, | ||
level: 'warning', | ||
message: 'Error fetching latest Expo update', | ||
}); | ||
} | ||
}; | ||
|
||
export const checkForNativeUpdate = async ( | ||
updateOptionsOverwrites: StartUpdateOptions, | ||
) => { | ||
const inAppUpdates = new SpInAppUpdates(config.isDebug); | ||
|
||
const currentVersion = Application.nativeApplicationVersion; | ||
let updateOptions: StartUpdateOptions = {}; | ||
const { shouldUpdate, storeVersion } = await inAppUpdates.checkNeedsUpdate(); | ||
|
||
if (shouldUpdate) { | ||
if (isAndroid) { | ||
updateOptions = { | ||
...updateOptionsOverwrites, | ||
updateType: IAUUpdateKind.FLEXIBLE, | ||
}; | ||
} else { | ||
updateOptions = updateOptionsOverwrites; | ||
} | ||
|
||
return { | ||
shouldUpdate, | ||
startUpdate: async () => inAppUpdates.startUpdate(updateOptions), | ||
storeVersion, | ||
currentVersion, | ||
}; | ||
} | ||
|
||
return { | ||
shouldUpdate: false, | ||
startUpdate: async () => {}, | ||
storeVersion, | ||
currentVersion, | ||
}; | ||
}; |
Oops, something went wrong.