Skip to content

Commit c296f3c

Browse files
committed
Fix waitForPopped condition
1 parent 080692e commit c296f3c

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

compose/ui/ui/src/uikitInstrumentedTest/kotlin/androidx/compose/ui/interop/UIKitNavigationSwipeBackTest.kt

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,13 @@ internal abstract class UIKitNavigationSwipeBackTest(
105105

106106
@Test
107107
fun testSwipeRightFromEdgePopsController() = runUIKitInstrumentedTest {
108-
setNavigationControllerContent {
108+
val viewControllerHostingCompose = setNavigationControllerContent {
109109
TestContent(currentPage = mutableIntStateOf(1))
110110
}
111111

112112
swipeRightFromEdge()
113113

114-
waitUntil("Waiting for view controller to be popped") {
115-
navigationController.viewControllers.size == 1
116-
}
114+
waitForPopped(viewControllerHostingCompose)
117115
}
118116

119117
@Test
@@ -148,15 +146,13 @@ internal abstract class UIKitNavigationSwipeBackTest(
148146
val initialPage = 1
149147
val currentPage = mutableIntStateOf(initialPage)
150148

151-
setNavigationControllerContent {
149+
val viewControllerHostingCompose = setNavigationControllerContent {
152150
TestContent(currentPage = currentPage)
153151
}
154152

155153
findNodeWithTag("outsideBox").swipeRight()
156154

157-
waitUntil("Waiting for view controller to be popped") {
158-
navigationController.viewControllers.size == 1
159-
}
155+
waitForPopped(viewControllerHostingCompose)
160156
}
161157

162158
@Test
@@ -167,15 +163,13 @@ internal abstract class UIKitNavigationSwipeBackTest(
167163
val initialPage = 1
168164
val currentPage = mutableIntStateOf(initialPage)
169165

170-
setNavigationControllerContent {
166+
val viewControllerHostingCompose = setNavigationControllerContent {
171167
TestContent(currentPage = currentPage)
172168
}
173169

174170
swipeRightFromEdge()
175171

176-
waitUntil("Waiting for view controller to be popped") {
177-
navigationController.viewControllers.size == 1
178-
}
172+
waitForPopped(viewControllerHostingCompose)
179173
}
180174

181175
@Test
@@ -186,7 +180,7 @@ internal abstract class UIKitNavigationSwipeBackTest(
186180
val initialPage = 1
187181
val currentPage = mutableIntStateOf(initialPage)
188182

189-
setNavigationControllerContent {
183+
val viewControllerHostingCompose = setNavigationControllerContent {
190184
TestContent(currentPage = currentPage)
191185
}
192186

@@ -195,11 +189,7 @@ internal abstract class UIKitNavigationSwipeBackTest(
195189
toPosition = { rightCenter() },
196190
)
197191

198-
waitForIdle()
199-
200-
waitUntil("Waiting for view controller to be popped") {
201-
navigationController.viewControllers.size == 1
202-
}
192+
waitForPopped(viewControllerHostingCompose)
203193
}
204194

205195
private val UIKitInstrumentedTest.navigationController: UINavigationController get() {
@@ -208,17 +198,28 @@ internal abstract class UIKitNavigationSwipeBackTest(
208198

209199
private fun UIKitInstrumentedTest.setNavigationControllerContent(
210200
content: @Composable () -> Unit = {}
211-
) {
212-
val composeViewController = createViewControllerHostingCompose(content = content)
201+
): UIViewController {
202+
val viewControllerHostingCompose = createViewControllerHostingCompose(content = content)
213203

214204
setupWindow {
215205
UINavigationController().also {
216-
it.setViewControllers(listOf(UIViewController(), composeViewController), false)
206+
it.setViewControllers(listOf(UIViewController(), viewControllerHostingCompose), false)
217207
}
218208
}
219209

220210
waitUntil {
221-
composeViewController.view.window != null
211+
viewControllerHostingCompose.view.window != null
212+
}
213+
214+
return viewControllerHostingCompose
215+
}
216+
217+
private fun UIKitInstrumentedTest.waitForPopped(
218+
viewController: UIViewController
219+
) {
220+
waitUntil("Waiting for view controller to be popped and detached") {
221+
navigationController.viewControllers.size == 1 &&
222+
viewController.view.window == null
222223
}
223224
}
224225

compose/ui/ui/src/uikitInstrumentedTest/kotlin/androidx/compose/ui/test/UIKitInstrumentedTest.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ internal class UIKitInstrumentedTest(
390390
waitUntil(
391391
conditionDescription = "waitForIdle: timeout ${timeoutMillis}ms reached.",
392392
timeoutMillis = timeoutMillis
393-
) { isIdle }
393+
) {
394+
clearComposeContainerReferencesIfDetached()
395+
isIdle
396+
}
394397
}
395398

396399
fun delay(timeoutMillis: Long) = UIKitInstrumentedTest.delay(timeoutMillis)

0 commit comments

Comments
 (0)