fix: bottom sheet gestures; closes #347 (#359)

This commit is contained in:
Diego Beraldin 2023-12-23 13:39:27 +01:00 committed by GitHub
parent c9bd899c1f
commit 189aaa0612
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 253 additions and 227 deletions

View File

@ -60,8 +60,14 @@ internal class DefaultNavigationCoordinator : NavigationCoordinator {
.debounce(BOTTOM_NAVIGATION_DELAY)
.onEach { evt ->
when (evt) {
is NavigationEvent.Show -> bottomNavigator?.show(evt.screen)
NavigationEvent.Hide -> bottomNavigator?.hide()
is NavigationEvent.Show -> {
bottomNavigator?.show(evt.screen)
}
NavigationEvent.Hide -> {
bottomNavigator?.hide()
setBottomSheetGesturesEnabled(true)
}
}
}.launchIn(this)
screenChannel.receiveAsFlow()

View File

@ -133,7 +133,6 @@ class ExploreScreen : Screen {
topAppBarState.contentOffset = 0f
}
}.launchIn(this)
navigationCoordinator.setBottomSheetGesturesEnabled(true)
}
LaunchedEffect(model) {
model.effects.onEach {
@ -564,14 +563,14 @@ class ExploreScreen : Screen {
},
onReply = rememberCallback {
if (uiState.isLogged) {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
val screen = CreateCommentScreen(
originalPost = PostModel(id = result.model.postId),
originalComment = result.model,
)
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = PostModel(id = result.model.postId),
originalComment = result.model,
)
showBottomSheet(screen)
}
}
},
onOpenCommunity = rememberCallbackArgs { community, instance ->

View File

@ -165,9 +165,6 @@ class CommunityDetailScreen(
LaunchedEffect(notificationCenter) {
notificationCenter.resetCache()
}
LaunchedEffect(navigationCoordinator) {
navigationCoordinator.setBottomSheetGesturesEnabled(true)
}
LaunchedEffect(model) {
model.effects.onEach { effect ->
when (effect) {
@ -462,11 +459,13 @@ class CommunityDetailScreen(
icon = Icons.Default.Create,
text = stringResource(MR.strings.action_create_post),
onSelected = rememberCallback {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreatePostScreen(
communityId = uiState.community.id,
)
navigationCoordinator.showBottomSheet(screen = screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreatePostScreen(
communityId = uiState.community.id,
)
showBottomSheet(screen = screen)
}
},
)
}
@ -761,12 +760,12 @@ class CommunityDetailScreen(
)
OptionId.Edit -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
navigationCoordinator.showBottomSheet(
CreatePostScreen(editedPost = post),
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreatePostScreen(editedPost = post),
)
}
}
OptionId.Report -> {
@ -776,12 +775,12 @@ class CommunityDetailScreen(
}
OptionId.CrossPost -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
navigationCoordinator.showBottomSheet(
CreatePostScreen(crossPost = post),
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreatePostScreen(crossPost = post),
)
}
}
OptionId.SeeRaw -> {
@ -894,14 +893,18 @@ class CommunityDetailScreen(
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
})
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
},
)
showBottomSheet(screen)
}
}
})
}
@ -917,14 +920,16 @@ class CommunityDetailScreen(
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(originalComment = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
})
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(originalComment = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
})
showBottomSheet(screen)
}
}
},
)

View File

