Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
OXeu opened this issue Oct 28, 2023 · 0 comments
Open

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

OXeu opened this issue Oct 28, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@OXeu
Copy link
Contributor

OXeu commented Oct 28, 2023

问题

过去的旧版本使用全局 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
        }
    )
@OXeu OXeu added the enhancement New feature or request label Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants