-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34ed79b
commit 3c65857
Showing
2 changed files
with
90 additions
and
27 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
packages/mobile/src/screens/SignerConfirmScreen/QrCodeView.tsx
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,46 @@ | ||
import { View, ViewStyle, deviceWidth, ns } from '@tonkeeper/uikit'; | ||
import { FC, memo, useCallback } from 'react'; | ||
import Animated, { useAnimatedStyle, useSharedValue } from 'react-native-reanimated'; | ||
import QRCode from 'react-native-qrcode-styled'; | ||
import { LayoutChangeEvent } from 'react-native'; | ||
|
||
export const QR_SIZE = deviceWidth - ns(16) * 2 - ns(24) * 2; | ||
|
||
export const QR_WRAP_STYLE: ViewStyle = { | ||
width: QR_SIZE, | ||
height: QR_SIZE, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}; | ||
|
||
interface Props { | ||
data: string; | ||
index: number; | ||
currentChunkIndex: Animated.SharedValue<number>; | ||
} | ||
|
||
export const QrCodeView: FC<Props> = memo((props) => { | ||
const { data, index, currentChunkIndex } = props; | ||
|
||
const qrCodeScale = useSharedValue(1); | ||
|
||
const handleQrCodeLayout = useCallback( | ||
(e: LayoutChangeEvent) => { | ||
qrCodeScale.value = QR_SIZE / e.nativeEvent.layout.width; | ||
}, | ||
[qrCodeScale], | ||
); | ||
|
||
const qrStyle = useAnimatedStyle(() => ({ | ||
transform: [{ scale: qrCodeScale.value }], | ||
opacity: index === currentChunkIndex.value ? 1 : 0, | ||
})); | ||
|
||
return ( | ||
<View style={QR_WRAP_STYLE}> | ||
<Animated.View style={qrStyle}> | ||
<QRCode data={data} onLayout={handleQrCodeLayout} pieceSize={8} /> | ||
</Animated.View> | ||
</View> | ||
); | ||
}); |
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