diff --git a/wear/compose/compose-navigation/src/androidTest/kotlin/androidx/wear/compose/navigation/SwipeDismissableNavHostTest.kt b/wear/compose/compose-navigation/src/androidTest/kotlin/androidx/wear/compose/navigation/SwipeDismissableNavHostTest.kt index 360df14460c7f..64a5666e437d2 100644 --- a/wear/compose/compose-navigation/src/androidTest/kotlin/androidx/wear/compose/navigation/SwipeDismissableNavHostTest.kt +++ b/wear/compose/compose-navigation/src/androidTest/kotlin/androidx/wear/compose/navigation/SwipeDismissableNavHostTest.kt @@ -19,6 +19,7 @@ import androidx.activity.OnBackPressedDispatcher import androidx.activity.OnBackPressedDispatcherOwner import androidx.activity.compose.LocalOnBackPressedDispatcherOwner import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding @@ -94,7 +95,7 @@ class SwipeDismissableNavHostTest { // Click to move to next destination then swipe to dismiss. rule.onNodeWithText(START).performClick() - rule.onNodeWithTag(TEST_TAG).performTouchInput({ swipeRight() }) + rule.onNodeWithTag(TEST_TAG).performTouchInput { swipeRight() } // Should now display "start". rule.onNodeWithText(START).assertExists() @@ -195,23 +196,28 @@ class SwipeDismissableNavHostTest { composable(START) { screenId.value = START var toggle by rememberSaveable { mutableStateOf(false) } - Column { - ToggleButton( - checked = toggle, - onCheckedChange = { - toggle = !toggle - }, - content = { Text(text = if (toggle) "On" else "Off") }, - modifier = Modifier.testTag("ToggleButton"), - ) - Button( - onClick = { navController.navigate(NEXT) }, - ) { - Text("Go") + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + Column { + ToggleButton( + checked = toggle, + onCheckedChange = { + toggle = !toggle + }, + content = { Text(text = if (toggle) "On" else "Off") }, + modifier = Modifier.testTag("ToggleButton"), + ) + Button( + onClick = { navController.navigate(NEXT) }, + ) { + Text("Go") + } } } } - composable("next") { + composable(NEXT) { screenId.value = NEXT CompactChip( onClick = {}, @@ -246,7 +252,9 @@ class SwipeDismissableNavHostTest { holder.SaveableStateProvider(START) { var toggle by rememberSaveable { mutableStateOf(false) } Column( - modifier = Modifier.fillMaxSize().padding(horizontal = 20.dp), + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 20.dp), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { @@ -271,7 +279,9 @@ class SwipeDismissableNavHostTest { holder.SaveableStateProvider(NEXT) { var counter by rememberSaveable { mutableStateOf(0) } Column( - modifier = Modifier.fillMaxSize().padding(horizontal = 20.dp), + modifier = Modifier + .fillMaxSize() + .padding(horizontal = 20.dp), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { @@ -448,13 +458,23 @@ class SwipeDismissableNavHostTest { userSwipeEnabled = userSwipeEnabled ) { composable(START) { - CompactChip( - onClick = { navController.navigate(NEXT) }, - label = { Text(text = START) } - ) + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + CompactChip( + onClick = { navController.navigate(NEXT) }, + label = { Text(text = START) } + ) + } } composable("next") { - Text(NEXT) + Box( + modifier = Modifier.fillMaxSize(), + contentAlignment = Alignment.Center + ) { + Text(NEXT) + } } } } diff --git a/wear/compose/integration-tests/macrobenchmark/src/main/java/androidx/wear/compose/integration/macrobenchmark/SwipeBenchmark.kt b/wear/compose/integration-tests/macrobenchmark/src/main/java/androidx/wear/compose/integration/macrobenchmark/SwipeBenchmark.kt index 7a523226ac7e4..dce428c07b9b0 100644 --- a/wear/compose/integration-tests/macrobenchmark/src/main/java/androidx/wear/compose/integration/macrobenchmark/SwipeBenchmark.kt +++ b/wear/compose/integration-tests/macrobenchmark/src/main/java/androidx/wear/compose/integration/macrobenchmark/SwipeBenchmark.kt @@ -66,7 +66,12 @@ class SwipeBenchmark( // Setting a gesture margin is important otherwise gesture nav is triggered. swipeToDismissBox.setGestureMargin(device.displayWidth / 5) repeat(3) { - swipeToDismissBox.swipe(Direction.RIGHT, 0.75f, SWIPE_SPEED) + swipeToDismissBox.swipe(Direction.RIGHT, 1f, SWIPE_SPEED) + // Sleeping the current thread for sometime before swiping again. This is required + // for cuttlefish_wear emulator as swipes are not completed when performed + // repeatedly. See b/328016250 for more details. + // TODO(b/329837878): Remove the sleep once infra improves + Thread.sleep(500) device.waitForIdle() } }