-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
81 lines (76 loc) · 1.97 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
import React, {useState} from 'react';
import {
StyleSheet,
Text,
ScrollView,
View,
TouchableOpacity,
Image,
} from 'react-native';
import {launchCamera, launchImageLibrary} from 'react-native-image-picker';
import ml from '@react-native-firebase/ml';
export default function App() {
const [image, setImage] = useState();
const [result, setResult] = useState({});
const onTakePhoto = () => launchCamera({mediaType: 'image'}, onMediaSelect);
const onSelectImagePress = () =>
launchImageLibrary({mediaType: 'image'}, onMediaSelect);
const onMediaSelect = async (media) => {
if (!media.didCancel) {
setImage(media.uri);
const result = await ml().cloudDocumentTextRecognizerProcessImage(
media.uri,
);
setResult(result);
}
};
return (
<ScrollView contentContainerStyle={styles.screen}>
<Text style={styles.title}>Text Recognition</Text>
<View>
<TouchableOpacity style={styles.button} onPress={onTakePhoto}>
<Text style={styles.buttonText}>Take Photo</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={onSelectImagePress}>
<Text style={styles.buttonText}>Pick a Photo</Text>
</TouchableOpacity>
<Image
resizeMode="contain"
source={{uri: image}}
style={styles.image}
/>
</View>
<View style={{marginTop: 30}}>
<Text style={{fontSize: 30}}>{result.text}</Text>
</View>
</ScrollView>
);
}
const styles = StyleSheet.create({
screen: {
alignItems: 'center',
},
title: {
fontSize: 35,
marginVertical: 40,
},
image: {
height: 300,
width: 300,
marginTop: 30,
borderRadius: 10,
},
button: {
backgroundColor: '#494e5a',
color: '#fff',
justifyContent: 'center',
alignItems: 'center',
paddingVertical: 15,
paddingHorizontal: 40,
borderRadius: 50,
marginTop: 20,
},
buttonText: {
color: '#fff',
},
});