rsktash
01/24/2021, 11:20 AMArkadii Ivanov
01/24/2021, 11:29 AMHow can I pass router to api service?There is not enough context to answer precisely, but you can pass Router via constructor of the
api service
. Just as normal object. But it may result in coupling. Maybe you can listen for api errors in the root/parant component (owner of the Router)?
The Router
has method Router.navigate
. You can supply any stack you want. E.g. Router.navigate { listOf(Configuration.Login} }
, will destroy the current stack and navigate to the Login screen. If the Login screen is already in the back stack, it will be resumed. If not, it will be created.rsktash
01/24/2021, 11:31 AMArkadii Ivanov
01/24/2021, 11:32 AMrsktash
01/24/2021, 11:34 AMArkadii Ivanov
01/24/2021, 11:38 AMrsktash
01/24/2021, 11:39 AMArkadii Ivanov
01/24/2021, 11:42 AMrsktash
01/24/2021, 11:52 AMArkadii Ivanov
01/24/2021, 12:44 PMComponentContext
extension. Decompose is quite flexible, so I came up with a solution. Would be nice if you try and provide your feedback in the issue.rsktash
01/24/2021, 1:56 PMArkadii Ivanov
01/24/2021, 2:01 PMrsktash
01/24/2021, 2:04 PMArkadii Ivanov
01/24/2021, 2:08 PMrsktash
01/24/2021, 2:09 PMArkadii Ivanov
01/24/2021, 2:11 PMrsktash
01/24/2021, 2:12 PMArkadii Ivanov
01/24/2021, 2:15 PMrsktash
01/24/2021, 2:18 PMArkadii Ivanov
01/24/2021, 2:20 PMrsktash
01/25/2021, 1:47 PMArkadii Ivanov
01/25/2021, 1:49 PMrsktash
01/25/2021, 1:50 PMArkadii Ivanov
01/25/2021, 1:56 PMDetails
responsibility ends once Back button is clicked in the appbar. It is Root's responsibility to navigate back.rsktash
01/25/2021, 1:59 PMArkadii Ivanov
01/25/2021, 2:08 PMBackPressedDispatcher
in your child component. Normally children should not be aware of the navigation logic. Navigation logic should be Parent's responsibility. Children should only tell Parents when they are finished, so the Parent can decide what to do (e.g. execute Router.pop()
). But if you really want, you can call backPressedDispatcher.onBackPressed()
in a Component.rsktash
01/25/2021, 2:11 PMArkadii Ivanov
01/25/2021, 2:16 PMrsktash
01/25/2021, 2:24 PMArkadii Ivanov
01/25/2021, 2:28 PMBackPressedDispatcher
and to the AppBar Back button. In both cases it should show a dialog and once confirmed, the Child component could emit an Output.Finished
(or just call a callback passed via constructor, whatever you prefer).BackPressedDispatcher
in this case.rsktash
01/25/2021, 2:42 PMArkadii Ivanov
01/25/2021, 2:46 PMregister
method. And don't forget to unregister at the end of lifecycle. You should return true
in onBackPressed
method, so the back navigation is blocked at this point.rsktash
01/25/2021, 2:47 PMArkadii Ivanov
01/25/2021, 2:47 PMrsktash
01/25/2021, 2:56 PMlifecycle.doOnCreate { }
Arkadii Ivanov
01/25/2021, 2:56 PMlifecycle.subscribe(onCreate=, onDestroy=)
rsktash
01/25/2021, 2:57 PMArkadii Ivanov
01/25/2021, 2:58 PMbinder
, which handles the lifecyclersktash
01/26/2021, 8:23 AMArkadii Ivanov
01/26/2021, 10:08 AM