Fix mounting nested fragments in the same transaction

This commit is contained in:
Krzysztof Magiera
2018-08-21 11:02:39 +02:00
parent 3743eb2a22
commit 70c022c628
5 changed files with 41 additions and 5 deletions

View File

@@ -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();

View File

@@ -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;