Skip to content

Commit 9bc16f2

Browse files
committed
Detach children before self
1 parent 85cf3b3 commit 9bc16f2

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

android/libraries/rib-base/src/main/kotlin/com/uber/rib/core/Router.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ protected constructor(
206206
public open fun dispatchDetach() {
207207
checkForMainThread()
208208

209-
interactorGeneric.dispatchDetach()
210209
willDetach()
211210
for (child in children) {
212211
detachChild(child)
213212
}
213+
interactorGeneric.dispatchDetach()
214214
}
215215

216216
/**

android/libraries/rib-base/src/test/kotlin/com/uber/rib/core/InteractorAndRouterTest.kt

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,23 @@ class InteractorAndRouterTest {
9797
router.dispatchDetach()
9898

9999
// Then.
100-
val ribActionInfoValues = ribActionInfoObserver.values()
101-
ribActionInfoValues
102-
.last()
103-
.assertRibActionInfo(
104-
RibEventType.DETACHED,
105-
RibActionEmitterType.ROUTER,
106-
RibActionState.COMPLETED,
107-
"com.uber.rib.core.FakeRouter",
108-
)
109100
verify(childInteractor).dispatchDetach()
101+
val ribActionInfoValues = ribActionInfoObserver.values()
102+
val childRouterDetachIndex =
103+
ribActionInfoValues.indexOfFirst {
104+
it.ribEventType == RibEventType.DETACHED &&
105+
it.ribActionEmitterType == RibActionEmitterType.ROUTER &&
106+
it.ribActionState == RibActionState.COMPLETED
107+
}
108+
val selfInteractorDetachIndex =
109+
ribActionInfoValues.indexOfFirst {
110+
it.ribEventType == RibEventType.DETACHED &&
111+
it.ribActionEmitterType == RibActionEmitterType.INTERACTOR &&
112+
it.ribActionState == RibActionState.COMPLETED
113+
}
114+
assertThat(selfInteractorDetachIndex).isGreaterThan(-1)
115+
assertThat(childRouterDetachIndex).isGreaterThan(-1)
116+
assertThat(selfInteractorDetachIndex > childRouterDetachIndex).isTrue()
110117
}
111118

112119
@Test

0 commit comments

Comments
 (0)