Skip to content

Commit

Permalink
US-1146 QR code scanner replacement (#335)
Browse files Browse the repository at this point in the history
* chore: add react-native-vision-camera package

* chore: add react-native-reanimated package

* refactor: change rn-camera to rn-vision-camera

Co-authored-by: Alexander Evchenko <[email protected]>
Co-authored-by: Jesse Clark <[email protected]>
  • Loading branch information
3 people authored Nov 10, 2022
1 parent f192f37 commit 9d81e58
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 81 deletions.
8 changes: 8 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
[
'react-native-reanimated/plugin',
{
globals: ['__scanCodes'],
},
],
],
}
129 changes: 129 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,71 @@ PODS:
- FlipperKit/FlipperKitNetworkPlugin
- fmt (6.2.1)
- glog (0.3.5)
- GoogleDataTransport (9.2.0):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleMLKit/BarcodeScanning (3.2.0):
- GoogleMLKit/MLKitCore
- MLKitBarcodeScanning (~> 2.2.0)
- GoogleMLKit/MLKitCore (3.2.0):
- MLKitCommon (~> 8.0.0)
- GoogleToolboxForMac/DebugUtils (2.3.2):
- GoogleToolboxForMac/Defines (= 2.3.2)
- GoogleToolboxForMac/Defines (2.3.2)
- GoogleToolboxForMac/Logger (2.3.2):
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSData+zlib (2.3.2)":
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSDictionary+URLArguments (2.3.2)":
- GoogleToolboxForMac/DebugUtils (= 2.3.2)
- GoogleToolboxForMac/Defines (= 2.3.2)
- "GoogleToolboxForMac/NSString+URLArguments (= 2.3.2)"
- "GoogleToolboxForMac/NSString+URLArguments (2.3.2)"
- GoogleUtilities/Environment (7.8.0):
- PromisesObjC (< 3.0, >= 1.2)
- GoogleUtilities/Logger (7.8.0):
- GoogleUtilities/Environment
- GoogleUtilities/UserDefaults (7.8.0):
- GoogleUtilities/Logger
- GoogleUtilitiesComponents (1.1.0):
- GoogleUtilities/Logger
- GTMSessionFetcher/Core (1.7.2)
- hermes-engine (0.70.3)
- jail-monkey (2.7.0):
- React-Core
- libevent (2.1.12)
- MLImage (1.0.0-beta3)
- MLKitBarcodeScanning (2.2.0):
- MLKitCommon (~> 8.0)
- MLKitVision (~> 4.2)
- MLKitCommon (8.0.0):
- GoogleDataTransport (~> 9.0)
- GoogleToolboxForMac/Logger (~> 2.1)
- "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
- "GoogleToolboxForMac/NSDictionary+URLArguments (~> 2.1)"
- GoogleUtilities/UserDefaults (~> 7.0)
- GoogleUtilitiesComponents (~> 1.0)
- GTMSessionFetcher/Core (~> 1.1)
- Protobuf (~> 3.12)
- MLKitVision (4.2.0):
- GoogleToolboxForMac/Logger (~> 2.1)
- "GoogleToolboxForMac/NSData+zlib (~> 2.1)"
- GTMSessionFetcher/Core (~> 1.1)
- MLImage (= 1.0.0-beta3)
- MLKitCommon (~> 8.0)
- Protobuf (~> 3.12)
- MMKV (1.2.14):
- MMKVCore (~> 1.2.14)
- MMKVCore (1.2.14)
- nanopb (2.30909.0):
- nanopb/decode (= 2.30909.0)
- nanopb/encode (= 2.30909.0)
- nanopb/decode (2.30909.0)
- nanopb/encode (2.30909.0)
- OpenSSL-Universal (1.1.1100)
- PromisesObjC (2.1.1)
- Protobuf (3.21.9)
- RCT-Folly (2021.07.22.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -400,11 +457,45 @@ PODS:
- React-Core
- RNGestureHandler (2.8.0):
- React-Core
- RNReanimated (2.12.0):
- DoubleConversion
- FBLazyVector
- FBReactNativeSpec
- glog
- RCT-Folly
- RCTRequired
- RCTTypeSafety
- React-callinvoker
- React-Core
- React-Core/DevSupport
- React-Core/RCTWebSocket
- React-CoreModules
- React-cxxreact
- React-jsi
- React-jsiexecutor
- React-jsinspector
- React-RCTActionSheet
- React-RCTAnimation
- React-RCTBlob
- React-RCTImage
- React-RCTLinking
- React-RCTNetwork
- React-RCTSettings
- React-RCTText
- ReactCommon/turbomodule/core
- Yoga
- RNSVG (12.4.3):
- React-Core
- RNVectorIcons (9.2.0):
- React-Core
- SocketRocket (0.6.0)
- vision-camera-code-scanner (0.2.0):
- GoogleMLKit/BarcodeScanning
- React-Core
- VisionCamera (2.15.2):
- React
- React-callinvoker
- React-Core
- Yoga (1.14.0)
- YogaKit (1.18.1):
- Yoga (~> 1.14)
Expand Down Expand Up @@ -479,8 +570,11 @@ DEPENDENCIES:
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)"
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
- RNSVG (from `../node_modules/react-native-svg`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
- vision-camera-code-scanner (from `../node_modules/vision-camera-code-scanner`)
- VisionCamera (from `../node_modules/react-native-vision-camera`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
Expand All @@ -496,10 +590,23 @@ SPEC REPOS:
- Flipper-RSocket
- FlipperKit
- fmt
- GoogleDataTransport
- GoogleMLKit
- GoogleToolboxForMac
- GoogleUtilities
- GoogleUtilitiesComponents
- GTMSessionFetcher
- libevent
- MLImage
- MLKitBarcodeScanning
- MLKitCommon
- MLKitVision
- MMKV
- MMKVCore
- nanopb
- OpenSSL-Universal
- PromisesObjC
- Protobuf
- SocketRocket
- YogaKit

Expand Down Expand Up @@ -592,10 +699,16 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-community/clipboard"
RNGestureHandler:
:path: "../node_modules/react-native-gesture-handler"
RNReanimated:
:path: "../node_modules/react-native-reanimated"
RNSVG:
:path: "../node_modules/react-native-svg"
RNVectorIcons:
:path: "../node_modules/react-native-vector-icons"
vision-camera-code-scanner:
:path: "../node_modules/vision-camera-code-scanner"
VisionCamera:
:path: "../node_modules/react-native-vision-camera"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

Expand All @@ -617,12 +730,25 @@ SPEC CHECKSUMS:
FlipperKit: cbdee19bdd4e7f05472a66ce290f1b729ba3cb86
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleMLKit: 0017a6a8372e1a182139b9def4d89be5d87ca5a7
GoogleToolboxForMac: 8bef7c7c5cf7291c687cf5354f39f9db6399ad34
GoogleUtilities: 1d20a6ad97ef46f67bbdec158ce00563a671ebb7
GoogleUtilitiesComponents: 679b2c881db3b615a2777504623df6122dd20afe
GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba
hermes-engine: bb344d89a0d14c2c91ad357480a79698bb80e186
jail-monkey: de7eab0c9cbe4e7cdd2f80d04f812337ae94b2e0
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
MLImage: 489dfec109f21da8621b28d476401aaf7a0d4ff4
MLKitBarcodeScanning: d92fe1911001ec36870162c5a0eb206f612b7169
MLKitCommon: f6da6c5659618c070b50a80db01248ebe2964175
MLKitVision: 96c96571190b7f63eddf4a12068ce8a8689e0d2c
MMKV: 9c4663aa7ca255d478ff10f2f5cb7d17c1651ccd
MMKVCore: 89f5c8a66bba2dcd551779dea4d412eeec8ff5bb
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
Protobuf: 02524ec14183fe08fb259741659e79683788158b
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda
RCTRequired: 5cf7e7d2f12699724b59f90350257a422eaa9492
RCTTypeSafety: 3f3ead9673d1ab8bb1aea85b0894ab3220f8f06e
Expand Down Expand Up @@ -659,9 +785,12 @@ SPEC CHECKSUMS:
RNCAsyncStorage: d81ee5c3db1060afd49ea7045ad460eff82d2b7d
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
RNGestureHandler: 62232ba8f562f7dea5ba1b3383494eb5bf97a4d3
RNReanimated: 2a91e85fcd343f8af3c58d3425b99fdd285590a5
RNSVG: f3b60aeeaa81960e2e0536c3a9eef50b667ef3a9
RNVectorIcons: fcc2f6cb32f5735b586e66d14103a74ce6ad61f8
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
vision-camera-code-scanner: dda884a7f3ec8243a2a6d6489b91860648371bca
VisionCamera: 4cfd685b1e671fea4aa0400905ab397f0e972210
Yoga: 2ed968a4f060a92834227c036279f2736de0fce3
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
3 changes: 2 additions & 1 deletion ios/sWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
DEVELOPMENT_TEAM = 3YDAH8ZR7C;
ENABLE_BITCODE = YES;
EXCLUDED_ARCHS = "";
"EXCLUDED_ARCHS[sdk=*]" = arm64;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = sWallet/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -538,6 +538,7 @@
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 3YDAH8ZR7C;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = arm64;
INFOPLIST_FILE = sWallet/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
2 changes: 1 addition & 1 deletion ios/sWallet/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</dict>
</dict>
<key>NSCameraUsageDescription</key>
<string>The app will use the camera to operate with Wallet Connect</string>
<string>$PRODUCT_NAME will use the camera to operate with Wallet Connect</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSPhotoLibraryUsageDescription</key>
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,22 @@
"react-native-modal": "^13.0.1",
"react-native-progress": "^5.0.0",
"react-native-randombytes": "^3.0.0",
"react-native-reanimated": "^2.12.0",
"react-native-safe-area-context": "^4.4.1",
"react-native-snap-carousel": "^3.9.1",
"react-native-svg": "^12.1.1",
"react-native-swipe-modal-up-down": "^1.1.0",
"react-native-uuid": "^2.0.1",
"react-native-vector-icons": "^9.1.0",
"react-native-vision-camera": "^2.15.2",
"react-native-webview": "^11.14.3",
"react-qr-code": "^2.0.2",
"react-redux": "^8.0.5",
"readable-stream": "1.0.33",
"socket.io-client": "^4.4.1",
"stream-browserify": "^1.0.0",
"url-parse": "^1.5.9"
"url-parse": "^1.5.9",
"vision-camera-code-scanner": "^0.2.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
Expand Down
75 changes: 47 additions & 28 deletions src/components/QRCodeScanner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,59 @@
import React from 'react'
import { Modal, StyleSheet } from 'react-native'
// import BarcodeMask from 'react-native-barcode-mask'
// import { BarCodeReadEvent, RNCamera } from 'react-native-camera'
// import Icon from 'react-native-vector-icons/Ionicons'
// import { colors } from '../../styles'
import React, { useCallback, useEffect } from 'react'
import {
ActivityIndicator,
Linking,
Modal,
StyleSheet,
View,
} from 'react-native'
import BarcodeMask from 'react-native-barcode-mask'
import { Camera, useCameraDevices } from 'react-native-vision-camera'
import { useScanBarcodes, BarcodeFormat } from 'vision-camera-code-scanner'
import Icon from 'react-native-vector-icons/Ionicons'
import { colors } from '../../styles'

interface QRCodeScannerProps {
onClose: () => void
onCodeRead: (data: string) => void
}

export const QRCodeScanner = (_: QRCodeScannerProps) => {
// const cameraRef = useRef<RNCamera>(null)
export const QRCodeScanner = ({ onClose, onCodeRead }: QRCodeScannerProps) => {
const device = useCameraDevices('wide-angle-camera').back
const [frameProcessor, barcodes] = useScanBarcodes([BarcodeFormat.QR_CODE], {
checkInverted: true,
})

// const onBarCodeRead = (event: BarCodeReadEvent) => {
// // @ts-ignore
// if (event.type === 'QR_CODE') {
// onCodeRead(decodeURIComponent(event.data))
// }
// }
const permissionHandler = useCallback(async () => {
const cameraPermission = await Camera.getCameraPermissionStatus()
if (cameraPermission === 'not-determined') {
await Camera.requestCameraPermission()
} else if (cameraPermission === 'denied') {
Linking.openSettings()
}
}, [])

useEffect(() => {
permissionHandler()
}, [])

useEffect(() => {
if (barcodes && barcodes[0] && barcodes[0].rawValue) {
onCodeRead(barcodes[0].rawValue)
}
}, [barcodes])

if (device == null) {
return <ActivityIndicator size={'large'} />
}

return (
<Modal presentationStyle="overFullScreen" style={styles.modal}>
{/* <RNCamera
ref={cameraRef}
style={styles.container}
onBarCodeRead={onBarCodeRead}
captureAudio={false}
type={RNCamera.Constants.Type.back}
flashMode={RNCamera.Constants.FlashMode.off}
androidCameraPermissionOptions={{
title: 'Permission to use camera',
message: 'We need your permission to use your camera',
buttonPositive: 'Ok',
buttonNegative: 'Cancel',
}}>
<Camera
frameProcessor={frameProcessor}
frameProcessorFps={5}
device={device}
isActive={true}
style={styles.container}>
<BarcodeMask
showAnimatedLine={false}
outerMaskOpacity={0.5}
Expand All @@ -53,7 +72,7 @@ export const QRCodeScanner = (_: QRCodeScannerProps) => {
borderRadius={40}
/>
</View>
</RNCamera> */}
</Camera>
</Modal>
)
}
Expand Down
Loading

0 comments on commit 9d81e58

Please sign in to comment.