Giter VIP home page Giter VIP logo

Comments (2)

xorzdev avatar xorzdev commented on May 30, 2024 1
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun NavHostSample() {
    val navigator = rememberNavigator()
    NavHost(
        navigator = navigator,
        initialRoute = "/A",
        swipeProperties = remember { SwipeProperties() },
    ) {
        scene(route = "/A") {
            var count by rememberSaveable { mutableStateOf(0) }
            Column(
                modifier = Modifier.fillMaxSize(),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center,
            ) {
                Button(onClick = { count++ }) {
                    Text(text = "count: $count")
                }
                Button(onClick = { navigator.navigate(route = "/B") }) {
                    Text(text = "navigate")
                }
            }
        }
        scene(route = "/B") {
            Column(
                modifier = Modifier.fillMaxSize(),
                horizontalAlignment = Alignment.CenterHorizontally,
                verticalArrangement = Arrangement.Center,
            ) {
                Button(onClick = { navigator.goBack() }) {
                    Text(text = "goBack")
                }
            }
        }
    }
}

以上代码在从A页面导航到B页面再回退到A页面时,count 被重置了

我发现跟这个 swipeProperties 参数有关,当我去掉这个参数时问题消失了

from precompose.

Tlaster avatar Tlaster commented on May 30, 2024

麻烦补全一下复现步骤
如果是:
①:在 A 页面使用rememberSaveable,导航到 B 页面,调用navigator.goBack()返回 A 页面,此时我测试rememberSaveable的行为正常,数据没有被重置,如果发现被重置了麻烦提供能够复现的 sample
②:从 A 页面导航到 B 页面,在 B 页面使用rememberSaveable,调用navigator.goBack()返回 A 页面,此时 B 页面rememberSaveable会被重置,这是预期行为
如果还有别的情况,麻烦补充,最好能够提供最小复现 sample

from precompose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.