Skip to content

Commit

Permalink
Merge pull request #191 from deepueg/add-null-check-and-util
Browse files Browse the repository at this point in the history
Add null check and util
  • Loading branch information
deepueg authored Aug 20, 2021
2 parents 523eee3 + 8c87f71 commit 9bb0102
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ public class SampleActivity extends ElectrodeBaseActivity {
public JSONObject finishFlowPayload;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
protected void preRootComponentRender() {
ElectrodeReactContainer.initialize(getApplication(), new ElectrodeReactContainer.Config());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ern.api.impl.core;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

Expand Down Expand Up @@ -74,14 +75,18 @@ public void onStart() {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
@Override
public void onResume() {
super.onResume();
if (getReactNativeHost() != null) {
super.onResume();
}
Logger.v(TAG, "onResume()");
}

@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
@Override
public void onPause() {
super.onPause();
if (getReactNativeHost() != null) {
super.onPause();
}
Logger.v(TAG, "onPause()");
}

Expand All @@ -94,7 +99,9 @@ public void onStop() {
@Override
public void onDestroy() {
mFragmentActivity = null;
super.onDestroy();
if (getReactNativeHost() != null) {
super.onDestroy();
}
Logger.v(TAG, "onDestroy()");
}

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

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (getReactNativeHost() != null) {
super.onActivityResult(requestCode, resultCode, data);
}
}

@Override
public boolean onBackPressed() {
if (mDefaultLaunchConfig.isRootBackPressHandledByRN() && mFragmentActivity.getOnBackPressedDispatcher().hasEnabledCallbacks()) {
Expand Down Expand Up @@ -197,9 +211,9 @@ private void switchToFragment(@NonNull Fragment fragment, @NonNull LaunchConfig
* @param transaction {@link FragmentTransaction} used for the current fragment transaction
*/
protected void manageTransition(@NonNull FragmentTransaction transaction) {
if(mDefaultLaunchConfig.navigationTransition == LaunchConfig.TRANSITION.FADE) {
if (mDefaultLaunchConfig.navigationTransition == LaunchConfig.TRANSITION.FADE) {
AnimUtil.fade(transaction);
} else if(mDefaultLaunchConfig.navigationTransition == LaunchConfig.TRANSITION.SLIDE) {
} else if (mDefaultLaunchConfig.navigationTransition == LaunchConfig.TRANSITION.SLIDE) {
AnimUtil.slide(transaction);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ private NavigationLaunchConfig createNavLaunchConfigInternal() {
@CallSuper
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
preRootComponentRender();
if (mainLayout() != NONE) {
setContentView(mainLayout());
}
Expand All @@ -156,6 +157,14 @@ protected void onCreate(Bundle savedInstanceState) {
setupNavBar();
}

/**
* Override this to perform any action that needs to be performed before the root component is first rendered.
* 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.
*/
protected void preRootComponentRender() {
// Do nothing here, override if needed.
}

@Override
protected void onDestroy() {
super.onDestroy();
Expand Down

0 comments on commit 9bb0102

Please sign in to comment.