android / compose-samples

Official Jetpack Compose samples.
https://developer.android.com/jetpack/compose
Apache License 2.0
20.24k stars 4.81k forks source link

How can I solve the problem of Compose Navigation repeatedly creating destination? #679

Closed SakurajimaMaii closed 3 years ago

SakurajimaMaii commented 3 years ago

My MainActivity contains five pages built using Compose. Compose-Navigation will repeatedly create destinations, For this reason, the animation in the application interface is repeatedly loaded as demonstrated in the video below. How can I solve it? I have only found a solution using fragment but not Compose.

https://user-images.githubusercontent.com/46998172/136490478-8cc0e50c-0af0-4d62-89ad-f9b0542e1e1d.mp4

alone-wolf commented 3 years ago

Pls read the official documentation, they provided a resolution

发自我的iPhone

在 2021年10月8日,10:49,码上夏雨 @.***> 写道:

 My MainActivity contains five pages built using Compose. Compose-Navigation will repeatedly create destinations, Because there are animations in the interface, the interface is repeatedly loaded. How can I solve it? I have only found a solution using fragment but not Compose.In the example video below, you can see that the animation on the interface is repeatedly started due to the repeated loading of the destination, which greatly affects the user experience.

https://user-images.githubusercontent.com/46998172/136490478-8cc0e50c-0af0-4d62-89ad-f9b0542e1e1d.mp4

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

SakurajimaMaii commented 3 years ago

Pls read the official documentation, they provided a resolution 发自我的iPhone 在 2021年10月8日,10:49,码上夏雨 @.***> 写道:  My MainActivity contains five pages built using Compose. Compose-Navigation will repeatedly create destinations, Because there are animations in the interface, the interface is repeatedly loaded. How can I solve it? I have only found a solution using fragment but not Compose.In the example video below, you can see that the animation on the interface is repeatedly started due to the repeated loading of the destination, which greatly affects the user experience. https://user-images.githubusercontent.com/46998172/136490478-8cc0e50c-0af0-4d62-89ad-f9b0542e1e1d.mp4 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

I did not find the location of the solution you mentioned. Could you please give me a link?

alone-wolf commented 3 years ago

https://developer.android.google.cn/jetpack/compose/navigation?hl=zh-cn

“与底部导航栏集成”

发自我的iPhone

在 2021年10月8日,11:35,码上夏雨 @.***> 写道:

 Pls read the official documentation, they provided a resolution 发自我的iPhone … 在 2021年10月8日,10:49,码上夏雨 @.***> 写道:  My MainActivity contains five pages built using Compose. Compose-Navigation will repeatedly create destinations, Because there are animations in the interface, the interface is repeatedly loaded. How can I solve it? I have only found a solution using fragment but not Compose.In the example video below, you can see that the animation on the interface is repeatedly started due to the repeated loading of the destination, which greatly affects the user experience. https://user-images.githubusercontent.com/46998172/136490478-8cc0e50c-0af0-4d62-89ad-f9b0542e1e1d.mp4 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

I did not find the location of the solution you mentioned. Could you please give me a link?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

alone-wolf commented 3 years ago

and

I don't know what’s your preference

“导航到可组合项”

// Navigate to the "search” destination only if we’re not already on // the "search" destination, avoiding multiple copies on the top of the // back stack navController.navigate("search") { launchSingleTop = true }

发自我的iPhone

在 2021年10月8日,11:49,绝非专业人士 @.***> 写道:

https://developer.android.google.cn/jetpack/compose/navigation?hl=zh-cn

“与底部导航栏集成”

发自我的iPhone

在 2021年10月8日,11:35,码上夏雨 @.***> 写道:

 Pls read the official documentation, they provided a resolution 发自我的iPhone … 在 2021年10月8日,10:49,码上夏雨 @.***> 写道:  My MainActivity contains five pages built using Compose. Compose-Navigation will repeatedly create destinations, Because there are animations in the interface, the interface is repeatedly loaded. How can I solve it? I have only found a solution using fragment but not Compose.In the example video below, you can see that the animation on the interface is repeatedly started due to the repeated loading of the destination, which greatly affects the user experience. https://user-images.githubusercontent.com/46998172/136490478-8cc0e50c-0af0-4d62-89ad-f9b0542e1e1d.mp4 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

I did not find the location of the solution you mentioned. Could you please give me a link?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

SakurajimaMaii commented 3 years ago

and I don't know what’s your preference “导航到可组合项” // Navigate to the "search” destination only if we’re not already on // the "search" destination, avoiding multiple copies on the top of the // back stack navController.navigate("search") { launchSingleTop = true } 发自我的iPhone 在 2021年10月8日,11:49,绝非专业人士 @.> 写道: https://developer.android.google.cn/jetpack/compose/navigation?hl=zh-cn “与底部导航栏集成” 发自我的iPhone >> 在 2021年10月8日,11:35,码上夏雨 @.> 写道: >> >  > Pls read the official documentation, they provided a resolution 发自我的iPhone > … > 在 2021年10月8日,10:49,码上夏雨 @.***> 写道:  My MainActivity contains five pages built using Compose. Compose-Navigation will repeatedly create destinations, Because there are animations in the interface, the interface is repeatedly loaded. How can I solve it? I have only found a solution using fragment but not Compose.In the example video below, you can see that the animation on the interface is repeatedly started due to the repeated loading of the destination, which greatly affects the user experience. https://user-images.githubusercontent.com/46998172/136490478-8cc0e50c-0af0-4d62-89ad-f9b0542e1e1d.mp4 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. > > I did not find the location of the solution you mentioned. Could you please give me a link? > > — > You are receiving this because you commented. > Reply to this email directly, view it on GitHub, or unsubscribe.

Thank you very much for your reply. I have seen the link you sent before and configured it according to the requirements, but this problem still occurs. The following are some settings of my code.

onClick = {
                    navController.navigate(screen.route) {
                        popUpTo(navController.graph.findStartDestination().id) {
                            saveState = true
                        }
                        launchSingleTop = true
                        restoreState = true
                    }
                    vm.setCurrentPage(index)
                }