Skip to content

Commit 96b2e40

Browse files
committed
Update example project to RN 0.64.2
1 parent b6a193b commit 96b2e40

File tree

32 files changed

+656
-1228
lines changed

32 files changed

+656
-1228
lines changed

example/.flowconfig

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
; Ignore polyfills
99
node_modules/react-native/Libraries/polyfills/.*
1010

11-
; These should not be required directly
12-
; require from fbjs/lib instead: require('fbjs/lib/warning')
13-
node_modules/warning/.*
14-
1511
; Flow doesn't support platforms
1612
.*/Libraries/Utilities/LoadingView.js
1713

@@ -30,6 +26,8 @@ emoji=true
3026
esproposal.optional_chaining=enable
3127
esproposal.nullish_coalescing=enable
3228

29+
exact_by_default=true
30+
3331
module.file_ext=.js
3432
module.file_ext=.json
3533
module.file_ext=.ios.js
@@ -44,10 +42,6 @@ suppress_type=$FlowFixMe
4442
suppress_type=$FlowFixMeProps
4543
suppress_type=$FlowFixMeState
4644

47-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
48-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
49-
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
50-
5145
[lints]
5246
sketchy-null-number=warn
5347
sketchy-null-mixed=warn
@@ -56,10 +50,8 @@ untyped-type-import=warn
5650
nonstrict-import=warn
5751
deprecated-type=warn
5852
unsafe-getters-setters=warn
59-
inexact-spread=warn
6053
unnecessary-invariant=warn
6154
signature-verification-failure=warn
62-
deprecated-utility=error
6355

6456
[strict]
6557
deprecated-type
@@ -71,4 +63,4 @@ untyped-import
7163
untyped-type-import
7264

7365
[version]
74-
^0.113.0
66+
^0.137.0

example/.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
*.pbxproj -text
1+
# Windows files should use crlf line endings
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
*.bat text eol=crlf

example/.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,3 @@ buck-out/
5757

5858
# CocoaPods
5959
/ios/Pods/
60-
61-
yarn.lock

example/.prettierrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ module.exports = {
33
jsxBracketSameLine: true,
44
singleQuote: true,
55
trailingComma: 'all',
6+
arrowParens: 'avoid',
67
};

example/App.js

Lines changed: 33 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@
66
* @flow strict-local
77
*/
88

9-
import React, {Component} from 'react';
9+
import React, {useCallback, useState} from 'react';
1010
import {
1111
Platform,
12+
StatusBar,
1213
StyleSheet,
1314
Text,
15+
TextInput,
1416
View,
1517
Button,
16-
Alert,
17-
TextInput,
18-
StatusBar,
19-
Linking,
2018
} from 'react-native';
21-
import {InAppBrowser} from 'react-native-inappbrowser-reborn';
19+
import {openLink, tryDeepLinking} from './utils';
2220

