https://kotlinlang.org logo
#compose
Title
# compose
y

Yamila Gammeri

09/04/2020, 3:29 AM
For some reason, my selectedNavigationTab resets itself to the initial value instead of retaining when a new navigationTab is selected. This occurs when the SignedInView is re-rendered on a theme change. What could I be doing wrong, this was working when I used the now removed 
state { xx }
Copy code
@Composable
fun SignedInView() {
  val context = ContextAmbient.current

  val initialNavigationTab = {
    if (runningInDebug(context = context)) {
      NavigationTab.Clinic
    } else {
      NavigationTab.Prepare
    }
  }()

  val selectedNavigationTab = mutableStateOf(initialNavigationTab)

  val navigationTabs = NavigationTab.values()

  Scaffold(
    topBar = { selectedNavigationTab.value.topBar() },
    bodyContent = { innerPadding ->
      val additionalPadding = 16.dp
      val contentPadding = InnerPadding(
        start = innerPadding.start + additionalPadding,
        top = <http://innerPadding.top|innerPadding.top> + additionalPadding,
        end = innerPadding.end + additionalPadding,
        bottom = innerPadding.bottom + additionalPadding
      )

      selectedNavigationTab.value.bodyContent(contentPadding = contentPadding)
    },
    bottomBar = { BottomBar(navigationTabs = navigationTabs, selectedNavigationTab = selectedNavigationTab) }
  )
}
a

allan.conda

09/04/2020, 5:17 AM
I can’t see where you update the selectedNavigationTab.value anyway, equivalent of
state{}
is
remember { mutableStateOf(value) }
2 Views