[Android] Bottom tab not update (#275)

Fixes #259

Issue
Screen doesn't update when switching between tabs.

Problem
When ScreenContainer re-added. mFragmentManager is destroyed.
This commit is contained in:
Tuan Luong
2020-01-11 22:36:28 +07:00
committed by Michał Osadnik
parent 2b1b726723
commit ca6319d26e
3 changed files with 25 additions and 0 deletions

View File

@@ -235,10 +235,24 @@ public class ScreenContainer<T extends ScreenFragment> extends ViewGroup {
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();
}

View File

@@ -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;
@@ -33,6 +35,10 @@ public class ScreenFragment extends Fragment {
return mScreenView;
}
protected ViewGroup getScreenRootView() {
return mScreenView;
}
public Screen getScreen() {
return mScreenView;
}

View File

@@ -96,6 +96,11 @@ public class ScreenStackFragment extends ScreenFragment {
return mScreenRootView;
}
@Override
protected ViewGroup getScreenRootView() {
return mScreenRootView;
}
public boolean isDismissable() {
View child = mScreenView.getChildAt(0);
if (child instanceof ScreenStackHeaderConfig) {