Skip to content

Commit 44fd1c5

Browse files
committed
chore(example): create a useful example
1 parent 3878004 commit 44fd1c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+5537
-8718
lines changed

Example/.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

Example/.flowconfig

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,58 @@
1212
; For RN Apps installed via npm, "Libraries" folder is inside
1313
; "node_modules/react-native" but in the source repo it is in the root
1414
.*/Libraries/react-native/React.js
15-
.*/Libraries/react-native/ReactNative.js
15+
16+
; Ignore polyfills
17+
.*/Libraries/polyfills/.*
18+
19+
; Ignore metro
20+
.*/node_modules/metro/.*
1621

1722
[include]
1823

1924
[libs]
2025
node_modules/react-native/Libraries/react-native/react-native-interface.js
21-
node_modules/react-native/flow
22-
flow/
26+
node_modules/react-native/flow/
2327

2428
[options]
2529
emoji=true
2630

27-
module.system=haste
31+
esproposal.optional_chaining=enable
32+
esproposal.nullish_coalescing=enable
2833

29-
experimental.strict_type_args=true
34+
module.system=haste
35+
module.system.haste.use_name_reducers=true
36+
# get basename
37+
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
38+
# strip .js or .js.flow suffix
39+
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
40+
# strip .ios suffix
41+
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
42+
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
43+
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
44+
module.system.haste.paths.blacklist=.*/__tests__/.*
45+
module.system.haste.paths.blacklist=.*/__mocks__/.*
46+
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
47+
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
3048

3149
munge_underscores=true
3250

3351
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
3452

53+
module.file_ext=.js
54+
module.file_ext=.jsx
55+
module.file_ext=.json
56+
module.file_ext=.native.js
57+
3558
suppress_type=$FlowIssue
3659
suppress_type=$FlowFixMe
37-
suppress_type=$FixMe
60+
suppress_type=$FlowFixMeProps
61+
suppress_type=$FlowFixMeState
3862

39-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-5]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
40-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-5]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
63+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
64+
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
4165
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
4266
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
4367

44-
unsafe.enable_getters_and_setters=true
45-
4668
[version]
47-
^0.45.0
69+
^0.92.0

Example/.gitignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ buck-out/
4646
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
4747
# screenshots whenever they are needed.
4848
# For more information about the recommended setup visit:
49-
# https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
49+
# https://docs.fastlane.tools/best-practices/source-control/
5050

51-
fastlane/report.xml
52-
fastlane/Preview.html
53-
fastlane/screenshots
51+
*/fastlane/report.xml
52+
*/fastlane/Preview.html
53+
*/fastlane/screenshots
54+
55+
# Bundle artifact
56+
*.jsbundle

Example/App.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React, { useRef, useState } from "react"
2+
import { StyleSheet, Text, TouchableOpacity, Image } from "react-native"
3+
import PDFScanner from "@woonivers/react-native-document-scanner"
4+
5+
export default function App() {
6+
const pdfScannerElement = useRef(null)
7+
const [data, setData] = useState({})
8+
9+
function handleOnPressRetry() {
10+
setData({})
11+
}
12+
function handleOnPress() {
13+
pdfScannerElement.current.capture()
14+
}
15+
if (data.croppedImage) {
16+
console.log("data", data)
17+
return (
18+
<React.Fragment>
19+
<Image source={{ uri: data.croppedImage }} style={styles.preview} />
20+
<TouchableOpacity onPress={handleOnPressRetry} style={styles.button}>
21+
<Text style={styles.buttonText}>Retry</Text>
22+
</TouchableOpacity>
23+
</React.Fragment>
24+
)
25+
}
26+
return (
27+
<React.Fragment>
28+
<PDFScanner
29+
ref={pdfScannerElement}
30+
style={styles.scanner}
31+
onPictureTaken={setData}
32+
overlayColor="rgba(255,130,0, 0.7)"
33+
enableTorch={false}
34+
brightness={0.3}
35+
saturation={1}
36+
contrast={1.1}
37+
quality={0.5}
38+
detectionCountBeforeCapture={5}
39+
detectionRefreshRateInMS={50}
40+
onPermissionsDenied={() => console.log("Permissions Denied")}
41+
/>
42+
<TouchableOpacity onPress={handleOnPress} style={styles.button}>
43+
<Text style={styles.buttonText}>Take picture</Text>
44+
</TouchableOpacity>
45+
</React.Fragment>
46+
)
47+
}
48+
49+
const styles = StyleSheet.create({
50+
scanner: {
51+
flex: 1,
52+
width: "100%",
53+
},
54+
button: {
55+
alignSelf: "center",
56+
position: "absolute",
57+
bottom: 32,
58+
},
59+
buttonText: {
60+
backgroundColor: "rgba(245, 252, 255, 0.7)",
61+
fontSize: 32,
62+
},
63+
preview: {
64+
flex: 1,
65+
width: "100%",
66+
resizeMode: "cover",
67+
},
68+
})
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
/**
2+
* @format
3+
*/
4+
15
import 'react-native';
26
import React from 'react';
3-
import Index from '../index.ios.js';
7+
import App from '../App';
48

