react-native-suno-scanner
v1.0.3
Published
test
Downloads
4
Readme
react-native-suno-scanner
React Native Suno Scanner
Installation
npm install react-native-suno-scanner
Usage
import {
CameraType,
SunoCamera,
TorchMode,
getCameraPermissionStatus,
requestCameraPermission,
} from 'react-native-suno-scanner';
// ...
export default function App() {
const cameraRef = useRef < any > null;
const [permissionState, setPermissionState] =
useState < string > 'not-determined';
useEffect(() => {
initilize();
}, []);
const initilize = async () => {
const permission = await getCameraPermissionStatus();
if (permission !== 'authorized') {
const result = await requestCameraPermission();
setPermissionState(result);
} else {
setPermissionState(permission);
}
};
const setOnFlash = () => {
cameraRef.current.setTorchMode(TorchMode.ON);
};
const setOffFlash = () => {
cameraRef.current.setTorchMode(TorchMode.OFF);
};
const scan = () => {
cameraRef.current.startBarcodeScanner();
};
const requestPermission = async () => {
const result = await requestCameraPermission();
setPermissionState(result);
};
const onReadCode = (event: any) => {
console.log('onReadCode =>', event.nativeEvent);
};
return (
<View style={styles.container}>
<View style={styles.row}>
<Button title="Bật flash" onPress={setOnFlash} />
<Button title="Tắt flash" onPress={setOffFlash} />
<Button title="Scan barcode" onPress={scan} />
</View>
{permissionState === 'authorized' && (
<SunoCamera
ref={cameraRef}
torchMode={TorchMode.ON}
cameraType={CameraType.BACK}
onReadCode={onReadCode}
/>
)}
{permissionState !== 'authorized' && (
<Button title="Request permission" onPress={requestPermission} />
)}
</View>
);
}
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library