-
Notifications
You must be signed in to change notification settings - Fork 0
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
94c6d21
commit 7e31e32
Showing
26 changed files
with
341 additions
and
64 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
module.exports = { | ||
plugins: ['react-native-reanimated/plugin'], // reanimated must be the last package | ||
plugins: [ | ||
['react-native-reanimated/plugin', { // reanimated must be the last package | ||
globals: ['__decode'], | ||
}] | ||
], | ||
presets: ['module:metro-react-native-babel-preset'], | ||
}; |
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
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
This file was deleted.
Oops, something went wrong.
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
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,17 @@ | ||
import React, { FC } from 'react'; | ||
import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
|
||
import Camera from '../../scan/camera/Camera'; | ||
|
||
export type TScanRoutes = 'Camera'; | ||
export type TScanParams = Record<TScanRoutes, undefined>; | ||
|
||
const Stack = createNativeStackNavigator<TScanParams>(); | ||
|
||
export const ScanNavigator: FC = () => { | ||
return ( | ||
<Stack.Navigator screenOptions={{ headerShown: false }}> | ||
<Stack.Screen component={Camera} name="Camera" /> | ||
</Stack.Navigator> | ||
); | ||
}; |
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
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export * from './useCameraPermission'; |
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,21 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { Camera } from 'react-native-vision-camera'; | ||
|
||
export function useCameraPermission() { | ||
const [hasCameraPermission, setHasCameraPermission] = useState<boolean>(); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
let permission = await Camera.getCameraPermissionStatus(); | ||
if (permission !== 'authorized') { | ||
permission = await Camera.requestCameraPermission(); | ||
} | ||
|
||
setHasCameraPermission(permission === 'authorized'); | ||
})(); | ||
}, []); | ||
|
||
return { | ||
hasCameraPermission, | ||
}; | ||
} |
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,68 @@ | ||
import { useMemo } from 'react'; | ||
import { PixelRatio } from 'react-native'; | ||
import { Rect } from 'vision-camera-code-scanner'; | ||
|
||
type Corner = { | ||
path: string; | ||
x: number; | ||
y: number; | ||
}; | ||
|
||
export type TOverlayDimensions = { | ||
cornerLength: number; | ||
padding: number; | ||
strokeWidth: number; | ||
}; | ||
|
||
export function useOverlayDimensions(dimensions, { padding, strokeWidth, cornerLength }: TOverlayDimensions) { | ||
const [width, height] = dimensions; | ||
const pixelRatio = PixelRatio.get(); | ||
|
||
return useMemo(() => { | ||
const sideLength = width - padding * 2; | ||
const boundingBox: Partial<Rect> = {}; | ||
|
||
boundingBox.left = (width - sideLength) / 2; | ||
boundingBox.right = boundingBox.left + sideLength; | ||
boundingBox.top = (height - sideLength) / 2; | ||
boundingBox.bottom = boundingBox.top + sideLength; | ||
|
||
const corners: Corner[] = [ | ||
{ | ||
path: `M 0 ${cornerLength} L 0 0 L ${cornerLength} 0`, | ||
x: boundingBox.left + strokeWidth / 2, | ||
y: boundingBox.top + strokeWidth / 2, | ||
}, | ||
{ | ||
path: `M 0 0 L ${cornerLength} 0 L ${cornerLength} ${cornerLength}`, | ||
x: boundingBox.right - cornerLength - strokeWidth / 2, | ||
y: boundingBox.top + strokeWidth / 2, | ||
}, | ||
{ | ||
path: `M ${cornerLength} 0 L ${cornerLength} ${cornerLength} L 0 ${cornerLength}`, | ||
x: boundingBox.right - cornerLength - strokeWidth / 2, | ||
y: boundingBox.bottom - cornerLength - strokeWidth / 2, | ||
}, | ||
{ | ||
path: `M 0 0 L 0 ${cornerLength} L ${cornerLength} ${cornerLength}`, | ||
x: boundingBox.left + strokeWidth / 2, | ||
y: boundingBox.bottom - cornerLength - strokeWidth / 2, | ||
}, | ||
]; | ||
|
||
/* @see https://www.dynamsoft.com/barcode-reader/docs/core/parameters/reference/region-definition/index.html?ver=latest#image-process-control */ | ||
const regionDefinition = { | ||
Bottom: Math.round((boundingBox.bottom / height) * 100), | ||
Left: Math.round((boundingBox.left / width) * 100), | ||
Right: Math.round((boundingBox.right / width) * 100), | ||
Top: Math.round((boundingBox.top / height) * 100), | ||
}; | ||
|
||
return { | ||
boundingBox: boundingBox as Rect, | ||
corners, | ||
regionDefinition, | ||
sideLength, | ||
}; | ||
}, [width, height, pixelRatio]); | ||
} |
Oops, something went wrong.