@ -93,7 +93,6 @@ object ProfileLoggedScreen : Tab {
lazyListState.scrollToItem(0)
}
}.launchIn(this)
navigationCoordinator.setBottomSheetGesturesEnabled(true)
}
LaunchedEffect(notificationCenter) {
notificationCenter.subscribe(NotificationCenterEvent.PostCreated::class).onEach {
@ -266,14 +265,14 @@ object ProfileLoggedScreen : Tab {
)
OptionId.Edit -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
navigationCoordinator.showBottomSheet(
CreatePostScreen(
editedPost = post,
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreatePostScreen(
editedPost = post,
)
)
)
}
}
OptionId.SeeRaw -> {
@ -399,12 +398,12 @@ object ProfileLoggedScreen : Tab {
}
OptionId.Edit -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
navigationCoordinator.showBottomSheet(
CreateCommentScreen(editedComment = comment)
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreateCommentScreen(editedComment = comment)
)
}
}
OptionId.SeeRaw -> {
@ -481,17 +480,19 @@ object ProfileLoggedScreen : Tab {
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen =
CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
}
)
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen =
CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
}
)
showBottomSheet(screen)
}
}
}
)
@ -508,9 +509,9 @@ object ProfileLoggedScreen : Tab {
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen =
CreateCommentScreen(
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalComment = content,
initialText = buildString {
append("> ")
@ -518,7 +519,8 @@ object ProfileLoggedScreen : Tab {
append("\n\n")
}
)
navigationCoordinator.showBottomSheet(screen)
showBottomSheet(screen)
}
}
}
)

View File

@ -264,11 +264,13 @@ class PostDetailScreen(
icon = Icons.Default.Reply,
text = stringResource(MR.strings.action_reply),
onSelected = rememberCallback {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = uiState.post,
)
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = uiState.post,
)
showBottomSheet(screen)
}
},
)
}
@ -356,11 +358,13 @@ class PostDetailScreen(
},
onReply = rememberCallback {
if (uiState.isLogged && !isOnOtherInstance) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = uiState.post,
)
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = uiState.post,
)
showBottomSheet(screen)
}
}
},
options = buildList {
@ -438,12 +442,12 @@ class PostDetailScreen(
OptionId.Delete -> model.reduce(PostDetailMviModel.Intent.DeletePost)
OptionId.Edit -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false,
)
navigationCoordinator.showBottomSheet(
CreatePostScreen(editedPost = uiState.post),
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreatePostScreen(editedPost = uiState.post),
)
}
}
OptionId.Report -> {
@ -453,12 +457,12 @@ class PostDetailScreen(
}
OptionId.CrossPost -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false,
)
navigationCoordinator.showBottomSheet(
CreatePostScreen(crossPost = uiState.post),
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreatePostScreen(crossPost = uiState.post),
)
}
}
OptionId.SeeRaw -> {
@ -712,16 +716,14 @@ class PostDetailScreen(
},
onReply = rememberCallback {
if (uiState.isLogged && !isOnOtherInstance) {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
val screen = CreateCommentScreen(
originalPost = uiState.post,
originalComment = comment,
)
navigationCoordinator.showBottomSheet(
screen
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = uiState.post,
originalComment = comment,
)
showBottomSheet(screen)
}
}
},
onOpenCreator = rememberCallbackArgs { user, instance ->
@ -814,14 +816,16 @@ class PostDetailScreen(
)
OptionId.Edit -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
navigationCoordinator.showBottomSheet(
CreateCommentScreen(
editedComment = comment,
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(
false
)
)
showBottomSheet(
CreateCommentScreen(
editedComment = comment,
)
)
}
}
OptionId.Report -> {
@ -932,14 +936,14 @@ class PostDetailScreen(
},
onReply = rememberCallback(model) {
if (uiState.isLogged && !isOnOtherInstance) {
navigationCoordinator.setBottomSheetGesturesEnabled(
false,
)
val screen = CreateCommentScreen(
originalPost = uiState.post,
originalComment = comment,
)
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = uiState.post,
originalComment = comment,
)
showBottomSheet(screen)
}
}
},
onOpenCreator = rememberCallbackArgs { user ->
@ -1011,14 +1015,14 @@ class PostDetailScreen(
)
OptionId.Edit -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false,
)
navigationCoordinator.showBottomSheet(
CreateCommentScreen(
editedComment = comment,
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreateCommentScreen(
editedComment = comment,
),
)
)
}
}
OptionId.Report -> {
@ -1193,14 +1197,18 @@ class PostDetailScreen(
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
})
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
},
)
showBottomSheet(screen)
}
}
},
)
@ -1217,14 +1225,18 @@ class PostDetailScreen(
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(originalComment = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
})
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalComment = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
},
)
showBottomSheet(screen)
}
}
},
)

View File