59
// Note: test renderer must be required after react-native.
610
import renderer from 'react-test-renderer';
711

812
it('renders correctly', () => {
9-
const tree = renderer.create(
10-
<Index />
11-
);
13+
renderer.create(<App />);
1214
});

Example/__tests__/index.android.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

Example/android/.project

Lines changed: 0 additions & 17 deletions
This file was deleted.

Example/android/.settings/org.eclipse.buildship.core.prefs

Lines changed: 0 additions & 2 deletions
This file was deleted.

Example/android/app/BUCK

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,13 @@
88
# - `buck install -r android/app` - compile, install and run application
99
#
1010

11+
load(":build_defs.bzl", "create_aar_targets", "create_jar_targets")
12+
1113
lib_deps = []
1214

13-
for jarfile in glob(['libs/*.jar']):
14-
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
15-
lib_deps.append(':' + name)
16-
prebuilt_jar(
17-
name = name,
18-
binary_jar = jarfile,
19-
)
15+
create_aar_targets(glob(["libs/*.aar"]))
2016

21-
for aarfile in glob(['libs/*.aar']):
22-
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
23-
lib_deps.append(':' + name)
24-
android_prebuilt_aar(
25-
name = name,
26-
aar = aarfile,
27-
)
17+
create_jar_targets(glob(["libs/*.jar"]))
2818

2919
android_library(
3020
name = "all-libs",

Example/android/app/build.gradle

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ import com.android.build.OutputFile
7272
* ]
7373
*/
7474

75+
project.ext.react = [
76+
entryFile: "index.js"
77+
]
78+
7579
apply from: "../../node_modules/react-native/react.gradle"
7680

7781
/**
@@ -90,25 +94,26 @@ def enableSeparateBuildPerCPUArchitecture = false
9094
def enableProguardInReleaseBuilds = false
9195

9296
android {
93-
compileSdkVersion 23
94-
buildToolsVersion "23.0.1"
97+
compileSdkVersion rootProject.ext.compileSdkVersion
98+
99+
compileOptions {
100+
sourceCompatibility JavaVersion.VERSION_1_8
101+
targetCompatibility JavaVersion.VERSION_1_8
102+
}
95103

96104
defaultConfig {
97105
applicationId "com.example"
98-
minSdkVersion 16
99-
targetSdkVersion 22
106+
minSdkVersion rootProject.ext.minSdkVersion
107+
targetSdkVersion rootProject.ext.targetSdkVersion
100108
versionCode 1
101109
versionName "1.0"
102-
ndk {
103-
abiFilters "armeabi-v7a", "x86"
104-
}
105110
}
106111
splits {
107112
abi {
108113
reset()
109114
enable enableSeparateBuildPerCPUArchitecture
110115
universalApk false // If true, also generate a universal APK
111-
include "armeabi-v7a", "x86"
116+
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
112117
}
113118
}
114119
buildTypes {
@@ -122,7 +127,7 @@ android {
122127
variant.outputs.each { output ->
123128
// For each separate APK per architecture, set a unique version code as described here:
124129
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
125-
def versionCodes = ["armeabi-v7a":1, "x86":2]
130+
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
126131
def abi = output.getFilter(OutputFile.ABI)
127132
if (abi != null) { // null for the universal-debug, universal-release variants
128133
output.versionCodeOverride =
@@ -133,11 +138,10 @@ android {
133138
}
134139

135140
dependencies {
136-
compile project(':react-native-document-scanner')
137-
compile project(':react-native-pdf-scanner')
138-
compile fileTree(dir: "libs", include: ["*.jar"])
139-
compile "com.android.support:appcompat-v7:23.0.1"
140-
compile "com.facebook.react:react-native:+" // From node_modules
141+
implementation project(':@woonivers_react-native-document-scanner')
142+
implementation fileTree(dir: "libs", include: ["*.jar"])
143+
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
144+
implementation "com.facebook.react:react-native:+" // From node_modules
141145
}
142146

143147
// Run this once to be able to run the application with BUCK

0 commit comments

Comments
 (0)