Skip to content

Commit 28daa71

Browse files
authored
Merge pull request #599 from BranchMetrics/update-examples-to-beta-api
Update examples to beta API
2 parents bfa8729 + c6d2201 commit 28daa71

File tree

47 files changed

+8413
-8443
lines changed

Some content is hidden

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

47 files changed

+8413
-8443
lines changed

android/src/main/java/io/branch/rnbranch/RNBranchModule.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import java.text.SimpleDateFormat;
3131
import java.util.*;
3232

33+
import javax.annotation.Nonnull;
34+
3335
public class RNBranchModule extends ReactContextBaseJavaModule {
3436
public static final String REACT_CLASS = "RNBranch";
3537
public static final String REACT_MODULE_NAME = "RNBranch";
@@ -88,6 +90,7 @@ public class RNBranchModule extends ReactContextBaseJavaModule {
8890
private static Activity mActivity = null;
8991
private static boolean mUseDebug = false;
9092
private static boolean mInitialized = false;
93+
private static volatile boolean mNewIntent = true;
9194
private static JSONObject mRequestMetadata = new JSONObject();
9295

9396
private AgingHash<String, BranchUniversalObject> mUniversalObjectMap = new AgingHash<>(AGING_HASH_TTL);
@@ -138,6 +141,7 @@ public static void initSession(final Uri uri, Activity reactActivity) {
138141
Branch branch = setupBranch(reactActivity.getApplicationContext());
139142

140143
mActivity = reactActivity;
144+
final boolean isNewIntent = mNewIntent;
141145
referralInitListener = new Branch.BranchReferralInitListener(){
142146

143147
private Activity mmActivity = null;
@@ -155,7 +159,7 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
155159
try {
156160
result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_PARAMS, referringParams);
157161
result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_ERROR, error != null ? error.getMessage() : JSONObject.NULL);
158-
result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_URI, uri != null ? uri.toString() : JSONObject.NULL);
162+
result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_URI, isNewIntent && uri != null ? uri.toString() : JSONObject.NULL);
159163
}
160164
catch (JSONException e) {
161165

@@ -195,7 +199,11 @@ private void generateLocalBroadcast(JSONObject referringParams,
195199
broadcastIntent.putExtra(NATIVE_INIT_SESSION_FINISHED_EVENT_LINK_PROPERTIES, linkProperties);
196200
}
197201

198-
if (uri != null) {
202+
/*
203+
* isNewIntent is a capture of the value of mNewIntent above, so does not change when
204+
* mNewIntent changes in onNewIntent.
205+
*/
206+
if (isNewIntent && uri != null) {
199207
broadcastIntent.putExtra(NATIVE_INIT_SESSION_FINISHED_EVENT_URI, uri.toString());
200208
}
201209

@@ -211,13 +219,35 @@ private void generateLocalBroadcast(JSONObject referringParams,
211219
Branch.sessionBuilder(reactActivity).withCallback(referralInitListener).withData(uri).init();
212220
}
213221

222+
/**
223+
* Call from Activity.onNewIntent:
224+
* @Override
225+
* public void onNewIntent(Intent intent) {
226+
* super.onNewIntent(intent);
227+
* RNBranchModule.onNewIntent(intent);
228+
* }
229+
* @param intent the new Intent received via Activity.onNewIntent
230+
*/
231+
public static void onNewIntent(@Nonnull Intent intent) {
232+
mActivity.setIntent(intent);
233+
mNewIntent = true;
234+
reInitSession(mActivity);
235+
}
236+
214237
/**
215238
* Notify JavaScript of init session start. This generates an RNBranch.initSessionStart
216239
* event to JS via the RN native event emitter.
217240
* @param context a Context for the LocalBroadcastManager
218241
* @param uri the URI to include in the notification or null
219242
*/
220243
private static void notifyJSOfInitSessionStart(Context context, Uri uri) {
244+
/*
245+
* This check just ensures that we only generate one RNBranch.initSessionStart
246+
* event per call to onNewIntent().
247+
*/
248+
if (!mNewIntent) return;
249+
mNewIntent = false;
250+
221251
Intent broadcastIntent = new Intent(NATIVE_INIT_SESSION_STARTED_EVENT);
222252
if (uri != null) {
223253
broadcastIntent.putExtra(NATIVE_INIT_SESSION_STARTED_EVENT_URI, uri);
@@ -612,11 +642,15 @@ public void openURL(String url, ReadableMap options) {
612642
return;
613643
}
614644

645+
/*
646+
* Using Intent.ACTION_VIEW here will open a browser for non-Branch links unless the
647+
* domain is registered in an intent-filter in the manifest. Instead specify the host
648+
* Activity.
649+
*/
615650
Intent intent = new Intent(mActivity, mActivity.getClass());
616-
intent.putExtra("branch", url);
651+
intent.setData(Uri.parse(url));
617652
intent.putExtra("branch_force_new_session", true);
618653

619-
if (options.hasKey("newActivity") && options.getBoolean("newActivity")) mActivity.finish();
620654
mActivity.startActivity(intent);
621655
}
622656

examples/browser_example/.flowconfig

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,66 +5,70 @@
55
; Ignore "BUCK" generated dirs
66
<PROJECT_ROOT>/\.buckd/
77

8-
; Ignore unexpected extra "@providesModule"
9-
.*/node_modules/.*/node_modules/fbjs/.*
8+
; Ignore polyfills
9+
node_modules/react-native/Libraries/polyfills/.*
1010

11-
; Ignore duplicate module providers
12-
; For RN Apps installed via npm, "Libraries" folder is inside
13-
; "node_modules/react-native" but in the source repo it is in the root
14-
.*/Libraries/react-native/React.js
11+
; These should not be required directly
12+
; require from fbjs/lib instead: require('fbjs/lib/warning')
13+
node_modules/warning/.*
1514

16-
; Ignore polyfills
17-
.*/Libraries/polyfills/.*
15+
; Flow doesn't support platforms
16+
.*/Libraries/Utilities/LoadingView.js
1817

19-
; Ignore metro
20-
.*/node_modules/metro/.*
18+
[untyped]
19+
.*/node_modules/@react-native-community/cli/.*/.*
2120

2221
[include]
2322

2423
[libs]
25-
node_modules/react-native/Libraries/react-native/react-native-interface.js
24+
node_modules/react-native/interface.js
2625
node_modules/react-native/flow/
27-
node_modules/react-native/flow-github/
2826

2927
[options]
3028
emoji=true
3129

3230
esproposal.optional_chaining=enable
3331
esproposal.nullish_coalescing=enable
3432

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

5037
munge_underscores=true
5138

52-
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'
53-
54-
module.file_ext=.js
55-
module.file_ext=.jsx
56-
module.file_ext=.json
57-
module.file_ext=.native.js
39+
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
40+
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\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'
5841

5942
suppress_type=$FlowIssue
6043
suppress_type=$FlowFixMe
6144
suppress_type=$FlowFixMeProps
6245
suppress_type=$FlowFixMeState
6346

64-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
65-
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
66-
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
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]+
6749
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
6850

51+
[lints]
52+
sketchy-null-number=warn
53+
sketchy-null-mixed=warn
54+
sketchy-number=warn
55+
untyped-type-import=warn
56+
nonstrict-import=warn
57+
deprecated-type=warn
58+
unsafe-getters-setters=warn
59+
inexact-spread=warn
60+
unnecessary-invariant=warn
61+
signature-verification-failure=warn
62+
deprecated-utility=error
63+
64+
[strict]
65+
deprecated-type
66+
nonstrict-import
67+
sketchy-null
68+
unclear-type
69+
unsafe-getters-setters
70+
untyped-import
71+
untyped-type-import
72+
6973
[version]
70-
^0.78.0
74+
^0.113.0

examples/browser_example/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ DerivedData
2020
*.hmap
2121
*.ipa
2222
*.xcuserstate
23-
project.xcworkspace
2423

2524
# Android/IntelliJ
2625
#
@@ -40,6 +39,7 @@ yarn-error.log
4039
buck-out/
4140
\.buckd/
4241
*.keystore
42+
!debug.keystore
4343

4444
# fastlane
4545
#
@@ -54,3 +54,6 @@ buck-out/
5454

5555
# Bundle artifact
5656
*.jsbundle
57+
58+
# CocoaPods
59+
/ios/Pods/
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+
};

examples/browser_example/App.js

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/**
2+
* Sample React Native App
3+
* https://github.com/facebook/react-native
4+
*
5+
* @format
6+
* @flow strict-local
7+
*/
8+
9+
import React from 'react';
10+
import {
11+
SafeAreaView,
12+
StyleSheet,
13+
ScrollView,
14+
View,
15+
Text,
16+
StatusBar,
17+
} from 'react-native';
18+
19+
import {
20+
Header,
21+
LearnMoreLinks,
22+
Colors,
23+
DebugInstructions,
24+
ReloadInstructions,
25+
} from 'react-native/Libraries/NewAppScreen';
26+
27+
const App: () => React$Node = () => {
28+
return (
29+
<>
30+
<StatusBar barStyle="dark-content" />
31+
<SafeAreaView>
32+
<ScrollView
33+
contentInsetAdjustmentBehavior="automatic"
34+
style={styles.scrollView}>
35+
<Header />
36+
{global.HermesInternal == null ? null : (
37+
<View style={styles.engine}>
38+
<Text style={styles.footer}>Engine: Hermes</Text>
39+
</View>
40+
)}
41+
<View style={styles.body}>
42+
<View style={styles.sectionContainer}>
43+
<Text style={styles.sectionTitle}>Step One</Text>
44+
<Text style={styles.sectionDescription}>
45+
Edit <Text style={styles.highlight}>App.js</Text> to change this
46+
screen and then come back to see your edits.
47+
</Text>
48+
</View>
49+
<View style={styles.sectionContainer}>
50+
<Text style={styles.sectionTitle}>See Your Changes</Text>
51+
<Text style={styles.sectionDescription}>
52+
<ReloadInstructions />
53+
</Text>
54+
</View>
55+
<View style={styles.sectionContainer}>
56+
<Text style={styles.sectionTitle}>Debug</Text>
57+
<Text style={styles.sectionDescription}>
58+
<DebugInstructions />
59+
</Text>
60+
</View>
61+
<View style={styles.sectionContainer}>
62+
<Text style={styles.sectionTitle}>Learn More</Text>
63+
<Text style={styles.sectionDescription}>
64+
Read the docs to discover what to do next:
65+
</Text>
66+
</View>
67+
<LearnMoreLinks />
68+
</View>
69+
</ScrollView>
70+
</SafeAreaView>
71+
</>
72+
);
73+
};
74+
75+
const styles = StyleSheet.create({
76+
scrollView: {
77+
backgroundColor: Colors.lighter,
78+
},
79+
engine: {
80+
position: 'absolute',
81+
right: 0,
82+
},
83+
body: {
84+
backgroundColor: Colors.white,
85+
},
86+
sectionContainer: {
87+
marginTop: 32,
88+
paddingHorizontal: 24,
89+
},
90+
sectionTitle: {
91+
fontSize: 24,
92+
fontWeight: '600',
93+
color: Colors.black,
94+
},
95+
sectionDescription: {
96+
marginTop: 8,
97+
fontSize: 18,
98+
fontWeight: '400',
99+
color: Colors.dark,
100+
},
101+
highlight: {
102+
fontWeight: '700',
103+
},
104+
footer: {
105+
color: Colors.dark,
106+
fontSize: 12,
107+
fontWeight: '600',
108+
padding: 4,
109+
paddingRight: 12,
110+
textAlign: 'right',
111+
},
112+
});
113+
114+
export default App;

examples/browser_example/README.md

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

examples/browser_example/android/app/BUCK

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ android_library(
3535

3636
android_build_config(
3737
name = "build_config",
38-
package = "com.webview_example",
38+
package = "com.browser_example",
3939
)
4040

4141
android_resource(
4242
name = "res",
43-
package = "com.webview_example",
43+
package = "com.browser_example",
4444
res = "src/main/res",
4545
)
4646

0 commit comments

Comments
 (0)