mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-10 17:23:42 +08:00
Fix mounting nested fragments in the same transaction
This commit is contained in:
@@ -60,6 +60,9 @@ public class Screen extends ViewGroup {
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
if (active == mActive) {
|
||||
return;
|
||||
}
|
||||
mActive = active;
|
||||
if (mContainer != null) {
|
||||
mContainer.notifyChildUpdate();
|
||||
|
||||
@@ -26,6 +26,7 @@ public class ScreenContainer extends ViewGroup {
|
||||
|
||||
private @Nullable FragmentTransaction mCurrentTransaction;
|
||||
private boolean mNeedUpdate;
|
||||
private boolean mIsAttached;
|
||||
|
||||
private ChoreographerCompat.FrameCallback mFrameCallback = new ChoreographerCompat.FrameCallback() {
|
||||
@Override
|
||||
@@ -95,7 +96,7 @@ public class ScreenContainer extends ViewGroup {
|
||||
|
||||
private void tryCommitTransaction() {
|
||||
if (mCurrentTransaction != null) {
|
||||
mCurrentTransaction.commitNow();
|
||||
mCurrentTransaction.commit();
|
||||
mCurrentTransaction = null;
|
||||
}
|
||||
}
|
||||
@@ -121,8 +122,21 @@ public class ScreenContainer extends ViewGroup {
|
||||
return screen.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
mIsAttached = true;
|
||||
updateIfNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow();
|
||||
mIsAttached = false;
|
||||
}
|
||||
|
||||
private void updateIfNeeded() {
|
||||
if (!mNeedUpdate || mFragmentManager.isDestroyed()) {
|
||||
if (!mNeedUpdate || mFragmentManager.isDestroyed() || !mIsAttached) {
|
||||
return;
|
||||
}
|
||||
mNeedUpdate = false;
|
||||
|
||||
Reference in New Issue
Block a user