@ -125,7 +125,6 @@ class PostListScreen : Screen {
topAppBarState.contentOffset = 0f
}
}.launchIn(this)
navigationCoordinator.setBottomSheetGesturesEnabled(true)
}
LaunchedEffect(model) {
model.effects.onEach { effect ->
@ -483,12 +482,12 @@ class PostListScreen : Screen {
)
OptionId.Edit -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
navigationCoordinator.showBottomSheet(
CreatePostScreen(editedPost = post)
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreatePostScreen(editedPost = post),
)
}
}
OptionId.Report -> {
@ -498,12 +497,12 @@ class PostListScreen : Screen {
}
OptionId.CrossPost -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
navigationCoordinator.showBottomSheet(
CreatePostScreen(crossPost = post)
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreatePostScreen(crossPost = post),
)
}
}
OptionId.SeeRaw -> {
@ -620,17 +619,19 @@ class PostListScreen : Screen {
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen =
CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
}
)
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen =
CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
},
)
showBottomSheet(screen)
}
}
}
)

View File

@ -32,7 +32,6 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@ -99,10 +98,6 @@ class SavedItemsScreen : Screen {
val navigationCoordinator = remember { getNavigationCoordinator() }
val detailOpener = remember { getDetailOpener() }
LaunchedEffect(navigationCoordinator) {
navigationCoordinator.setBottomSheetGesturesEnabled(true)
}
Scaffold(
topBar = {
TopAppBar(
@ -375,12 +370,14 @@ class SavedItemsScreen : Screen {
)
},
onReply = {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = PostModel(id = comment.postId),
originalComment = comment,
)
navigatorCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = PostModel(id = comment.postId),
originalComment = comment,
)
showBottomSheet(screen)
}
},
options = buildList {
add(
@ -475,15 +472,18 @@ class SavedItemsScreen : Screen {
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
})
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
},
)
showBottomSheet(screen)
}
}
},
)
@ -500,16 +500,18 @@ class SavedItemsScreen : Screen {
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalComment = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
},
)
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalComment = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
},
)
showBottomSheet(screen)
}
}
}
)

View File

@ -151,9 +151,6 @@ class UserDetailScreen(
LaunchedEffect(notificationCenter) {
notificationCenter.resetCache()
}
LaunchedEffect(navigationCoordinator) {
navigationCoordinator.setBottomSheetGesturesEnabled(true)
}
LaunchedEffect(model) {
model.effects.onEach {
when (it) {
@ -576,12 +573,12 @@ class UserDetailScreen(
}
OptionId.CrossPost -> {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
navigationCoordinator.showBottomSheet(
CreatePostScreen(crossPost = post)
)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
showBottomSheet(
CreatePostScreen(crossPost = post),
)
}
}
OptionId.SeeRaw -> {
@ -743,14 +740,14 @@ class UserDetailScreen(
null
} else {
rememberCallback {
navigationCoordinator.setBottomSheetGesturesEnabled(
false
)
val screen = CreateCommentScreen(
originalPost = PostModel(id = comment.postId),
originalComment = comment,
)
navigationCoordinator.showBottomSheet(screen)
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = PostModel(id = comment.postId),
originalComment = comment,
)
showBottomSheet(screen)
}
}
},
onOpenCommunity = rememberCallbackArgs { community, instance ->
@ -870,17 +867,18 @@ class UserDetailScreen(
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen =
CreateCommentScreen(
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalPost = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
}
},
)
navigationCoordinator.showBottomSheet(screen)
showBottomSheet(screen)
}
}
}
)
@ -897,17 +895,18 @@ class UserDetailScreen(
onQuote = rememberCallbackArgs { quotation ->
rawContent = null
if (quotation != null) {
navigationCoordinator.setBottomSheetGesturesEnabled(false)
val screen =
CreateCommentScreen(
with(navigationCoordinator) {
setBottomSheetGesturesEnabled(false)
val screen = CreateCommentScreen(
originalComment = content,
initialText = buildString {
append("> ")
append(quotation)
append("\n\n")
}
},
)
navigationCoordinator.showBottomSheet(screen)
showBottomSheet(screen)
}
}
}
)