Skip to content

Commit

Permalink
Merge pull request #154 from canopas/sneh/fix-appearance-for-space-se…
Browse files Browse the repository at this point in the history
…lection-menu

Fix the spaceSelectionMenu appearance for map screen
  • Loading branch information
cp-sneh-s authored Jan 9, 2025
2 parents 9b0fe65 + b98ae75 commit 2169093
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fun HomeScreen(verifyingSpace: Boolean) {
modifier = Modifier
.padding(it)
) {
HomeScreenContent(navController)
HomeScreenContent(navController, viewModel::dismissSpaceSelection)

HomeTopBar(verifyingSpace)
}
Expand Down Expand Up @@ -207,13 +207,13 @@ private fun MapControl(

@OptIn(ExperimentalAnimationApi::class)
@Composable
fun HomeScreenContent(navController: NavHostController) {
fun HomeScreenContent(navController: NavHostController, dismissSpaceSelection: () -> Unit) {
NavHost(
navController = navController,
startDestination = AppDestinations.map.path
) {
tabComposable(AppDestinations.map.path) {
MapScreen()
MapScreen(dismissSpaceSelection)
}

tabComposable(AppDestinations.places.path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ class HomeScreenViewModel @Inject constructor(
_state.value.copy(showSpaceSelectionPopup = !state.value.showSpaceSelectionPopup)
}

fun dismissSpaceSelection() {
_state.value = _state.value.copy(showSpaceSelectionPopup = false)
}

fun navigateToCreateSpace() {
navigator.navigateTo(AppDestinations.createSpace.path)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private const val DEFAULT_CAMERA_ZOOM_FOR_SELECTED_USER = 17f

@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun MapScreen() {
fun MapScreen(dismissSpaceSelection: () -> Unit) {
val viewModel = hiltViewModel<MapViewModel>()
val state by viewModel.state.collectAsState()
val scope = rememberCoroutineScope()
Expand Down Expand Up @@ -136,7 +136,7 @@ fun MapScreen() {
}

Box(modifier = Modifier.fillMaxSize()) {
MapView(cameraPositionState)
MapView(cameraPositionState, dismissSpaceSelection)

Column(
modifier = Modifier
Expand All @@ -145,6 +145,7 @@ fun MapScreen() {
) {
Column(modifier = Modifier.align(Alignment.End)) {
MapControlBtn(icon = R.drawable.ic_map_type) {
dismissSpaceSelection()
viewModel.toggleStyleSheetVisibility(true)
}

Expand All @@ -153,6 +154,7 @@ fun MapScreen() {
show = relocate
) {
scope.launch {
dismissSpaceSelection()
if (state.isMapLoaded) {
cameraPositionState.animate(
CameraUpdateFactory.newLatLngZoom(
Expand All @@ -169,6 +171,7 @@ fun MapScreen() {
containerColor = AppTheme.colorScheme.primary,
contentColor = AppTheme.colorScheme.textInversePrimary
) {
dismissSpaceSelection()
viewModel.navigateToPlaces()
}
}
Expand Down Expand Up @@ -212,6 +215,7 @@ fun MapScreen() {
}
items(state.members) {
MapUserItem(it) {
dismissSpaceSelection()
viewModel.showMemberDetail(it)
}
}
Expand Down Expand Up @@ -330,7 +334,8 @@ fun PermissionFooter(onClick: () -> Unit) {

@Composable
private fun MapView(
cameraPositionState: CameraPositionState
cameraPositionState: CameraPositionState,
dismissSpaceSelection: () -> Unit
) {
val viewModel = hiltViewModel<MapViewModel>()
val state by viewModel.state.collectAsState()
Expand Down Expand Up @@ -368,6 +373,15 @@ private fun MapView(
),
onMapLoaded = {
viewModel.onMapLoaded()
},
onMapClick = {
dismissSpaceSelection()
if (state.showUserDetails) {
viewModel.dismissMemberDetail()
}
if (state.isStyleSheetVisible) {
viewModel.toggleStyleSheetVisibility(false)
}
}
) {
if (state.members.isNotEmpty()) {
Expand All @@ -377,6 +391,10 @@ private fun MapView(
location = it.location!!,
isSelected = it.user.id == state.selectedUser?.user?.id
) {
dismissSpaceSelection()
if (state.isStyleSheetVisible) {
viewModel.toggleStyleSheetVisibility(false)
}
viewModel.showMemberDetail(it)
}
}
Expand All @@ -388,7 +406,12 @@ private fun MapView(
user = currentUser,
location = location.toApiLocation(currentUser.id),
isSelected = currentUser.id == state.selectedUser?.user?.id
) {}
) {
dismissSpaceSelection()
if (state.isStyleSheetVisible) {
viewModel.toggleStyleSheetVisibility(false)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class MapViewModel @Inject constructor(
}

fun toggleStyleSheetVisibility(isVisible: Boolean) {
_state.value = _state.value.copy(isStyleSheetVisible = isVisible)
_state.value = _state.value.copy(isStyleSheetVisible = isVisible, showUserDetails = false)
}

fun showJourneyTimeline() {
Expand Down

0 comments on commit 2169093

Please sign in to comment.