|
1 | 1 | import React, { useState, useEffect } from 'react' |
2 | 2 | import { Alert } from 'react-native' |
3 | | -import { launchCamera, launchImageLibrary } from 'react-native-image-picker' |
4 | 3 | // @ts-ignore |
5 | 4 | import Tflite from 'tflite-react-native' |
6 | 5 |
|
7 | | -import { Translate } from '~/services' |
| 6 | +import { ChooseFile, TakePicture, Translate } from '~/services' |
8 | 7 |
|
9 | | -import { Button, ImagePreview, Result, Title } from '~/components' |
| 8 | +import { Button, ButtonContainer, ImagePreview, Result, Title } from '~/components' |
10 | 9 |
|
11 | 10 |
|
12 | 11 | type RESPONSE = { |
@@ -38,43 +37,6 @@ function ImageClassification () { |
38 | 37 | } |
39 | 38 |
|
40 | 39 |
|
41 | | - function chooseFile () { |
42 | | - const options = { |
43 | | - title: Translate('selectImage'), |
44 | | - storageOptions: { |
45 | | - skipBackup: true, |
46 | | - path: 'images' |
47 | | - } |
48 | | - } |
49 | | - // @ts-ignore |
50 | | - launchImageLibrary(options, response => { |
51 | | - if (response.didCancel) { |
52 | | - return |
53 | | - } |
54 | | - // @ts-ignore |
55 | | - setFileUri(response.assets[0].uri) |
56 | | - }) |
57 | | - } |
58 | | - |
59 | | - |
60 | | - function takePicture () { |
61 | | - const options = { |
62 | | - storageOptions: { |
63 | | - skipBackup: true, |
64 | | - path: 'images' |
65 | | - } |
66 | | - } |
67 | | - // @ts-ignore |
68 | | - launchCamera(options, response => { |
69 | | - if (response.didCancel) { |
70 | | - return |
71 | | - } |
72 | | - // @ts-ignore |
73 | | - setFileUri(response.assets[0].uri) |
74 | | - }) |
75 | | - } |
76 | | - |
77 | | - |
78 | 40 | function performImageClassification () { |
79 | 41 | tflite.runModelOnImage({ |
80 | 42 | path: fileUri, |
@@ -118,8 +80,10 @@ function ImageClassification () { |
118 | 80 | <Title text='pickImagesCG' /> |
119 | 81 | <ImagePreview uri={fileUri} /> |
120 | 82 | <Result result={result} /> |
121 | | - <Button onPress={chooseFile} text='chooseFile' /> |
122 | | - <Button onPress={takePicture} text='takePicture' /> |
| 83 | + <ButtonContainer style={{ width: '60%', maxWidth: 300 }}> |
| 84 | + <Button onPress={() => ChooseFile(setFileUri)} text='chooseFile' /> |
| 85 | + <Button onPress={() => TakePicture(setFileUri)} text='takePicture' /> |
| 86 | + </ButtonContainer> |
123 | 87 | </> |
124 | 88 | ) |
125 | 89 | } |
|
0 commit comments