From 45572cf72e70d13dd337ce4aa6a9e39ad712651b Mon Sep 17 00:00:00 2001 From: Rickard Ekman Date: Mon, 27 Jun 2016 14:03:01 +0200 Subject: [PATCH] React-Native 0.29 Compability --- android/build.gradle | 2 +- .../java/com/pw/droplet/braintree/Braintree.java | 16 +++++++++------- .../pw/droplet/braintree/BraintreePackage.java | 14 +------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 0e1e578a..ab9a1085 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -20,7 +20,7 @@ android { dependencies { compile fileTree(dir: "libs", include: ["*.jar"]) - compile "com.facebook.react:react-native:0.15.+" + compile "com.facebook.react:react-native:+" compile 'com.braintreepayments.api:braintree:2.+' compile 'com.braintreepayments.api:drop-in:2.+' } diff --git a/android/src/main/java/com/pw/droplet/braintree/Braintree.java b/android/src/main/java/com/pw/droplet/braintree/Braintree.java index 2ded2d87..8fe61881 100644 --- a/android/src/main/java/com/pw/droplet/braintree/Braintree.java +++ b/android/src/main/java/com/pw/droplet/braintree/Braintree.java @@ -17,8 +17,9 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.ActivityEventListener; -public class Braintree extends ReactContextBaseJavaModule { +public class Braintree extends ReactContextBaseJavaModule implements ActivityEventListener { private static final int PAYMENT_REQUEST = 1; private String token; @@ -29,9 +30,9 @@ public class Braintree extends ReactContextBaseJavaModule { private BraintreeFragment mBraintreeFragment; - public Braintree(ReactApplicationContext reactContext, Context activityContext) { + public Braintree(ReactApplicationContext reactContext) { super(reactContext); - this.mActivityContext = activityContext; + reactContext.addActivityEventListener(this); } @Override @@ -50,7 +51,7 @@ public void setToken(String token) { @ReactMethod public void setup(final String token, final Callback successCallback, final Callback errorCallback) { try { - this.mBraintreeFragment = BraintreeFragment.newInstance((Activity)this.mActivityContext, token); + this.mBraintreeFragment = BraintreeFragment.newInstance(getCurrentActivity(), token); this.mBraintreeFragment.addListener(new PaymentMethodNonceCreatedListener() { @Override public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) { @@ -89,13 +90,14 @@ public void paymentRequest(final Callback successCallback, final Callback errorC PaymentRequest paymentRequest = new PaymentRequest() .clientToken(this.getToken()); - ((Activity)this.mActivityContext).startActivityForResult( - paymentRequest.getIntent(this.mActivityContext), + (getCurrentActivity()).startActivityForResult( + paymentRequest.getIntent(getCurrentActivity()), PAYMENT_REQUEST ); } - public void handleActivityResult(final int requestCode, final int resultCode, final Intent data) { + @Override + public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { if (requestCode == PAYMENT_REQUEST) { switch (resultCode) { case Activity.RESULT_OK: diff --git a/android/src/main/java/com/pw/droplet/braintree/BraintreePackage.java b/android/src/main/java/com/pw/droplet/braintree/BraintreePackage.java index cff7d305..cdfbb518 100644 --- a/android/src/main/java/com/pw/droplet/braintree/BraintreePackage.java +++ b/android/src/main/java/com/pw/droplet/braintree/BraintreePackage.java @@ -1,8 +1,5 @@ package com.pw.droplet.braintree; -import android.content.Intent; -import android.content.Context; - import com.facebook.react.ReactPackage; import com.facebook.react.bridge.JavaScriptModule; import com.facebook.react.bridge.NativeModule; @@ -14,17 +11,12 @@ import java.util.List; public class BraintreePackage implements ReactPackage { - private Context mContext; private Braintree mModuleInstance; - public BraintreePackage(Context activityContext) { - mContext = activityContext; - } - @Override public List createNativeModules(ReactApplicationContext reactContext) { List modules = new ArrayList<>(); - mModuleInstance = new Braintree(reactContext, mContext); + mModuleInstance = new Braintree(reactContext); modules.add(mModuleInstance); return modules; @@ -39,8 +31,4 @@ public List> createJSModules() { public List createViewManagers(ReactApplicationContext reactContext) { return Collections.emptyList(); } - - public void handleActivityResult(final int requestCode, final int resultCode, final Intent data) { - mModuleInstance.handleActivityResult(requestCode, resultCode, data); - } }