Skip to content

Commit

Permalink
chore: fix sample app build
Browse files Browse the repository at this point in the history
  • Loading branch information
1fabiopereira committed Jun 19, 2023
1 parent 6d2446b commit 94bc786
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MainApplication extends Application implements ReactApplication {
new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return false;
return true;
}

@Override
Expand Down
1 change: 1 addition & 0 deletions sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/runtime": "^7.18.3",
"@react-native-community/cli-platform-android": "^11.3.2",
"@types/react-native-document-picker": "^3.1.1",
"babel-plugin-module-resolver": "^4.1.0",
"metro-react-native-babel-preset": "^0.71.1"
Expand Down
63 changes: 23 additions & 40 deletions sample/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect, useState, memo } from 'react';
import React, { useState, memo } from 'react';
import { Button, FlatList, StyleSheet, Text, View } from 'react-native';
import DocumentPicker from 'react-native-document-picker';

import { Extractor, Patterns } from '../..';
import { TransientObject } from '../../src/types';

const App: React.FC = (): JSX.Element => {
const [isEncrypted, setIsEncrypted] = useState<boolean | undefined>(false);
Expand All @@ -12,45 +12,23 @@ const App: React.FC = (): JSX.Element => {
const [uri, setUri] = useState<string | undefined>();
const [time, setTime] = useState<string | undefined>();

function selectFile() {
(async () => {
const response = await DocumentPicker.pickSingle({
presentationStyle: 'fullScreen',
copyTo: 'cachesDirectory',
type: 'application/pdf',
});
const selectFile = async () => {
const data = await DocumentPicker.pickSingle({
presentationStyle: 'fullScreen',
copyTo: 'cachesDirectory',
type: 'application/pdf',
});

extract(response.uri);
})();
}
setUri(data.uri);
};

function apply(response: any) {
setPages(response.pages);
setIsEncrypted(response.isEncrypted);
setUri(response.uri);
setTime(response.duration);
setResult(response.text as string[]);
}

function extractFromIntent() {
(async () => {
const response = await Extractor.extractFromIntent(
Patterns.Brazil.BankSlip
);
apply(response);
})();
}

function extract(path: string) {
(async () => {
const response = await Extractor.extract(path, Patterns.Brazil.BankSlip);
apply(response);
})();
}

useEffect(() => {
extractFromIntent();
}, []);
const onResult = (data: TransientObject) => {
setPages(data.pages);
setIsEncrypted(data.isEncrypted);
setUri(data.uri);
setTime(data.duration);
setResult(data.text as string[]);
};

return (
<View style={styles.container}>
Expand All @@ -61,11 +39,16 @@ const App: React.FC = (): JSX.Element => {
<Text>{`Execution time: ${time}`}</Text>
<Text>Result:</Text>
<FlatList
style={{}}
data={result || []}
keyExtractor={(item) => item}
renderItem={({ item }: { item: string }) => <Text>{item}</Text>}
/>
<Extractor
onResult={onResult}
patterns={Patterns.Brazil.BankSlip}
uri={uri}
fromIntent
/>
</View>
);
};
Expand Down
Loading

0 comments on commit 94bc786

Please sign in to comment.