-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathindex.tsx
82 lines (72 loc) · 2.55 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type {ForwardedRef} from 'react';
import React, {forwardRef, useImperativeHandle, useRef, useState} from 'react';
import type {LayoutChangeEvent} from 'react-native';
import {View} from 'react-native';
import type {Svg} from 'react-native-svg';
import ExpensifyWordmark from '@assets/images/expensify-wordmark.svg';
import ImageSVG from '@components/ImageSVG';
import QRCode from '@components/QRCode';
import Text from '@components/Text';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import type {QRShareHandle, QRShareProps} from './types';
function QRShare({url, title, subtitle, logo, logoRatio, logoMarginRatio}: QRShareProps, ref: ForwardedRef<QRShareHandle>) {
const styles = useThemeStyles();
const theme = useTheme();
const [qrCodeSize, setQrCodeSize] = useState<number | undefined>();
const svgRef = useRef<Svg>();
useImperativeHandle(
ref,
() => ({
getSvg: () => svgRef.current,
}),
[],
);
const onLayout = (event: LayoutChangeEvent) => {
const containerWidth = event.nativeEvent.layout.width - variables.qrShareHorizontalPadding * 2 || 0;
setQrCodeSize(Math.max(1, containerWidth));
};
return (
<View
style={styles.shareCodeContainer}
onLayout={onLayout}
>
<View style={styles.expensifyQrLogo}>
<ImageSVG
contentFit="contain"
src={ExpensifyWordmark}
fill={theme.QRLogo}
/>
</View>
<QRCode
getRef={(svg) => (svgRef.current = svg)}
url={url}
logo={logo}
size={qrCodeSize}
logoRatio={logoRatio}
logoMarginRatio={logoMarginRatio}
/>
<Text
family="EXP_NEW_KANSAS_MEDIUM"
fontSize={variables.fontSizeXLarge}
numberOfLines={2}
style={styles.qrShareTitle}
>
{title}
</Text>
{!!subtitle && (
<Text
fontSize={variables.fontSizeLabel}
numberOfLines={2}
style={[styles.mt1, styles.textAlignCenter]}
color={theme.textSupporting}
>
{subtitle}
</Text>
)}
</View>
);
}
QRShare.displayName = 'QRShare';
export default forwardRef(QRShare);