I have a `OutlinedTextField` and ```var email by r...
# compose
k
I have a
OutlinedTextField
and
Copy code
var email by rememberSaveable { mutableStateOf("") }
inside single compose function. Upon rotating screen, email state value resets to
""
. Shouldn't
rememberSaveable
actually keep value of an email and not reset it?
c
Hm. It should indeed. Do you have any effects defined or anything?
I just tried this and it worked, so it sounds like maybe something is wrong with your code somewhere. Hard to tell without seeing it.
Copy code
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            AppTheme {
                Surface(modifier = Modifier.fillMaxSize()) {
                    var email by rememberSaveable { mutableStateOf("") }
                    OutlinedTextField(value = email, onValueChange = { email = it })
                }
            }
        }
    }
}
k
Hard nested
rememberSaveable
should still work, right?
It might be due to nested navigation?
Copy code
private fun NavGraphBuilder.addAuthenticationScreenModule() {
    navigation(
        route = AuthenticationNavigation.route,
        startDestination = AuthenticationNavigation.SignInNavigation.route
    ) {
        addSignInScreen()
    }
}

private fun NavGraphBuilder.addSignInScreen() {
    composable(
        route = AuthenticationNavigation.SignInNavigation.route,
    ) {
        SignInScreen()
    }
}
I just tested and it works all until inside SignInScreen composable.
c
Maybe related to this that was asked just yesterday? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1627788714178500
k
Thanks, I'll look into it.
NavHost
definately for some reason breaks it, not sure if it's my fault, but this does not save `rememberSaveable`:
Copy code
class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            OperationCenterTheme {
                NavHost(navController = rememberNavController(), startDestination = SplashNavigation.route) {
                    composable(route = SplashNavigation.route) {
                        TestComposable()
                    }
                }
            }
        }
    }
}
and this works
Copy code
class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            OperationCenterTheme {
                TestComposable()
            }
        }
    }
}
Ok, found it,
rememberSaveable
got broken with
androidx.navigation:navigation-compose:2.4.0-alpha05
, works in
2.4.0-alpha04
😲 2
c
Try alpha06 released today?
k
Thanks mate
s
There's the bug in alpha06 too 😞
c
Fixed in alpha07. Try the snapshot.
🆒 1
❤️ 1