2321
const instructions = Platform.select({
2422
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
@@ -27,142 +25,36 @@ const instructions = Platform.select({
2725
'Shake or press menu button for dev menu',
2826
});
2927

30-
type ComponentState = {
31-
url: string,
32-
statusBarStyle: string,
33-
};
34-
35-
export default class App extends Component<ComponentState> {
36-
constructor(props) {
37-
super(props);
38-
39-
this.state = {
40-
url: 'https://reactnative.dev',
41-
statusBarStyle: 'dark-content',
42-
};
43-
}
28+
const App = () => {
29+
const [url, setUrl] = useState('https://reactnative.dev');
30+
const [statusBarStyle] = useState('dark-content');
4431

45-
sleep(timeout: number) {
46-
return new Promise((resolve) => setTimeout(resolve, timeout));
47-
}
32+
const onOpenLink = useCallback(async () => {
33+
await openLink(url, statusBarStyle);
34+
}, [url, statusBarStyle]);
4835

49-
async openLink() {
50-
const {url, statusBarStyle} = this.state;
51-
try {
52-
if (await InAppBrowser.isAvailable()) {
53-
// A delay to change the StatusBar when the browser is opened
54-
const animated = true;
55-
const delay = animated && Platform.OS === 'ios' ? 400 : 0;
56-
setTimeout(() => StatusBar.setBarStyle('light-content'), delay);
57-
const result = await InAppBrowser.open(url, {
58-
// iOS Properties
59-
dismissButtonStyle: 'cancel',
60-
preferredBarTintColor: '#453AA4',
61-
preferredControlTintColor: 'white',
62-
readerMode: true,
63-
animated,
64-
modalPresentationStyle: 'fullScreen',
65-
modalTransitionStyle: 'flipHorizontal',
66-
modalEnabled: true,
67-
enableBarCollapsing: true,
68-
// Android Properties
69-
showTitle: true,
70-
toolbarColor: '#6200EE',
71-
secondaryToolbarColor: 'black',
72-
navigationBarColor: 'black',
73-
navigationBarDividerColor: 'white',
74-
enableUrlBarHiding: true,
75-
enableDefaultShare: true,
76-
forceCloseOnRedirection: false,
77-
// Specify full animation resource identifier(package:anim/name)
78-
// or only resource name(in case of animation bundled with app).
79-
animations: {
80-
startEnter: 'slide_in_right',
81-
startExit: 'slide_out_left',
82-
endEnter: 'slide_in_left',
83-
endExit: 'slide_out_right',
84-
},
85-
headers: {
86-
'my-custom-header': 'my custom header value',
87-
},
88-
hasBackButton: true,
89-
browserPackage: null,
90-
showInRecents: false,
91-
});
92-
// A delay to show an alert when the browser is closed
93-
await this.sleep(800);
94-
Alert.alert('Response', JSON.stringify(result));
95-
} else {
96-
Linking.openURL(url);
97-
}
98-
} catch (error) {
99-
console.error(error);
100-
Alert.alert(error.message || error);
101-
} finally {
102-
// Restore the previous StatusBar of the App
103-
StatusBar.setBarStyle(statusBarStyle);
104-
}
105-
}
106-
107-
getDeepLink(path = '') {
108-
const scheme = 'my-demo';
109-
const prefix =
110-
Platform.OS === 'android' ? `${scheme}://demo/` : `${scheme}://`;
111-
return prefix + path;
112-
}
113-
114-
async tryDeepLinking() {
115-
const loginUrl = 'https://proyecto26.github.io/react-native-inappbrowser/';
116-
const redirectUrl = this.getDeepLink();
117-
const url = `${loginUrl}?redirect_url=${encodeURIComponent(redirectUrl)}`;
118-
try {
119-
if (await InAppBrowser.isAvailable()) {
120-
const result = await InAppBrowser.openAuth(url, redirectUrl, {
121-
// iOS Properties
122-
ephemeralWebSession: false,
123-
// Android Properties
124-
showTitle: false,
125-
enableUrlBarHiding: true,
126-
enableDefaultShare: false,
127-
});
128-
Alert.alert('Response', JSON.stringify(result));
129-
} else {
130-
Alert.alert('InAppBrowser is not supported :/');
131-
}
132-
} catch (error) {
133-
console.error(error);
134-
Alert.alert('Something’s wrong with the app :(');
135-
}
136-
}
137-
138-
render() {
139-
const {statusBarStyle} = this.state;
140-
return (
141-
<View style={styles.container}>
142-
<StatusBar barStyle={statusBarStyle} />
143-
<Text style={styles.welcome}>
144-
{'Welcome InAppBrowser\nfor React Native!'}
145-
</Text>
146-
<Text style={styles.instructions}>Type the url</Text>
147-
<TextInput
148-
style={styles.urlInput}
149-
onChangeText={(text) => this.setState({url: text})}
150-
value={this.state.url}
151-
/>
152-
<View style={styles.openButton}>
153-
<Button title="Open link" onPress={() => this.openLink()} />
154-
</View>
155-
<View style={styles.openButton}>
156-
<Button
157-
title="Try deep linking"
158-
onPress={() => this.tryDeepLinking()}
159-
/>
160-
</View>
161-
<Text style={styles.instructions}>{instructions}</Text>
36+
return (
37+
<View style={styles.container}>
38+
<StatusBar barStyle={statusBarStyle} />
39+
<Text style={styles.welcome}>
40+
{'Welcome InAppBrowser\nfor React Native!'}
41+
</Text>
42+
<Text style={styles.instructions}>Type the url</Text>
43+
<TextInput
44+
style={styles.urlInput}
45+
onChangeText={text => setUrl(text)}
46+
value={url}
47+
/>
48+
<View style={styles.openButton}>
49+
<Button title="Open link" onPress={onOpenLink} />
16250
</View>
163-
);
164-
}
165-
}
51+
<View style={styles.openButton}>
52+
<Button title="Try deep linking" onPress={tryDeepLinking} />
53+
</View>
54+
<Text style={styles.instructions}>{instructions}</Text>
55+
</View>
56+
);
57+
};
16658

16759
const styles = StyleSheet.create({
16860
container: {
@@ -193,3 +85,5 @@ const styles = StyleSheet.create({
19385
paddingBottom: Platform.OS === 'ios' ? 0 : 20,
19486
},
19587
});
88+
89+
export default App;

example/_editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Windows files
2+
[*.bat]
3+
end_of_line = crlf

example/android/app/build.gradle

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import com.android.build.OutputFile
2020
* // default. Can be overridden with ENTRY_FILE environment variable.
2121
* entryFile: "index.android.js",
2222
*
23-
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
23+
* // https://reactnative.dev/docs/performance#enable-the-ram-format
2424
* bundleCommand: "ram-bundle",
2525
*
2626
* // whether to bundle JS and assets in debug mode
@@ -121,6 +121,8 @@ def jscFlavor = 'org.webkit:android-jsc:+'
121121
def enableHermes = project.ext.react.get("enableHermes", false);
122122

123123
android {
124+
ndkVersion rootProject.ext.ndkVersion
125+
124126
compileSdkVersion rootProject.ext.compileSdkVersion
125127

126128
compileOptions {
@@ -157,30 +159,24 @@ android {
157159
}
158160
release {
159161
// Caution! In production, you need to generate your own keystore file.
160-
// see https://facebook.github.io/react-native/docs/signed-apk-android.
162+
// see https://reactnative.dev/docs/signed-apk-android.
161163
signingConfig signingConfigs.debug
162164
minifyEnabled enableProguardInReleaseBuilds
163165
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
164166
}
165167
}
166168

167-
packagingOptions {
168-
pickFirst "lib/armeabi-v7a/libc++_shared.so"
169-
pickFirst "lib/arm64-v8a/libc++_shared.so"
170-
pickFirst "lib/x86/libc++_shared.so"
171-
pickFirst "lib/x86_64/libc++_shared.so"
172-
}
173-
174169
// applicationVariants are e.g. debug, release
175170
applicationVariants.all { variant ->
176171
variant.outputs.each { output ->
177172
// For each separate APK per architecture, set a unique version code as described here:
178173
// https://developer.android.com/studio/build/configure-apk-splits.html
174+
// Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc.
179175
def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
180176
def abi = output.getFilter(OutputFile.ABI)
181177
if (abi != null) { // null for the universal-debug, universal-release variants
182178
output.versionCodeOverride =
183-
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
179+
defaultConfig.versionCode * 1000 + versionCodes.get(abi)
184180
}
185181

186182
}
@@ -200,6 +196,7 @@ dependencies {
200196

201197
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
202198
exclude group:'com.facebook.flipper'
199+
exclude group:'com.squareup.okhttp3', module:'okhttp'
203200
}
204201

205202
debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44

55
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
66

7-
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
7+
<application
8+
android:usesCleartextTraffic="true"
9+
tools:targetApi="28"
10+
tools:ignore="GoogleAppIndexingWarning">
11+
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
12+
</application>
813
</manifest>

example/android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@
2828
<data android:scheme="my-demo" android:host="demo" />
2929
</intent-filter>
3030
</activity>
31-
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
3231
</application>
33-
3432
</manifest>

0 commit comments

Comments
 (0)