Vivian Thayil
09/06/2022, 5:52 PMAtaul Munim
09/06/2022, 9:57 PMyschimke
09/06/2022, 10:14 PMVivian Thayil
09/08/2022, 2:54 PMVivian Thayil
09/08/2022, 2:56 PMAtaul Munim
09/08/2022, 2:57 PMVivian Thayil
09/08/2022, 3:19 PMyschimke
09/08/2022, 3:58 PMAtaul Munim
09/08/2022, 3:59 PMyschimke
09/08/2022, 3:59 PMLimits swipe to dismiss to be active from the edge of the viewport only. Used when the center of the screen needs to be able to handle horizontal paging, such as 2-d scrolling a Map or swiping horizontally between pages. Swipe to the right is intercepted on the left part of the viewport with width specified by, with other touch events ignored - vertical scroll, click, long click, etc.edgeWidth
yschimke
09/08/2022, 4:00 PMyschimke
09/08/2022, 4:04 PMVivian Thayil
09/13/2022, 1:15 PMAtaul Munim
09/13/2022, 1:22 PMAtaul Munim
09/13/2022, 4:48 PM@Composable
fun WearApp() {
val boxState = rememberSwipeToDismissBoxState()
val navController = rememberSwipeDismissableNavController()
val navHostState = rememberSwipeDismissableNavHostState(boxState)
EdgeSwipeTheme {
SwipeDismissableNavHost(
navController = navController,
startDestination = SCREEN_HOME,
state = navHostState
) {
// start screen - can navigate to settings/active_exercise
composable(SCREEN_HOME) {
Home(
onClickActiveExercise = {
navController.navigate(SCREEN_ACTIVE_EXERCISE)
},
onClickSettings = {
navController.navigate(SCREEN_SETTINGS)
}
)
}
// can swipe back to home
composable(SCREEN_SETTINGS) {
Settings()
}
// has a horizontal viewpager, CANNOT swipe back to home
composable(SCREEN_ACTIVE_EXERCISE) {
ActiveExercise(boxState)
}
}
}
}
Ataul Munim
09/13/2022, 4:48 PMedgeSwipeToDismiss
modifier on the composable which supports horizontal swiping. In your case it'll be the paging composable. Note the 0.dp
as the second parameter.
@Composable
private fun ActiveExercise(
boxState: SwipeToDismissBoxState
) {
val scrollState = rememberScrollState()
Row(
modifier = Modifier
.edgeSwipeToDismiss(boxState, 0.dp)
.horizontalScroll(scrollState)
.fillMaxHeight()
.background(MaterialTheme.colors.background),
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier.width(100.dp),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
text = SCREEN_ACTIVE_EXERCISE
)
Text(
modifier = Modifier.width(100.dp),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
text = SCREEN_ACTIVE_EXERCISE
)
Text(
modifier = Modifier.width(100.dp),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
text = SCREEN_ACTIVE_EXERCISE
)
}
}
Ataul Munim
09/13/2022, 4:48 PM@Composable
private fun Settings() {
Column(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colors.background),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
text = SCREEN_SETTINGS
)
}
}
@Composable
private fun Home(
onClickActiveExercise: () -> Unit,
onClickSettings: () -> Unit,
) {
Column(
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colors.background),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
text = SCREEN_HOME
)
Button(onClick = onClickActiveExercise) {
Text(text = SCREEN_ACTIVE_EXERCISE)
}
Button(onClickSettings) {
Text(text = SCREEN_SETTINGS)
}
}
}
private const val SCREEN_HOME = "screen_home"
private const val SCREEN_SETTINGS = "screen_settings"
private const val SCREEN_ACTIVE_EXERCISE = "screen_active_exercise"
Ataul Munim
09/13/2022, 4:49 PMedgeSwipeToDismiss
modifier, it effectively disables swipe to dismiss.