diff options
Diffstat (limited to 'src/components/StarterPack')
-rw-r--r-- | src/components/StarterPack/QrCode.tsx | 17 | ||||
-rw-r--r-- | src/components/StarterPack/QrCodeDialog.tsx | 90 |
2 files changed, 60 insertions, 47 deletions
diff --git a/src/components/StarterPack/QrCode.tsx b/src/components/StarterPack/QrCode.tsx index 8ce5cbbb1..c6408109b 100644 --- a/src/components/StarterPack/QrCode.tsx +++ b/src/components/StarterPack/QrCode.tsx @@ -1,18 +1,23 @@ import React from 'react' import {View} from 'react-native' import QRCode from 'react-native-qrcode-styled' -import ViewShot from 'react-native-view-shot' +import type ViewShot from 'react-native-view-shot' import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api' import {Trans} from '@lingui/macro' -import {isWeb} from 'platform/detection' -import {Logo} from 'view/icons/Logo' -import {Logotype} from 'view/icons/Logotype' +import {isWeb} from '#/platform/detection' +import {Logo} from '#/view/icons/Logo' +import {Logotype} from '#/view/icons/Logotype' import {useTheme} from '#/alf' import {atoms as a} from '#/alf' import {LinearGradientBackground} from '#/components/LinearGradientBackground' import {Text} from '#/components/Typography' +const LazyViewShot = React.lazy( + // @ts-expect-error dynamic import + () => import('react-native-view-shot/src/index'), +) + interface Props { starterPack: AppBskyGraphDefs.StarterPackView link: string @@ -29,7 +34,7 @@ export const QrCode = React.forwardRef<ViewShot, Props>(function QrCode( } return ( - <ViewShot ref={ref}> + <LazyViewShot ref={ref}> <LinearGradientBackground style={[ {width: 300, minHeight: 390}, @@ -79,7 +84,7 @@ export const QrCode = React.forwardRef<ViewShot, Props>(function QrCode( </Text> </View> </LinearGradientBackground> - </ViewShot> + </LazyViewShot> ) }) diff --git a/src/components/StarterPack/QrCodeDialog.tsx b/src/components/StarterPack/QrCodeDialog.tsx index a884390bf..b2af8ff73 100644 --- a/src/components/StarterPack/QrCodeDialog.tsx +++ b/src/components/StarterPack/QrCodeDialog.tsx @@ -1,6 +1,6 @@ import React from 'react' import {View} from 'react-native' -import ViewShot from 'react-native-view-shot' +import type ViewShot from 'react-native-view-shot' import {requestMediaLibraryPermissionsAsync} from 'expo-image-picker' import {createAssetAsync} from 'expo-media-library' import * as Sharing from 'expo-sharing' @@ -8,9 +8,9 @@ import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {logEvent} from '#/lib/statsig/statsig' import {logger} from '#/logger' -import {logEvent} from 'lib/statsig/statsig' -import {isNative, isWeb} from 'platform/detection' +import {isNative, isWeb} from '#/platform/detection' import * as Toast from '#/view/com/util/Toast' import {atoms as a} from '#/alf' import {Button, ButtonText} from '#/components/Button' @@ -153,46 +153,54 @@ export function QrCodeDialog({ <Dialog.ScrollableInner label={_(msg`Create a QR code for a starter pack`)}> <View style={[a.flex_1, a.align_center, a.gap_5xl]}> - {!link ? ( - <View style={[a.align_center, a.p_xl]}> - <Loader size="xl" /> - </View> - ) : ( - <> - <QrCode starterPack={starterPack} link={link} ref={ref} /> - {isProcessing ? ( - <View> - <Loader size="xl" /> - </View> - ) : ( - <View - style={[a.w_full, a.gap_md, isWeb && [a.flex_row_reverse]]}> - <Button - label={_(msg`Copy QR code`)} - variant="solid" - color="secondary" - size="small" - onPress={isWeb ? onCopyPress : onSharePress}> - <ButtonText> - {isWeb ? <Trans>Copy</Trans> : <Trans>Share</Trans>} - </ButtonText> - </Button> - <Button - label={_(msg`Save QR code`)} - variant="solid" - color="secondary" - size="small" - onPress={onSavePress}> - <ButtonText> - <Trans>Save</Trans> - </ButtonText> - </Button> - </View> - )} - </> - )} + <React.Suspense fallback={<Loading />}> + {!link ? ( + <Loading /> + ) : ( + <> + <QrCode starterPack={starterPack} link={link} ref={ref} /> + {isProcessing ? ( + <View> + <Loader size="xl" /> + </View> + ) : ( + <View + style={[a.w_full, a.gap_md, isWeb && [a.flex_row_reverse]]}> + <Button + label={_(msg`Copy QR code`)} + variant="solid" + color="secondary" + size="small" + onPress={isWeb ? onCopyPress : onSharePress}> + <ButtonText> + {isWeb ? <Trans>Copy</Trans> : <Trans>Share</Trans>} + </ButtonText> + </Button> + <Button + label={_(msg`Save QR code`)} + variant="solid" + color="secondary" + size="small" + onPress={onSavePress}> + <ButtonText> + <Trans>Save</Trans> + </ButtonText> + </Button> + </View> + )} + </> + )} + </React.Suspense> </View> </Dialog.ScrollableInner> </Dialog.Outer> ) } + +function Loading() { + return ( + <View style={[a.align_center, a.p_xl]}> + <Loader size="xl" /> + </View> + ) +} |