Allow using Activity instead of FragmentActivity

This commit is contained in:
Janic Duplessis 2016-01-24 12:57:05 -05:00
parent afcb088eab
commit 805292d39b
3 changed files with 11 additions and 13 deletions

View File

@ -34,12 +34,11 @@ dependencies {
``` ```
The changes should look like [this](https://github.com/aakashns/react-native-dialogs-example/commit/b58086d8fb9ece99f0e678dd8bf0e689a856bd43). The changes should look like [this](https://github.com/aakashns/react-native-dialogs-example/commit/b58086d8fb9ece99f0e678dd8bf0e689a856bd43).
Next, you need to change the `MainActivity` of your app to extends `FragmentActivity` instead of `Activity` (otherwise dialogs will not be rendered), and register `ReactNativeDialogsPackage` : Next, you need to change the `MainActivity` of your app to register `ReactNativeDialogsPackage` :
```java ```java
import android.support.v4.app.FragmentActivity;
import com.aakashns.reactnativedialogs.ReactNativeDialogsPackage; import com.aakashns.reactnativedialogs.ReactNativeDialogsPackage;
public class MainActivity extends FragmentActivity implements DefaultHardwareBackBtnHandler { public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
//... //...
mReactInstanceManager = ReactInstanceManager.builder() mReactInstanceManager = ReactInstanceManager.builder()
@ -194,4 +193,3 @@ TODO
Upcoming Features Upcoming Features
------- -------
TODO TODO

View File

@ -1,6 +1,6 @@
package com.aakashns.reactnativedialogs; package com.aakashns.reactnativedialogs;
import android.support.v4.app.FragmentActivity; import android.app.Activity;
import com.aakashns.reactnativedialogs.modules.DialogAndroid; import com.aakashns.reactnativedialogs.modules.DialogAndroid;
import com.facebook.react.ReactPackage; import com.facebook.react.ReactPackage;
@ -13,10 +13,10 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ReactNativeDialogsPackage implements ReactPackage { public class ReactNativeDialogsPackage implements ReactPackage {
FragmentActivity mActivity; Activity mActivity;
public ReactNativeDialogsPackage(FragmentActivity fragmentActivity) { public ReactNativeDialogsPackage(Activity activity) {
mActivity = fragmentActivity; mActivity = activity;
} }
@Override @Override

View File

@ -1,7 +1,7 @@
package com.aakashns.reactnativedialogs.modules; package com.aakashns.reactnativedialogs.modules;
import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v4.app.FragmentActivity;
import android.view.View; import android.view.View;
import com.afollestad.materialdialogs.DialogAction; import com.afollestad.materialdialogs.DialogAction;
@ -23,13 +23,13 @@ public class DialogAndroid extends ReactContextBaseJavaModule {
return "DialogAndroid"; return "DialogAndroid";
} }
FragmentActivity mActivity; Activity mActivity;
public DialogAndroid( public DialogAndroid(
ReactApplicationContext reactContext, ReactApplicationContext reactContext,
FragmentActivity fragmentActivity) { Activity activity) {
super(reactContext); super(reactContext);
mActivity = fragmentActivity; mActivity = activity;
} }
/* Apply the options to the provided builder */ /* Apply the options to the provided builder */