This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
forked from quikkly/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
180 lines (164 loc) · 4.28 KB
/
App.js
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from "react"
import {createStackNavigator, createAppContainer} from 'react-navigation'
import {
Platform,
StyleSheet,
Button,
Text,
View,
Image
} from "react-native"
import { Quikkly, QuikklyView } from "react-native-quikkly"
class HomeScreen extends React.Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
const {navigate} = this.props.navigation;
return (
<View>
<Button
title="Go to Overlay Scanner"
onPress={() => navigate('Overlay', {name: 'overlay'})}
/>
<Text style={{textAlign: 'center',color: '#333333',marginBottom: 5,}}>
When I click the "Go to Overlay Scanner" for the second
time I see the error message.
</Text>
</View>
);
}
}
class OverlayScreen extends React.Component {
static navigationOptions = {
title: 'Overlay',
};
constructor(props) {
super(props)
this.state = {
code: "<none>"
}
}
onScanCodeOverlay = (result) => {
console.log(result);
this.setState({ code: result.value})
}
render() {
const {navigate} = this.props.navigation;
return (
<View style={{flex: 1}}>
<Button
title="Go back home"
onPress={() => navigate('Home', {name: 'home'})}
/>
<Text style={{textAlign: 'center',color: '#333333',marginBottom: 5,}}>
The last scanned code was: {this.state.code}
</Text>
<View style={{flex:1, alignItems: 'center'}}>
<QuikklyView
style={{width: '100%', height: '100%'}}
onScanCode={this.onScanCodeOverlay}
cameraPreviewFit={2}/>
<Image
style={{width: '100%', height: '100%', position: 'absolute'}}
source={require('./images/mask2.png')}
/>
</View>
</View>
);
}
}
const MainNavigator = createStackNavigator({
Home: {screen: HomeScreen},
Overlay: {screen: OverlayScreen},
});
const instructions = Platform.select({
ios: "Press Cmd+R to reload,\nCmd+D or shake for dev menu",
android: "Double tap R on your keyboard to reload,\nShake or press menu button for dev menu"
})
/*
export default class App extends Component {
constructor(props) {
super(props)
this.state = {
code: "<none>"
}
}
onScanCode = () => {
Quikkly.scanForResult().then((result) => {
this.setState({ code: result.value })
}).catch((err) => {
this.setState({ code: "<cancelled>" })
})
}
onScanCodeOverlay = (result) => {
console.log(result);
this.setState({ code: result.value})
}
render() {
return (
<View style={{flex: 1}}>
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to Quikkly SDK {Quikkly.VERSION} Demo!
</Text>
<Text style={styles.instructions}>
Tap the "Scan a code" button to open the full screen scanner
or use the overlay scanner below to scan a tag
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Button
style={styles.action}
onPress={this.onScanCode}
title="Scan a code" />
<Text style={styles.instructions}>
The last scanned code was: {this.state.code}
</Text>
</View>
<View style={{flex:1, alignItems: 'center'}}>
<QuikklyView
style={{width: '100%', height: '100%'}}
onScanCode={this.onScanCodeOverlay}
cameraPreviewFit={2}/>
<Image
style={{width: '100%', height: '100%', position: 'absolute'}}
source={require('./images/mask2.png')}
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
justifyContent: 'flex-start',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
action: {
color: "#330066"
},
overlay: {
position: 'absolute'
}
})
*/
const App = createAppContainer(MainNavigator);
export default App;