Skip to content

Commit d735cde

Browse files
committed
remove @OverRide onActivityResult in Android
1 parent 08b1c20 commit d735cde

4 files changed

Lines changed: 31 additions & 65 deletions

File tree

README.md

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,28 @@ This is the beta but functional MOLPay React Native payment module that is ready
1313

1414
- Node.js Version: 5.3.0 ++
1515

16-
- Minimum Android SDK Version: 25 ++
16+
- Minimum Android SDK Version: 27 ++
1717

1818
- Minimum Android API level: 19 ++
1919

2020
- Minimum Android target version: Android 4.4
2121

2222
- Minimum React Navtive version : 0.47.1 ++
2323

24-
- Xcode version: 7 ++
24+
- Xcode version: 9 ++
2525

26-
- Minimum target version: iOS 7
26+
- Minimum target version: iOS 8
2727

2828
## Installation
2929

3030
### Android
3131

3232
1) npm install molpay-mobile-xdk-reactnative-beta
3333

34-
2) add the following import to `MainApplication.java` (`MainActivity.java` if RN < 0.33) of your application
34+
2) add the following code to add the package to `MainApplication.java` (`MainActivity.java` if RN < 0.33)
3535

3636
```java
37-
//add these three
38-
import com.molpayxdk.MOLPayReact;
39-
import com.molpayxdk.MOLPayReactActivity;
40-
import android.content.Intent;
41-
42-
public class MainActivity extends ReactActivity {
43-
/**
44-
* Returns the name of the main component registered from JavaScript.
45-
* This is used to schedule rendering of the component.
46-
*/
47-
@Override
48-
protected String getMainComponentName() {
49-
return "MOLPayReactExampleProject";
50-
}
51-
52-
//add activity result in here
53-
@Override
54-
public void onActivityResult(int requestCode, int resultCode, Intent data)
55-
{
56-
if (requestCode == MOLPayReactActivity.MOLPayReactXDK && resultCode == RESULT_OK){
57-
if(MOLPayReact.successCallback != null){
58-
MOLPayReact.successCallback.invoke(data.getStringExtra(MOLPayReactActivity.MOLPayTransactionResult));
59-
}
60-
}
61-
}
62-
63-
}
64-
```
65-
66-
3) add the following code to add the package to `MainApplication.java`` (`MainActivity.java` if RN < 0.33)
67-
68-
```java
69-
import com.molpayxdk.MOLPayReactPackage;
37+
import com.molpayxdk.MOLPayReactPackage; //<- this
7038

7139
protected List<ReactPackage> getPackages() {
7240
return Arrays.<ReactPackage>asList(
@@ -76,7 +44,7 @@ protected List<ReactPackage> getPackages() {
7644
}
7745
```
7846

79-
4) add the following codes to your `android/setting.gradle`
47+
3) add the following codes to your `android/setting.gradle`
8048

8149
> you might have multiple 3rd party libraries, make sure that you don't create multiple include.
8250
@@ -85,13 +53,13 @@ include ':app', ':molpay-mobile-xdk-reactnative-beta'
8553
project(':molpay-mobile-xdk-reactnative-beta').projectDir = new File(rootProject.projectDir, '../node_modules/molpay-mobile-xdk-reactnative-beta/android')
8654
```
8755

88-
5) edit `android/app/build.gradle` and add the following line inside `dependencies`
56+
4) edit `android/app/build.gradle` and add the following line inside `dependencies`
8957

9058
```
9159
compile project(':molpay-mobile-xdk-reactnative-beta')
9260
```
9361

94-
6) run `react-native run-android` to see if everything is compilable.
62+
5) run `react-native run-android` to see if everything is compilable.
9563

9664
if have any issue when run-android please make sure your `android/local.properties` already set sdk path
9765

@@ -100,7 +68,7 @@ ndk.dir=path/Android/sdk/ndk-bundle
10068
sdk.dir=path/Android/sdk
10169
```
10270

103-
7) (Optional) header include Close button in payment UI
71+
6) (Optional) header include Close button in payment UI
10472
change the following codes in your `android/app/src/main/res/values/styles.xml`
10573
```
10674
<resources>

android/src/main/java/com/molpayxdk/MOLPayReact.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import com.facebook.react.bridge.ReactContextBaseJavaModule;
66
import com.facebook.react.bridge.ReactMethod;
77
import com.molpay.molpayxdk.MOLPayActivity;
8+
import android.content.Intent;
9+
10+
import android.app.Activity;
11+
import com.facebook.react.bridge.ActivityEventListener;
12+
import com.facebook.react.bridge.BaseActivityEventListener;
813

914
import org.json.JSONObject;
1015

@@ -13,11 +18,22 @@
1318

1419
import javax.annotation.Nullable;
1520

16-
public class MOLPayReact extends ReactContextBaseJavaModule{
21+
public class MOLPayReact extends ReactContextBaseJavaModule {
1722
public static HashMap<String, Object> paymentDetails;
1823
public static Callback successCallback;
1924
public static Callback errorCallback;
2025

26+
private final ActivityEventListener mActivityEventListener = new BaseActivityEventListener() {
27+
@Override
28+
public void onActivityResult(final Activity activity,int requestCode, int resultCode, Intent data) {
29+
if (requestCode == MOLPayActivity.MOLPayXDK && resultCode == Activity.RESULT_OK){
30+
if(successCallback != null){
31+
successCallback.invoke(data.getStringExtra(MOLPayActivity.MOLPayTransactionResult));
32+
}
33+
}
34+
}
35+
};
36+
2137
@Override
2238
public String getName() {
2339
return "MOLPay";
@@ -26,6 +42,7 @@ public String getName() {
2642

2743
public MOLPayReact(ReactApplicationContext reactContext) {
2844
super(reactContext);
45+
reactContext.addActivityEventListener(mActivityEventListener);
2946
}
3047

3148
@ReactMethod
@@ -56,8 +73,9 @@ public void setPaymentDetails(String str,@Nullable Callback successCallback, @Nu
5673
this.errorCallback.invoke(e);
5774
}
5875
}
59-
MOLPayReactActivity m = new MOLPayReactActivity();
60-
m.PaymentUpdated(getCurrentActivity());
76+
Intent intent = new Intent(getCurrentActivity(), MOLPayActivity.class);
77+
intent.putExtra(MOLPayActivity.MOLPayPaymentDetails, this.paymentDetails);
78+
getCurrentActivity().startActivityForResult(intent, MOLPayActivity.MOLPayXDK);
6179
}
6280

6381

android/src/main/java/com/molpayxdk/MOLPayReactActivity.java

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "molpay-mobile-xdk-reactnative-beta",
3-
"version": "0.18.3",
3+
"version": "0.18.4",
44
"description": "MOLPay mobile payment for React Native (BETA)",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1"

0 commit comments

Comments
 (0)