Skip to content

Commit

Permalink
Fix detaching views rendered under header config component. (#282)
Browse files Browse the repository at this point in the history
This change fixes the problem when header update would get triggered while the header config subviews are not yet fully unmounted. The root cause of this problem is kind of a mystery, I encouneter a crash when going back using back button from a screen that have custom back button image rendered. Turned out that after implementing removeAll schema the problem no longer occurs. I didn't have enough time to investigate it further but supporting removeAll schema is an improvement regardless so going with this solution for now.
  • Loading branch information
kmagiera authored Jan 14, 2020
1 parent 28f5724 commit 1ac7426
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ protected void removeScreenAt(int index) {
markUpdated();
}

protected void removeAllScreens() {
for (int i = 0, size = mScreenFragments.size(); i < size; i++) {
mScreenFragments.get(i).getScreen().setContainer(null);
}
mScreenFragments.clear();
markUpdated();
}

@Override
public void startViewTransition(View view) {
super.startViewTransition(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public void removeViewAt(ScreenContainer parent, int index) {
parent.removeScreenAt(index);
}

@Override
public void removeAllViews(ScreenContainer parent) {
parent.removeAllScreens();
}

@Override
public int getChildCount(ScreenContainer parent) {
return parent.getScreenCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ protected void removeScreenAt(int index) {
super.removeScreenAt(index);
}

@Override
protected void removeAllScreens() {
mDismissed.clear();
super.removeAllScreens();
}

@Override
protected boolean hasScreen(ScreenFragment screenFragment) {
return super.hasScreen(screenFragment) && !mDismissed.contains(screenFragment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public void removeConfigSubview(int index) {
maybeUpdate();
}

public void removeAllConfigSubviews() {
mConfigSubviews.clear();
maybeUpdate();
}

public void addConfigSubview(ScreenStackHeaderSubview child, int index) {
mConfigSubviews.add(index, child);
maybeUpdate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public void addView(ScreenStackHeaderConfig parent, View child, int index) {
parent.addConfigSubview((ScreenStackHeaderSubview) child, index);
}

@Override
public void removeAllViews(ScreenStackHeaderConfig parent) {
parent.removeAllConfigSubviews();
}

@Override
public void removeViewAt(ScreenStackHeaderConfig parent, int index) {
parent.removeConfigSubview(index);
Expand Down

0 comments on commit 1ac7426

Please sign in to comment.