Skip to content

Commit 9bb0102

Browse files
authored
Merge pull request #191 from deepueg/add-null-check-and-util
Add null check and util
2 parents 523eee3 + 8c87f71 commit 9bb0102

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

android/lib/src/androidTest/java/com/ern/api/impl/SampleActivity.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ public class SampleActivity extends ElectrodeBaseActivity {
2525
public JSONObject finishFlowPayload;
2626

2727
@Override
28-
protected void onCreate(Bundle savedInstanceState) {
29-
super.onCreate(savedInstanceState);
28+
protected void preRootComponentRender() {
3029
ElectrodeReactContainer.initialize(getApplication(), new ElectrodeReactContainer.Config());
3130
}
3231

android/lib/src/main/java/com/ern/api/impl/core/ElectrodeBaseActivityDelegate.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.ern.api.impl.core;
22

3+
import android.content.Intent;
34
import android.os.Bundle;
45
import android.view.MenuItem;
56

@@ -74,14 +75,18 @@ public void onStart() {
7475
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
7576
@Override
7677
public void onResume() {
77-
super.onResume();
78+
if (getReactNativeHost() != null) {
79+
super.onResume();
80+
}
7881
Logger.v(TAG, "onResume()");
7982
}
8083

8184
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
8285
@Override
8386
public void onPause() {
84-
super.onPause();
87+
if (getReactNativeHost() != null) {
88+
super.onPause();
89+
}
8590
Logger.v(TAG, "onPause()");
8691
}
8792

@@ -94,7 +99,9 @@ public void onStop() {
9499
@Override
95100
public void onDestroy() {
96101
mFragmentActivity = null;
97-
super.onDestroy();
102+
if (getReactNativeHost() != null) {
103+
super.onDestroy();
104+
}
98105
Logger.v(TAG, "onDestroy()");
99106
}
100107

@@ -106,6 +113,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
106113
return false;
107114
}
108115

116+
@Override
117+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
118+
if (getReactNativeHost() != null) {
119+
super.onActivityResult(requestCode, resultCode, data);
120+
}
121+
}
122+
109123
@Override
110124
public boolean onBackPressed() {
111125
if (mDefaultLaunchConfig.isRootBackPressHandledByRN() && mFragmentActivity.getOnBackPressedDispatcher().hasEnabledCallbacks()) {
@@ -197,9 +211,9 @@ private void switchToFragment(@NonNull Fragment fragment, @NonNull LaunchConfig
197211
* @param transaction {@link FragmentTransaction} used for the current fragment transaction
198212
*/
199213
protected void manageTransition(@NonNull FragmentTransaction transaction) {
200-
if(mDefaultLaunchConfig.navigationTransition == LaunchConfig.TRANSITION.FADE) {
214+
if (mDefaultLaunchConfig.navigationTransition == LaunchConfig.TRANSITION.FADE) {
201215
AnimUtil.fade(transaction);
202-
} else if(mDefaultLaunchConfig.navigationTransition == LaunchConfig.TRANSITION.SLIDE) {
216+
} else if (mDefaultLaunchConfig.navigationTransition == LaunchConfig.TRANSITION.SLIDE) {
203217
AnimUtil.slide(transaction);
204218
}
205219
}

android/lib/src/main/java/com/ern/api/impl/navigation/ElectrodeBaseActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ private NavigationLaunchConfig createNavLaunchConfigInternal() {
145145
@CallSuper
146146
protected void onCreate(Bundle savedInstanceState) {
147147
super.onCreate(savedInstanceState);
148+
preRootComponentRender();
148149
if (mainLayout() != NONE) {
149150
setContentView(mainLayout());
150151
}
@@ -156,6 +157,14 @@ protected void onCreate(Bundle savedInstanceState) {
156157
setupNavBar();
157158
}
158159

160+
/**
161+
* Override this to perform any action that needs to be performed before the root component is first rendered.
162+
* Some apps might only choose to initialize the container inside an activity. This method can act as a helper method for them to perform init.
163+
*/
164+
protected void preRootComponentRender() {
165+
// Do nothing here, override if needed.
166+
}
167+
159168
@Override
160169
protected void onDestroy() {
161170
super.onDestroy();

0 commit comments

Comments
 (0)