Skip to content

Commit

Permalink
Merge pull request #570 from kosenda/feature/improved-map-usability
Browse files Browse the repository at this point in the history
Added drag gesture and crossfade in EventMapTab
  • Loading branch information
takahirom authored Aug 18, 2024
2 parents 64cffc7 + b94ccd1 commit fb8f35f
Showing 1 changed file with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package io.github.droidkaigi.confsched.eventmap.component

import androidx.compose.animation.Crossfade
import androidx.compose.foundation.Image
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.draggable
import androidx.compose.foundation.gestures.rememberDraggableState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -31,6 +35,7 @@ import org.jetbrains.compose.resources.painterResource

const val EventMapTabTestTagPrefix = "EventMapTabTestTag:"
const val EventMapTabImageTestTag = "EventMapTabImageTestTag"
private const val ChangeTabDeltaThreshold = 20f

@Composable
fun EventMapTab(
Expand All @@ -40,7 +45,17 @@ fun EventMapTab(
var selectedTabIndex by rememberSaveable { mutableStateOf(0) }

Column(
modifier = modifier,
modifier = modifier.draggable(
orientation = Orientation.Horizontal,
state = rememberDraggableState { delta ->
if (selectedTabIndex == 0 && delta > ChangeTabDeltaThreshold) {
selectedTabIndex = 1
}
if (selectedTabIndex == 1 && delta < -ChangeTabDeltaThreshold) {
selectedTabIndex = 0
}
},
),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.Start,
) {
Expand Down Expand Up @@ -92,21 +107,23 @@ fun EventMapTab(
},
)
Spacer(modifier = Modifier.height(24.dp))
val mapRes = if (selectedTabIndex == 0) {
Res.drawable.event_map_1f
} else {
Res.drawable.event_map_b1f
Crossfade(targetState = selectedTabIndex) { index ->
val mapRes = if (index == 0) {
Res.drawable.event_map_1f
} else {
Res.drawable.event_map_b1f
}
val mapContentDescription = if (index == 0) {
FloorLevel.Ground.floorName
} else {
FloorLevel.Basement.floorName
}
Image(
modifier = Modifier.testTag(EventMapTabImageTestTag),
painter = painterResource(mapRes),
contentDescription = "Map of $mapContentDescription",
)
}
val mapContentDescription = if (selectedTabIndex == 0) {
FloorLevel.Ground.floorName
} else {
FloorLevel.Basement.floorName
}
Image(
modifier = Modifier.testTag(EventMapTabImageTestTag),
painter = painterResource(mapRes),
contentDescription = "Map of $mapContentDescription",
)
}
}

Expand Down

0 comments on commit fb8f35f

Please sign in to comment.