Skip to content

[FR] 支持每个页面独立 Dialog 与 BottomSheetDialog #6

@OXeu

Description

@OXeu

问题

过去的旧版本使用全局 Dialog 与全局 BottomSheetDialog 的方式,这导致了许多问题:

  1. 首次启动隐私协议弹窗的可点击链接点击后不能跳转 App 内浏览器,因为即使跳转了引导弹窗也不会消失,仍然在浏览器界面之上,只能打开外部浏览器查看
  2. 评论区查看子回复会展开 BottomSheetDialog,在其中点击用户头像会跳转到用户主页,此时需要将 BottomSheetDialog 关闭,如果不关闭它仍会显示在最顶部,而不是被用户主页的界面覆盖

解决方案

考虑到目前 Navigation 均使用了自己封装了一层的 animateCompose 方法,可以在该方法中使用 CompositionLocalProvider 提供 LocalDialogLocalBottomSheetDialog,实现其每个页面的弹窗独立化,不再置于全局顶部

考虑修改以下代码

https://github.com/BingyanStudio/BBHustAndroid/blob/648c7f8311d942389d867a8cc27df6c560cb4e05/app/src/main/java/com/bingyan/bbhust/AppNav.kt#L72-L96

为:

@OptIn(ExperimentalAnimationApi::class)
fun NavGraphBuilder.animateCompose(
    route: String,
    arguments: List<NamedNavArgument> = emptyList(),
    deepLinks: List<NavDeepLink> = emptyList(),
    content: @Composable AnimatedVisibilityScope.(NavBackStackEntry) -> Unit
) =
    composable(
        route,
        enterTransition = {
            slideInHorizontally(initialOffsetX = { it }, animationSpec = animation)
        },
        exitTransition = {
            slideOutHorizontally(targetOffsetX = { -it / 2 }, animationSpec = animation)
        },
        popEnterTransition = {
            slideInHorizontally(initialOffsetX = { -it / 2 }, animationSpec = animation)
        },
        popExitTransition = {
            slideOutHorizontally(targetOffsetX = { it }, animationSpec = animation)
        },
        arguments = arguments,
        deepLinks = deepLinks,
        content = {
+            // Wrap it with Dialog & BottomSheetDialog
            content(it)
+            // Wrap it with Dialog & BottomSheetDialog
        }
    )

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions