Skip to content

Commit

Permalink
[Android] Bottom tab not update (#275)
Browse files Browse the repository at this point in the history
Fixes #259

Issue
Screen doesn't update when switching between tabs.

Problem
When ScreenContainer re-added. mFragmentManager is destroyed.
  • Loading branch information
r0b0t3d authored and osdnk committed Jan 11, 2020
1 parent 2b1b726 commit ca6319d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
14 changes: 14 additions & 0 deletions android/src/main/java/com/swmansion/rnscreens/ScreenContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,24 @@ protected boolean hasScreen(ScreenFragment screenFragment) {
return mScreenFragments.contains(screenFragment);
}

protected void ensureFragmentManager() {
if (mFragmentManager != null && mFragmentManager.isDestroyed()) {
// When fragmentManager is destroyed, try to remove current fragment's views
for (int i = 0, size = mScreenFragments.size(); i < size; i++) {
ScreenFragment screenFragment = mScreenFragments.get(i);
removeView(screenFragment.getScreenRootView());
}
mFragmentManager = null;
mActiveScreenFragments.clear();
mNeedUpdate = true;
}
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
mIsAttached = true;
ensureFragmentManager();
updateIfNeeded();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.swmansion.rnscreens;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

Expand Down Expand Up @@ -33,6 +35,10 @@ public View onCreateView(LayoutInflater inflater,
return mScreenView;
}

protected ViewGroup getScreenRootView() {
return mScreenView;
}

public Screen getScreen() {
return mScreenView;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public View onCreateView(LayoutInflater inflater,
return mScreenRootView;
}

@Override
protected ViewGroup getScreenRootView() {
return mScreenRootView;
}

public boolean isDismissable() {
View child = mScreenView.getChildAt(0);
if (child instanceof ScreenStackHeaderConfig) {
Expand Down

0 comments on commit ca6319d

Please sign in to comment.