mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {View} from 'react-native'
3// @ts-expect-error missing types
4import QRCode from 'react-native-qrcode-styled'
5import type ViewShot from 'react-native-view-shot'
6import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api'
7import {Trans} from '@lingui/macro'
8
9import {isWeb} from '#/platform/detection'
10import {Logo} from '#/view/icons/Logo'
11import {Logotype} from '#/view/icons/Logotype'
12import {useTheme} from '#/alf'
13import {atoms as a} from '#/alf'
14import {LinearGradientBackground} from '#/components/LinearGradientBackground'
15import {Text} from '#/components/Typography'
16
17const LazyViewShot = React.lazy(
18 // @ts-expect-error dynamic import
19 () => import('react-native-view-shot/src/index'),
20)
21
22interface Props {
23 starterPack: AppBskyGraphDefs.StarterPackView
24 link: string
25}
26
27export const QrCode = React.forwardRef<ViewShot, Props>(function QrCode(
28 {starterPack, link},
29 ref,
30) {
31 const {record} = starterPack
32
33 if (!AppBskyGraphStarterpack.isRecord(record)) {
34 return null
35 }
36
37 return (
38 <LazyViewShot ref={ref}>
39 <LinearGradientBackground
40 style={[
41 {width: 300, minHeight: 390},
42 a.align_center,
43 a.px_sm,
44 a.py_xl,
45 a.rounded_sm,
46 a.justify_between,
47 a.gap_md,
48 ]}>
49 <View style={[a.gap_sm]}>
50 <Text
51 style={[a.font_bold, a.text_3xl, a.text_center, {color: 'white'}]}>
52 {record.name}
53 </Text>
54 </View>
55 <View style={[a.gap_xl, a.align_center]}>
56 <Text
57 style={[
58 a.font_bold,
59 a.text_center,
60 {color: 'white', fontSize: 18},
61 ]}>
62 <Trans>Join the conversation</Trans>
63 </Text>
64 <View style={[a.rounded_sm, a.overflow_hidden]}>
65 <QrCodeInner link={link} />
66 </View>
67
68 <Text
69 style={[
70 a.flex,
71 a.flex_row,
72 a.align_center,
73 a.font_bold,
74 {color: 'white', fontSize: 18, gap: 6},
75 ]}>
76 <Trans>
77 on
78 <View style={[a.flex_row, a.align_center, {gap: 6}]}>
79 <Logo width={25} fill="white" />
80 <View style={[{marginTop: 3.5}]}>
81 <Logotype width={72} fill="white" />
82 </View>
83 </View>
84 </Trans>
85 </Text>
86 </View>
87 </LinearGradientBackground>
88 </LazyViewShot>
89 )
90})
91
92export function QrCodeInner({link}: {link: string}) {
93 const t = useTheme()
94
95 return (
96 <QRCode
97 data={link}
98 style={[
99 a.rounded_sm,
100 {height: 225, width: 225, backgroundColor: '#f3f3f3'},
101 ]}
102 pieceSize={isWeb ? 8 : 6}
103 padding={20}
104 // pieceLiquidRadius={2}
105 pieceBorderRadius={isWeb ? 4.5 : 3.5}
106 outerEyesOptions={{
107 topLeft: {
108 borderRadius: [12, 12, 0, 12],
109 color: t.palette.primary_500,
110 },
111 topRight: {
112 borderRadius: [12, 12, 12, 0],
113 color: t.palette.primary_500,
114 },
115 bottomLeft: {
116 borderRadius: [12, 0, 12, 12],
117 color: t.palette.primary_500,
118 },
119 }}
120 innerEyesOptions={{borderRadius: 3}}
121 logo={{
122 href: require('../../../assets/logo.png'),
123 scale: 0.95,
124 padding: 2,
125 hidePieces: true,
126 }}
127 />
128 )
129}