Skip to content

Commit

Permalink
Merge pull request #599 from BranchMetrics/update-examples-to-beta-api
Browse files Browse the repository at this point in the history
Update examples to beta API
  • Loading branch information
jdee authored Aug 27, 2020
2 parents bfa8729 + c6d2201 commit 28daa71
Show file tree
Hide file tree
Showing 47 changed files with 8,413 additions and 8,443 deletions.
42 changes: 38 additions & 4 deletions android/src/main/java/io/branch/rnbranch/RNBranchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.text.SimpleDateFormat;
import java.util.*;

import javax.annotation.Nonnull;

public class RNBranchModule extends ReactContextBaseJavaModule {
public static final String REACT_CLASS = "RNBranch";
public static final String REACT_MODULE_NAME = "RNBranch";
Expand Down Expand Up @@ -88,6 +90,7 @@ public class RNBranchModule extends ReactContextBaseJavaModule {
private static Activity mActivity = null;
private static boolean mUseDebug = false;
private static boolean mInitialized = false;
private static volatile boolean mNewIntent = true;
private static JSONObject mRequestMetadata = new JSONObject();

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

mActivity = reactActivity;
final boolean isNewIntent = mNewIntent;
referralInitListener = new Branch.BranchReferralInitListener(){

private Activity mmActivity = null;
Expand All @@ -155,7 +159,7 @@ public void onInitFinished(JSONObject referringParams, BranchError error) {
try {
result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_PARAMS, referringParams);
result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_ERROR, error != null ? error.getMessage() : JSONObject.NULL);
result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_URI, uri != null ? uri.toString() : JSONObject.NULL);
result.put(NATIVE_INIT_SESSION_FINISHED_EVENT_URI, isNewIntent && uri != null ? uri.toString() : JSONObject.NULL);
}
catch (JSONException e) {

Expand Down Expand Up @@ -195,7 +199,11 @@ private void generateLocalBroadcast(JSONObject referringParams,
broadcastIntent.putExtra(NATIVE_INIT_SESSION_FINISHED_EVENT_LINK_PROPERTIES, linkProperties);
}

if (uri != null) {
/*
* isNewIntent is a capture of the value of mNewIntent above, so does not change when
* mNewIntent changes in onNewIntent.
*/
if (isNewIntent && uri != null) {
broadcastIntent.putExtra(NATIVE_INIT_SESSION_FINISHED_EVENT_URI, uri.toString());
}

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

/**
* Call from Activity.onNewIntent:
* @Override
* public void onNewIntent(Intent intent) {
* super.onNewIntent(intent);
* RNBranchModule.onNewIntent(intent);
* }
* @param intent the new Intent received via Activity.onNewIntent
*/
public static void onNewIntent(@Nonnull Intent intent) {
mActivity.setIntent(intent);
mNewIntent = true;
reInitSession(mActivity);
}

/**
* Notify JavaScript of init session start. This generates an RNBranch.initSessionStart
* event to JS via the RN native event emitter.
* @param context a Context for the LocalBroadcastManager
* @param uri the URI to include in the notification or null
*/
private static void notifyJSOfInitSessionStart(Context context, Uri uri) {
/*
* This check just ensures that we only generate one RNBranch.initSessionStart
* event per call to onNewIntent().
*/
if (!mNewIntent) return;
mNewIntent = false;

Intent broadcastIntent = new Intent(NATIVE_INIT_SESSION_STARTED_EVENT);
if (uri != null) {
broadcastIntent.putExtra(NATIVE_INIT_SESSION_STARTED_EVENT_URI, uri);
Expand Down Expand Up @@ -612,11 +642,15 @@ public void openURL(String url, ReadableMap options) {
return;
}

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

if (options.hasKey("newActivity") && options.getBoolean("newActivity")) mActivity.finish();
mActivity.startActivity(intent);
}

Expand Down
76 changes: 40 additions & 36 deletions examples/browser_example/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,70 @@
; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

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

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

; Ignore polyfills
.*/Libraries/polyfills/.*
; Flow doesn't support platforms
.*/Libraries/Utilities/LoadingView.js

; Ignore metro
.*/node_modules/metro/.*
[untyped]
.*/node_modules/@react-native-community/cli/.*/.*

[include]

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/

[options]
emoji=true

esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable

module.system=haste
module.system.haste.use_name_reducers=true
# get basename
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
# strip .js or .js.flow suffix
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
# strip .ios suffix
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
module.system.haste.paths.blacklist=.*/__tests__/.*
module.system.haste.paths.blacklist=.*/__mocks__/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
module.file_ext=.js
module.file_ext=.json
module.file_ext=.ios.js

munge_underscores=true

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'

module.file_ext=.js
module.file_ext=.jsx
module.file_ext=.json
module.file_ext=.native.js
module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
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'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native\\(_ios\\)?_\\(oss\\|fb\\)[a-z,_]*\\)?)\\)?:? #[0-9]+
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[lints]
sketchy-null-number=warn
sketchy-null-mixed=warn
sketchy-number=warn
untyped-type-import=warn
nonstrict-import=warn
deprecated-type=warn
unsafe-getters-setters=warn
inexact-spread=warn
unnecessary-invariant=warn
signature-verification-failure=warn
deprecated-utility=error

[strict]
deprecated-type
nonstrict-import
sketchy-null
unclear-type
unsafe-getters-setters
untyped-import
untyped-type-import

[version]
^0.78.0
^0.113.0
5 changes: 4 additions & 1 deletion examples/browser_example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IntelliJ
#
Expand All @@ -40,6 +39,7 @@ yarn-error.log
buck-out/
\.buckd/
*.keystore
!debug.keystore

# fastlane
#
Expand All @@ -54,3 +54,6 @@ buck-out/

# Bundle artifact
*.jsbundle

# CocoaPods
/ios/Pods/
6 changes: 6 additions & 0 deletions examples/browser_example/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
};
114 changes: 114 additions & 0 deletions examples/browser_example/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* Sample React Native App
* https:/facebook/react-native
*
* @format
* @flow strict-local
*/

import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
} from 'react-native';

import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';

const App: () => React$Node = () => {
return (
<>
<StatusBar barStyle="dark-content" />
<SafeAreaView>
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={styles.scrollView}>
<Header />
{global.HermesInternal == null ? null : (
<View style={styles.engine}>
<Text style={styles.footer}>Engine: Hermes</Text>
</View>
)}
<View style={styles.body}>
<View style={styles.sectionContainer}>
<Text style={styles.sectionTitle}>Step One</Text>
<Text style={styles.sectionDescription}>
Edit <Text style={styles.highlight}>App.js</Text> to change this
screen and then come back to see your edits.
</Text>
</View>
<View style={styles.sectionContainer}>
<Text style={styles.sectionTitle}>See Your Changes</Text>
<Text style={styles.sectionDescription}>
<ReloadInstructions />
</Text>
</View>
<View style={styles.sectionContainer}>
<Text style={styles.sectionTitle}>Debug</Text>
<Text style={styles.sectionDescription}>
<DebugInstructions />
</Text>
</View>
<View style={styles.sectionContainer}>
<Text style={styles.sectionTitle}>Learn More</Text>
<Text style={styles.sectionDescription}>
Read the docs to discover what to do next:
</Text>
</View>
<LearnMoreLinks />
</View>
</ScrollView>
</SafeAreaView>
</>
);
};

const styles = StyleSheet.create({
scrollView: {
backgroundColor: Colors.lighter,
},
engine: {
position: 'absolute',
right: 0,
},
body: {
backgroundColor: Colors.white,
},
sectionContainer: {
marginTop: 32,
paddingHorizontal: 24,
},
sectionTitle: {
fontSize: 24,
fontWeight: '600',
color: Colors.black,
},
sectionDescription: {
marginTop: 8,
fontSize: 18,
fontWeight: '400',
color: Colors.dark,
},
highlight: {
fontWeight: '700',
},
footer: {
color: Colors.dark,
fontSize: 12,
fontWeight: '600',
padding: 4,
paddingRight: 12,
textAlign: 'right',
},
});

export default App;
31 changes: 0 additions & 31 deletions examples/browser_example/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions examples/browser_example/android/app/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ android_library(

android_build_config(
name = "build_config",
package = "com.webview_example",
package = "com.browser_example",
)

android_resource(
name = "res",
package = "com.webview_example",
package = "com.browser_example",
res = "src/main/res",
)

Expand Down
Loading

0 comments on commit 28daa71

Please sign in to comment.