|
| 1 | +import { getStoreUrlAsync } from '@app/screens/DevTools/utils/getStoreUrlAsync'; |
| 2 | +import { openLinkInBrowser } from '@app/utils/browser/openLinkInBrowser'; |
| 3 | +import * as Application from 'expo-application'; |
| 4 | +import { useState } from 'react'; |
| 5 | +import { Modal as RNModal, View } from 'react-native'; |
| 6 | +import { useSafeAreaInsets } from 'react-native-safe-area-context'; |
| 7 | +import { StyleSheet } from 'react-native-unistyles'; |
| 8 | +import { Button } from '../Button'; |
| 9 | +import { IconSymbol } from '../IconSymbol/IconSymbol'; |
| 10 | +import { Typography } from '../Typography'; |
| 11 | + |
| 12 | +interface ForceUpdateModalProps { |
| 13 | + isVisible: boolean; |
| 14 | + minimumVersion: string; |
| 15 | +} |
| 16 | + |
| 17 | +export function ForceUpdateModal({ |
| 18 | + isVisible, |
| 19 | + minimumVersion, |
| 20 | +}: ForceUpdateModalProps) { |
| 21 | + const [isLoading, setIsLoading] = useState(false); |
| 22 | + const insets = useSafeAreaInsets(); |
| 23 | + |
| 24 | + const handleUpdatePress = async () => { |
| 25 | + setIsLoading(true); |
| 26 | + try { |
| 27 | + const storeUrl = await getStoreUrlAsync(); |
| 28 | + if (storeUrl) { |
| 29 | + openLinkInBrowser(storeUrl); |
| 30 | + } |
| 31 | + } finally { |
| 32 | + setIsLoading(false); |
| 33 | + } |
| 34 | + }; |
| 35 | + |
| 36 | + const currentVersion = Application.nativeApplicationVersion ?? 'Unknown'; |
| 37 | + |
| 38 | + return ( |
| 39 | + <RNModal |
| 40 | + animationType="fade" |
| 41 | + transparent |
| 42 | + visible={isVisible} |
| 43 | + statusBarTranslucent |
| 44 | + > |
| 45 | + <View style={[styles.overlay, { paddingTop: insets.top }]}> |
| 46 | + <View style={styles.card}> |
| 47 | + <View style={styles.iconContainer}> |
| 48 | + <IconSymbol name="arrow.up" /> |
| 49 | + </View> |
| 50 | + |
| 51 | + <Typography color="gray" size="xl" fontWeight="bold" align="center"> |
| 52 | + Update Required |
| 53 | + </Typography> |
| 54 | + |
| 55 | + <Typography |
| 56 | + color="gray.textLow" |
| 57 | + size="sm" |
| 58 | + align="left" |
| 59 | + style={styles.subtitle} |
| 60 | + > |
| 61 | + A new version of Foam is available. Please update to continue using |
| 62 | + the app. |
| 63 | + </Typography> |
| 64 | + |
| 65 | + <View style={styles.versionInfo}> |
| 66 | + <View style={styles.versionRow}> |
| 67 | + <Typography color="gray.textLow" size="xs"> |
| 68 | + Current version |
| 69 | + </Typography> |
| 70 | + <Typography color="gray" size="xs" fontWeight="semiBold"> |
| 71 | + {currentVersion} |
| 72 | + </Typography> |
| 73 | + </View> |
| 74 | + <View style={styles.versionRow}> |
| 75 | + <Typography color="gray.textLow" size="xs"> |
| 76 | + Minimum required |
| 77 | + </Typography> |
| 78 | + <Typography color="gray" size="xs" fontWeight="semiBold"> |
| 79 | + {minimumVersion} |
| 80 | + </Typography> |
| 81 | + </View> |
| 82 | + </View> |
| 83 | + |
| 84 | + <Button |
| 85 | + // eslint-disable-next-line @typescript-eslint/no-misused-promises |
| 86 | + onPress={handleUpdatePress} |
| 87 | + style={styles.updateButton} |
| 88 | + disabled={isLoading} |
| 89 | + > |
| 90 | + <Typography color="accent" contrast size="md" fontWeight="semiBold"> |
| 91 | + {isLoading ? 'Opening Store...' : 'Update Now'} |
| 92 | + </Typography> |
| 93 | + </Button> |
| 94 | + </View> |
| 95 | + </View> |
| 96 | + </RNModal> |
| 97 | + ); |
| 98 | +} |
| 99 | + |
| 100 | +const styles = StyleSheet.create(theme => ({ |
| 101 | + overlay: { |
| 102 | + flex: 1, |
| 103 | + backgroundColor: 'rgba(0, 0, 0, 0.85)', |
| 104 | + justifyContent: 'center' as const, |
| 105 | + alignItems: 'center' as const, |
| 106 | + paddingHorizontal: theme.spacing.lg, |
| 107 | + }, |
| 108 | + card: { |
| 109 | + backgroundColor: theme.colors.gray.bgAlt, |
| 110 | + borderRadius: theme.radii.lg, |
| 111 | + paddingHorizontal: theme.spacing.xl, |
| 112 | + paddingVertical: theme.spacing.xl, |
| 113 | + width: '100%', |
| 114 | + maxWidth: 340, |
| 115 | + alignItems: 'center' as const, |
| 116 | + borderWidth: 1, |
| 117 | + borderColor: theme.colors.gray.border, |
| 118 | + }, |
| 119 | + iconContainer: { |
| 120 | + width: 72, |
| 121 | + height: 72, |
| 122 | + borderRadius: 36, |
| 123 | + backgroundColor: theme.colors.accent.ui, |
| 124 | + justifyContent: 'center' as const, |
| 125 | + alignItems: 'center' as const, |
| 126 | + marginBottom: theme.spacing.lg, |
| 127 | + }, |
| 128 | + icon: { |
| 129 | + fontSize: 32, |
| 130 | + }, |
| 131 | + subtitle: { |
| 132 | + marginBottom: theme.spacing.lg, |
| 133 | + marginTop: theme.spacing.sm, |
| 134 | + lineHeight: 20, |
| 135 | + }, |
| 136 | + versionInfo: { |
| 137 | + width: '100%', |
| 138 | + backgroundColor: theme.colors.gray.ui, |
| 139 | + borderRadius: theme.radii.md, |
| 140 | + padding: theme.spacing.md, |
| 141 | + marginBottom: theme.spacing.lg, |
| 142 | + gap: theme.spacing.xs, |
| 143 | + }, |
| 144 | + versionRow: { |
| 145 | + flexDirection: 'row' as const, |
| 146 | + justifyContent: 'space-between' as const, |
| 147 | + alignItems: 'center' as const, |
| 148 | + }, |
| 149 | + updateButton: { |
| 150 | + width: '100%', |
| 151 | + backgroundColor: theme.colors.accent.accent, |
| 152 | + borderRadius: theme.radii.md, |
| 153 | + paddingVertical: theme.spacing.md, |
| 154 | + alignItems: 'center' as const, |
| 155 | + justifyContent: 'center' as const, |
| 156 | + }, |
| 157 | +})); |
0 commit comments