-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
128 lines (118 loc) · 4.99 KB
/
App.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import React, {useEffect} from 'react';
import {ActivityIndicator, StyleSheet, View} from 'react-native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import {NavigationContainer} from '@react-navigation/native';
import {
ActivityIndicatorContext,
BarcodeDocumentFormatContext,
BarcodeFormatsContext,
useBarcodeDocumentFormats,
useBarcodeFormats,
useLoading,
} from '@context';
import {COLORS, NavigationTheme} from '@theme';
import {FILE_ENCRYPTION_ENABLED, Screens, ScreenTitles} from '@utils';
import {BarcodeDocumentFormatsScreen} from './src/screens/BarcodeDocumentFormatsScreen.tsx';
import {BarcodeCameraViewScreen} from './src/screens/BarcodeCameraViewScreen.tsx';
import {BarcodeFormatsScreen} from './src/screens/BarcodeFormatsScreen.tsx';
import {HomeScreen} from './src/screens/HomeScreen.tsx';
import {ImageResultsScreen} from './src/screens/ImageResultsScreen.tsx';
import {BarcodeResultScreen} from './src/screens/BarcodeResultScreen.tsx';
import {BarcodeV2ResultsScreen} from './src/screens/BarcodeV2ResultsScreen.tsx';
import ScanbotBarcodeSDK, {
ScanbotBarcodeSdkConfiguration,
} from 'react-native-scanbot-barcode-scanner-sdk';
const Stack = createNativeStackNavigator();
/**
* TODO Add the license key here.
* Please note: Scanbot Barcode Scanner SDK will run without a license key for one minute per session!
* After the trial period has expired all SDK features as well as the UI components will stop working
* or may be terminated. You can get an unrestricted "no-strings-attached" 30 day trial license key for free.
* Please submit the trial license form (https://scanbot.io/en/sdk/demo/trial) on our website by using
* the app identifier "io.scanbot.example.sdk.barcode.reactnative" of this example app.
*/
const LICENSE_KEY = '';
export default function App() {
const barcodeDocumentFormatsValues = useBarcodeDocumentFormats();
const barcodeFormatsValues = useBarcodeFormats();
const [loading, setLoading] = useLoading();
useEffect(() => {
const configuration: ScanbotBarcodeSdkConfiguration = {
// Consider switching logging OFF in production builds for security and performance reasons!
loggingEnabled: true,
enableNativeLogging: false,
licenseKey: LICENSE_KEY,
// Optional custom storage directory
// storageBaseDirectory: Platform.select({
// ios: DocumentDirectoryPath + '/my-custom-storage',
// android: ExternalDirectoryPath + '/my-custom-storage',
// default: undefined,
// }),
};
// Set the following properties to enable encryption.
if (FILE_ENCRYPTION_ENABLED) {
configuration.fileEncryptionMode = 'AES256';
configuration.fileEncryptionPassword = 'SomeSecretPa$$w0rdForFileEncryption';
}
ScanbotBarcodeSDK.initializeSdk(configuration)
.then(result => {
console.log(result.data);
})
.catch(error => {
console.log('Initialization error: ', error.message);
});
console.log(`Using ${(global as any)?.nativeFabricUIManager ? 'New' : 'Old'} Architecture`);
}, []);
return (
<View style={styles.container}>
<BarcodeDocumentFormatContext.Provider value={barcodeDocumentFormatsValues}>
<BarcodeFormatsContext.Provider value={barcodeFormatsValues}>
<ActivityIndicatorContext.Provider value={{setLoading}}>
<NavigationContainer theme={NavigationTheme}>
<Stack.Navigator
screenOptions={navigation => ({
title: ScreenTitles[navigation.route.name as Screens],
headerBackTitleVisible: false,
})}>
<Stack.Screen name={Screens.HOME} component={HomeScreen} />
<Stack.Screen name={Screens.BARCODE_FORMATS} component={BarcodeFormatsScreen} />
<Stack.Screen
name={Screens.BARCODE_DOCUMENTS}
component={BarcodeDocumentFormatsScreen}
/>
<Stack.Screen
name={Screens.BARCODE_CAMERA_VIEW}
component={BarcodeCameraViewScreen}
/>
<Stack.Screen name={Screens.IMAGE_RESULTS} component={ImageResultsScreen} />
<Stack.Screen
name={Screens.BARCODE_RESULTS_LEGACY}
component={BarcodeResultScreen}
/>
<Stack.Screen name={Screens.BARCODE_RESULTS} component={BarcodeV2ResultsScreen} />
</Stack.Navigator>
</NavigationContainer>
<ActivityIndicator
size="large"
color={COLORS.SCANBOT_RED}
style={styles.loadingIndicator}
animating={loading}
/>
</ActivityIndicatorContext.Provider>
</BarcodeFormatsContext.Provider>
</BarcodeDocumentFormatContext.Provider>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
loadingIndicator: {
elevation: 6,
position: 'absolute',
left: '47%',
top: '40%',
width: '6%',
},
});