Skip to content

Commit 82b1c96

Browse files
committed
chore(example): upgrade react-native version
1 parent 8ccdf47 commit 82b1c96

File tree

29 files changed

+1915
-1852
lines changed

29 files changed

+1915
-1852
lines changed

example/.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
root: true,
3+
extends: '@react-native-community',
4+
};

example/.flowconfig

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

example/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ yarn-error.log
4040
buck-out/
4141
\.buckd/
4242
*.keystore
43+
!debug.keystore
4344

4445
# fastlane
4546
#
@@ -54,3 +55,6 @@ buck-out/
5455

5556
# Bundle artifact
5657
*.jsbundle
58+
59+
# CocoaPods
60+
/ios/Pods/

example/.prettierrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
bracketSpacing: false,
3+
jsxBracketSameLine: true,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
};

example/App.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
1-
import React, { useRef, useState } from "react"
2-
import { StyleSheet, Text, TouchableOpacity, Image } from "react-native"
1+
import React, { useRef, useState, useEffect } from "react"
2+
import { View, StyleSheet, Text, TouchableOpacity, Image, Platform } from "react-native"
3+
import Permissions from 'react-native-permissions';
34
import PDFScanner from "@woonivers/react-native-document-scanner"
45

56
export default function App() {
67
const pdfScannerElement = useRef(null)
78
const [data, setData] = useState({})
9+
const [allowed, setAllowed] = useState(false)
10+
11+
useEffect(() => {
12+
async function requestCamera() {
13+
const result = await Permissions.request(Platform.OS === "android" ? "android.permission.CAMERA" : "ios.permission.CAMERA")
14+
if (result === "granted") setAllowed(true)
15+
}
16+
requestCamera()
17+
}, [])
818

919
function handleOnPressRetry() {
1020
setData({})
1121
}
1222
function handleOnPress() {
1323
pdfScannerElement.current.capture()
1424
}
25+
if (!allowed) {
26+
console.log("You must accept camera permission")
27+
return (<View style={styles.permissions}>
28+
<Text>You must accept camera permission</Text>
29+
</View>)
30+
}
1531
if (data.croppedImage) {
1632
console.log("data", data)
1733
return (
@@ -48,7 +64,8 @@ export default function App() {
4864
const styles = StyleSheet.create({
4965
scanner: {
5066
flex: 1,
51-
width: "100%",
67+
// width: "100%",
68+
5269
},
5370
button: {
5471
alignSelf: "center",
@@ -64,4 +81,9 @@ const styles = StyleSheet.create({
6481
width: "100%",
6582
resizeMode: "cover",
6683
},
84+
permissions: {
85+
flex:1,
86+
justifyContent: "center",
87+
alignItems: "center"
88+
}
6789
})

example/__tests__/App-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @format
3+
*/
4+
5+
import 'react-native';
6+
import React from 'react';
7+
import App from '../App';
8+
9+
// Note: test renderer must be required after react-native.
10+
import renderer from 'react-test-renderer';
11+
12+
it('renders correctly', () => {
13+
renderer.create(<App />);
14+
});

example/android/app/build.gradle

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import com.android.build.OutputFile
1818
* // the entry file for bundle generation
1919
* entryFile: "index.android.js",
2020
*
21+
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
22+
* bundleCommand: "ram-bundle",
23+
*
2124
* // whether to bundle JS and assets in debug mode
2225
* bundleInDebug: false,
2326
*
@@ -73,7 +76,8 @@ import com.android.build.OutputFile
7376
*/
7477

7578
project.ext.react = [
76-
entryFile: "index.js"
79+
entryFile: "index.js",
80+
enableHermes: false, // clean and rebuild if changing
7781
]
7882

7983
apply from: "../../node_modules/react-native/react.gradle"
@@ -93,6 +97,28 @@ def enableSeparateBuildPerCPUArchitecture = false
9397
*/
9498
def enableProguardInReleaseBuilds = false
9599

100+
/**
101+
* The preferred build flavor of JavaScriptCore.
102+
*
103+
* For example, to use the international variant, you can use:
104+
* `def jscFlavor = 'org.webkit:android-jsc-intl:+'`
105+
*
106+
* The international variant includes ICU i18n library and necessary data
107+
* allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that
108+
* give correct results when using with locales other than en-US. Note that
109+
* this variant is about 6MiB larger per architecture than default.
110+
*/
111+
def jscFlavor = 'org.webkit:android-jsc:+'
112+
113+
/**
114+
* Whether to enable the Hermes VM.
115+
*
116+
* This should be set on project.ext.react and mirrored here. If it is not set
117+
* on project.ext.react, JavaScript will not be compiled to Hermes Bytecode
118+
* and the benefits of using Hermes will therefore be sharply reduced.
119+
*/
120+
def enableHermes = project.ext.react.get("enableHermes", false);
121+
96122
android {
97123
compileSdkVersion rootProject.ext.compileSdkVersion
98124

@@ -116,8 +142,22 @@ android {
116142
include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
117143
}
118144
}
145+
signingConfigs {
146+
debug {
147+
storeFile file('debug.keystore')
148+
storePassword 'android'
149+
keyAlias 'androiddebugkey'
150+
keyPassword 'android'
151+
}
152+
}
119153
buildTypes {
154+
debug {
155+
signingConfig signingConfigs.debug
156+
}
120157
release {
158+
// Caution! In production, you need to generate your own keystore file.
159+
// see https://facebook.github.io/react-native/docs/signed-apk-android.
160+
signingConfig signingConfigs.debug
121161
minifyEnabled enableProguardInReleaseBuilds
122162
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
123163
}
@@ -126,22 +166,29 @@ android {
126166
applicationVariants.all { variant ->
127167
variant.outputs.each { output ->
128168
// For each separate APK per architecture, set a unique version code as described here:
129-
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
130-
def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
169+
// https://developer.android.com/studio/build/configure-apk-splits.html
170+
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
131171
def abi = output.getFilter(OutputFile.ABI)
132172
if (abi != null) { // null for the universal-debug, universal-release variants
133173
output.versionCodeOverride =
134174
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
135175
}
176+
136177
}
137178
}
138179
}
139180

140181
dependencies {
141-
implementation project(':@woonivers_react-native-document-scanner')
142182
implementation fileTree(dir: "libs", include: ["*.jar"])
143-
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
144183
implementation "com.facebook.react:react-native:+" // From node_modules
184+
185+
if (enableHermes) {
186+
def hermesPath = "../../node_modules/hermes-engine/android/";
187+
debugImplementation files(hermesPath + "hermes-debug.aar")
188+
releaseImplementation files(hermesPath + "hermes-release.aar")
189+
} else {
190+
implementation jscFlavor
191+
}
145192
}
146193

147194
// Run this once to be able to run the application with BUCK
@@ -150,3 +197,5 @@ task copyDownloadableDepsToLibs(type: Copy) {
150197
from configurations.compile
151198
into 'libs'
152199
}
200+
201+
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

example/android/app/debug.keystore

2.2 KB
Binary file not shown.

example/android/app/proguard-rules.pro

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,3 @@
88
# http://developer.android.com/guide/developing/tools/proguard.html
99

1010
# Add any project specific keep options here:
11-
12-
# If your project uses WebView with JS, uncomment the following
13-
# and specify the fully qualified class name to the JavaScript interface
14-
# class:
15-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16-
# public *;
17-
#}

example/android/app/src/main/java/com/example/MainActivity.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
public class MainActivity extends ReactActivity {
66

7-
/**
8-
* Returns the name of the main component registered from JavaScript.
9-
* This is used to schedule rendering of the component.
10-
*/
11-
@Override
12-
protected String getMainComponentName() {
13-
return "example";
14-
}
7+
/**
8+
* Returns the name of the main component registered from JavaScript. This is used to schedule
9+
* rendering of the component.
10+
*/
11+
@Override
12+
protected String getMainComponentName() {
13+
return "example";
14+
}
1515
}

0 commit comments

Comments
 (0)