bluelinelabs / bluelinelabs/Conductor
Help with child controller custom back handling
- Dominant language
- Java
- Stars
- 3.9k
- Forks
- 338
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I have a drawer layout, (whole screen is a controller), where drawer has its own backstack, and content (the view under drawer when it is opened) has also its own backstack; so two child routers
**When drawer is opened, I want to handle the drawer router back clicks; if not, then the content's**
Mind you the first controller placed in the drawer router has handleBack overriden with
`override fun handleBack() = false`. Which in my mind reads I dont wanna handle back at all, just pass it through
What I want is:
_When I press back when the drawer is opened, that means I should pop that drawer router; and when there is only one controller left on drawer router, just close the drawer_
So the the back implementation in the root controller is like this:
```
override fun handleBack(): Boolean {
if (drawerLayout.isDrawerOpen()) {
if (!drawerRouter.handleBack()) {
drawerLayout.closeDrawer()
}
return true
} else {
if (contentRouter.handleBack()) {
return true
}
}
return false
}
```
However this has a bug, where if there is only 1 controller in the drawer router, because of this Conductor code
```
class Controller ....
@UiThread
public boolean handleBack() {
ThreadUtils.ensureMainThread();
if (!backstack.isEmpty()) {
//noinspection ConstantConditions
if (backstack.peek().controller.handleBack()) {
return true;
} else if (popCurrentController()) { <-------- THIS
return true;
}
}
return false;
}
```
tldr;
When there is only one, the expected would be to have its handleBack called; which in my case always returns false, and therefore it should pass through to the root controller, which would return hardcoded true in this case, thuss stopping the back press handling; with nothing actually happening (besides the drawer closing)
However the THIS line shows it gets popped, thuss calling its onDestroy, which is not what I want. I would not expect it to get popped if I return false from its handleBack. Another interesting fact is that the controller's view stays in layout, and then when another controller is placed onto drawer router, I can see 2 overlapping controllers (bug)
Contributor guide
Assessment
This issue has not been assessed yet.