Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: New Architecture Support #1052

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apply plugin: 'com.android.library'
import groovy.json.JsonSlurper

def DEFAULT_COMPILE_SDK_VERSION = 29
def DEFAULT_COMPILE_SDK_VERSION = 34
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_TARGET_SDK_VERSION = 29
def DEFAULT_TARGET_SDK_VERSION = 34

def getNpmVersion() {
def packageJsonFile = file('../package.json')
Expand Down Expand Up @@ -47,5 +47,5 @@ def safeExtGet(prop, fallback) {
dependencies {
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
implementation 'com.facebook.react:react-native:+' // From node_modules
api 'io.branch.sdk.android:library:5.12.4'
api 'io.branch.sdk.android:library:5.14.0'
}
59 changes: 31 additions & 28 deletions android/src/main/java/io/branch/rnbranch/RNBranchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Base64;

Expand Down Expand Up @@ -178,7 +177,7 @@ private void generateLocalBroadcast(JSONObject referringParams,
BranchUniversalObject branchUniversalObject,
LinkProperties linkProperties,
BranchError error) {

Intent broadcastIntent = new Intent(NATIVE_INIT_SESSION_FINISHED_EVENT);

if (referringParams != null) {
Expand Down Expand Up @@ -210,7 +209,7 @@ private void generateLocalBroadcast(JSONObject referringParams,
}.init(reactActivity);

notifyJSOfInitSessionStart(reactActivity, uri);

Branch.InitSessionBuilder initSessionBuilder = Branch.sessionBuilder(reactActivity).withCallback(referralInitListener).withData(uri);
Log.d(REACT_CLASS, "sessionBuilder " + initSessionBuilder);
initSessionBuilder.init();
Expand Down Expand Up @@ -261,6 +260,10 @@ public static void enableLogging() {
Branch.enableLogging();
}

public static void enableLogging(BranchLogger.BranchLogLevel logLevel) {
Branch.enableLogging(logLevel);
}

public static void setRequestMetadata(String key, String val) {
if (key == null) {
return;
Expand Down Expand Up @@ -336,7 +339,7 @@ private void listenForInitSessionEventsToReactNative(ReactApplicationContext rea
public void onReceive(Context context, Intent intent) {
final boolean hasError = (initSessionResult.has("error") && !initSessionResult.isNull("error"));
final String eventName = hasError ? RN_INIT_SESSION_ERROR_EVENT : RN_INIT_SESSION_SUCCESS_EVENT;

mBranchModule.sendRNEvent(eventName, convertJsonToMap(initSessionResult));
}

Expand Down Expand Up @@ -374,8 +377,8 @@ private BroadcastReceiver init(RNBranchModule branchModule) {
}

@Override
public void onCatalystInstanceDestroy() {
Log.d(REACT_CLASS,"onCatalystInstanceDestroy ");
public void invalidate() {
Log.d(REACT_CLASS,"React instance invalidate()");

LocalBroadcastManager.getInstance(getReactApplicationContext()).unregisterReceiver(mInitSessionFinishedEventReceiver);
LocalBroadcastManager.getInstance(getReactApplicationContext()).unregisterReceiver(mInitSessionStartedEventReceiver);
Expand Down Expand Up @@ -444,15 +447,15 @@ public void getFirstReferringParams(Promise promise) {
public void lastAttributedTouchData(int window, final Promise promise) {
Branch branch = Branch.getInstance();
branch.getLastAttributedTouchData(new ServerRequestGetLATD.BranchLastAttributedTouchDataListener() {
@Override
public void onDataFetched(JSONObject jsonObject, BranchError error) {
if (error == null) {
promise.resolve(convertJsonToMap(jsonObject));
} else {
promise.reject(GENERIC_ERROR, error.getMessage());
}
@Override
public void onDataFetched(JSONObject jsonObject, BranchError error) {
if (error == null) {
promise.resolve(convertJsonToMap(jsonObject));
} else {
promise.reject(GENERIC_ERROR, error.getMessage());
}
}, window);
}
}, window);
}

@ReactMethod
Expand All @@ -461,7 +464,7 @@ public void setIdentity(String identity) {
branch.setIdentity(identity);
}

@ReactMethod
@ReactMethod
public void setIdentityAsync(String identity, final Promise promise) {
Branch branch = Branch.getInstance();
branch.setIdentity(identity, new Branch.BranchReferralInitListener() {
Expand Down Expand Up @@ -633,7 +636,7 @@ private Branch.BranchLinkShareListener init(Promise promise) {
public void registerView(String ident, Promise promise) {
BranchUniversalObject branchUniversalObject = findUniversalObjectOrReject(ident, promise);
if (branchUniversalObject == null) {
return;
return;
}

branchUniversalObject.registerView();
Expand Down Expand Up @@ -692,9 +695,9 @@ public void openURL(String url, ReadableMap options) {
mActivity.startActivity(intent);
}

@ReactMethod
@ReactMethod
public void getBranchQRCode(ReadableMap branchQRCodeSettingsMap, ReadableMap branchUniversalObjectMap, ReadableMap linkPropertiesMap, ReadableMap controlParamsMap, final Promise promise) {

BranchUniversalObject branchUniversalObject = createBranchUniversalObject(branchUniversalObjectMap);
LinkProperties linkProperties = createLinkProperties(linkPropertiesMap, controlParamsMap);
BranchQRCode qrCode = createBranchQRCode(branchQRCodeSettingsMap);
Expand All @@ -706,13 +709,13 @@ public void onSuccess(byte[] qrCodeData) {
String qrCodeString = Base64.encodeToString(qrCodeData, Base64.DEFAULT);
promise.resolve(qrCodeString);
}

@Override
public void onFailure(Exception e) {
Log.d("Failed to get QR Code", e.getMessage());
promise.reject("Failed to get QR Code", e.getMessage());
}
});
}
});
} catch (IOException e) {
e.printStackTrace();
Log.d("Failed to get QR Code", e.getMessage());
Expand All @@ -728,7 +731,7 @@ public BranchQRCode createBranchQRCode(ReadableMap branchQRCodeSettingsMap) {
if (branchQRCodeSettingsMap.hasKey("centerLogo")) branchQRCode.setCenterLogo(branchQRCodeSettingsMap.getString("centerLogo"));
if (branchQRCodeSettingsMap.hasKey("width")) branchQRCode.setWidth(branchQRCodeSettingsMap.getInt("width"));
if (branchQRCodeSettingsMap.hasKey("margin")) branchQRCode.setMargin(branchQRCodeSettingsMap.getInt("margin"));

if (branchQRCodeSettingsMap.hasKey("imageFormat")) {
String imageFormat = branchQRCodeSettingsMap.getString("imageFormat");
if (imageFormat != null ) {
Expand Down Expand Up @@ -780,7 +783,7 @@ public static BranchEvent createBranchEvent(String eventName, ReadableMap params
ReadableMapKeySetIterator it = customData.keySetIterator();
while (it.hasNextKey()) {
String key = it.nextKey();

ReadableType readableType = customData.getType(key);
if(readableType == ReadableType.String) {
event.addCustomDataProperty(key, customData.getString(key));
Expand Down Expand Up @@ -1085,9 +1088,9 @@ private Runnable init(ReactApplicationContext _context, Handler _mainHandler, St
@Override
public void run() {
try {
Log.d(REACT_CLASS, "Catalyst instance poller try " + Integer.toString(tries));
if (mContext.hasActiveCatalystInstance()) {
Log.d(REACT_CLASS, "Catalyst instance active");
Log.d(REACT_CLASS, "React instance poller try " + Integer.toString(tries));
if (mContext.hasActiveReactInstance()) {
Log.d(REACT_CLASS, "Has React instance");
mContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(mEventName, mParams);
Expand All @@ -1096,12 +1099,12 @@ public void run() {
if (tries <= maxTries) {
mMainHandler.postDelayed(this, pollDelayInMs);
} else {
Log.e(REACT_CLASS, "Could not get Catalyst instance");
Log.e(REACT_CLASS, "Could not get React instance");
}
}
}
catch (Exception e) {
e.printStackTrace();
Log.e(REACT_CLASS, Objects.requireNonNull(e.getMessage()));
}
}
}.init(context, mainHandler, eventName, params);
Expand Down
2 changes: 2 additions & 0 deletions newarchitectureexample/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
4 changes: 4 additions & 0 deletions newarchitectureexample/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native',
};
74 changes: 74 additions & 0 deletions newarchitectureexample/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
**/.xcode.env.local

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/
*.keystore
!debug.keystore

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# Ruby / CocoaPods
**/Pods/
/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
7 changes: 7 additions & 0 deletions newarchitectureexample/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: false,
singleQuote: true,
trailingComma: 'all',
};
1 change: 1 addition & 0 deletions newarchitectureexample/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading
Loading