Skip to content

Commit

Permalink
React-Native 0.29 Compability
Browse files Browse the repository at this point in the history
  • Loading branch information
kraffslol committed Jun 27, 2016
1 parent 12f845e commit 45572cf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.+'
}
16 changes: 9 additions & 7 deletions android/src/main/java/com/pw/droplet/braintree/Braintree.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
mModuleInstance = new Braintree(reactContext, mContext);
mModuleInstance = new Braintree(reactContext);

modules.add(mModuleInstance);
return modules;
Expand All @@ -39,8 +31,4 @@ public List<Class<? extends JavaScriptModule>> createJSModules() {
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}

public void handleActivityResult(final int requestCode, final int resultCode, final Intent data) {
mModuleInstance.handleActivityResult(requestCode, resultCode, data);
}
}

0 comments on commit 45572cf

Please sign in to comment.