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

TabNavigator not Allowing Theme change #480

Closed
RaheemJnr opened this issue Aug 31, 2024 · 5 comments
Closed

TabNavigator not Allowing Theme change #480

RaheemJnr opened this issue Aug 31, 2024 · 5 comments

Comments

@RaheemJnr
Copy link

RaheemJnr commented Aug 31, 2024

I have been trying to implement theme change in 2 of my app but it being a hassle after extensive debug period I figured the common thing between them is that both app uses Voyager because they are a multiplatform app, I figured after a successful theme change and the state changes Voyager doesn't recompose to reflect the current (newly) selected theme until I close the app and open again, so my question now is had anyone faced similar issue and what advice will you give me on how to overcome it or probably a code example.

note: After lot of time spent debugging i found out it's the ### TabNavigator causing it. in two separate example where i use and didn't use the tab navigator the issue persist in the former and not the latter.

` @composable
override fun Content() {
val vm: ProfileViewmodel = koinScreenModel()
val modifier = Modifier
val isDark = remember { mutableStateOf(false) }

    TabNavigator(
        tab = TodayTab(),
        key = isDark.value.toString(),
        content = {
            Surface(
                modifier = modifier
                    .fillMaxSize()
                    .background(MaterialTheme.colorScheme.background)
                    .padding(top = 50.dp),
            ) {
                Box {
                    Icon(
                        imageVector = Icons.Rounded.WbSunny,
                        contentDescription = null,
                        modifier = modifier
                            .padding(16.dp)
                            .align(Alignment.TopEnd)
                            .size(32.dp)
                            .clickable {
                                isDark.value = !isDark.value
                                vm.toggleTheme(isDark = isDark.value)
                            }
                    )
                    Column(
                        modifier = modifier.fillMaxSize(),
                        verticalArrangement = Arrangement.Center,
                        horizontalAlignment = Alignment.CenterHorizontally,
                    ) {
                        Spacer(modifier = Modifier.height(16.dp))
                        Column(
                            horizontalAlignment = Alignment.CenterHorizontally,
                            verticalArrangement = Arrangement.spacedBy(62.dp),
                            modifier = modifier.padding(12.dp)
                        ) {
                            val text = buildAnnotatedString {
                                append("Just start with a ")
                                withStyle(
                                    style = SpanStyle(
                                        textDecoration = TextDecoration.Underline,
                                        color = MaterialTheme.colorScheme.primary
                                    )
                                ) {
                                    append("Goal")
                                }
                                append(" and we help break it down into ")
                                withStyle(style = SpanStyle(color = MaterialTheme.colorScheme.primary)) {
                                    append("actionable tasks")
                                }
                                append(" and ")
                                withStyle(style = SpanStyle(color = MaterialTheme.colorScheme.primary)) {
                                    append("time frame")
                                }
                            }
                            Text(
                                text = text,
                                style = MaterialTheme.typography.titleLarge.copy(
                                    fontWeight = FontWeight.Bold,
                                    textAlign = TextAlign.Center,
                                    letterSpacing = 2.sp
                                ),
                            )
                        }
                    }

                    SkipIcon {
                        //onSkipClick()
                    }
                }
            }
        }
    )

}`

the second example

`@Composable
override fun Content() {
val vm: ProfileViewmodel = koinScreenModel()
val modifier = Modifier
val isDark = remember { mutableStateOf(false) }

    Surface(
        modifier = modifier
            .fillMaxSize()
            .background(MaterialTheme.colorScheme.background)
            .padding(top = 50.dp),
    ) {
        Box {
            Icon(
                imageVector = Icons.Rounded.WbSunny,
                contentDescription = null,
                modifier = modifier
                    .padding(16.dp)
                    .align(Alignment.TopEnd)
                    .size(32.dp)
                    .clickable {
                        isDark.value = !isDark.value
                        vm.toggleTheme(isDark = isDark.value)
                    }
            )
            Column(
                modifier = modifier.fillMaxSize(),
                verticalArrangement = Arrangement.Center,
                horizontalAlignment = Alignment.CenterHorizontally,
            ) {
                Spacer(modifier = Modifier.height(16.dp))
                Column(
                    horizontalAlignment = Alignment.CenterHorizontally,
                    verticalArrangement = Arrangement.spacedBy(62.dp),
                    modifier = modifier.padding(12.dp)
                ) {
                    val text = buildAnnotatedString {
                        append("Just start with a ")
                        withStyle(
                            style = SpanStyle(
                                textDecoration = TextDecoration.Underline,
                                color = MaterialTheme.colorScheme.primary
                            )
                        ) {
                            append("Goal")
                        }
                        append(" and we help break it down into ")
                        withStyle(style = SpanStyle(color = MaterialTheme.colorScheme.primary)) {
                            append("actionable tasks")
                        }
                        append(" and ")
                        withStyle(style = SpanStyle(color = MaterialTheme.colorScheme.primary)) {
                            append("time frame")
                        }
                    }
                    Text(
                        text = text,
                        style = MaterialTheme.typography.titleLarge.copy(
                            fontWeight = FontWeight.Bold,
                            textAlign = TextAlign.Center,
                            letterSpacing = 2.sp
                        ),
                    )
                }
            }

            SkipIcon {
                //onSkipClick()
            }
        }
    }
}`
@kotlin-compose-multiplatform

I downgrade my voyager version and problem fixed:

  • my current version: 1.1.0-alpha04
  • same problem on this version: 1.1.0-beta02

@RaheemJnr
Copy link
Author

I downgrade my voyager version and problem fixed:

  • my current version: 1.1.0-alpha04
  • same problem on this version: 1.1.0-beta02

I'll downgrade and try it out

@RaheemJnr
Copy link
Author

@shageldi-dev Thank you so much! It finally worked after downgrading my voyager version.

@jayesh94
Copy link

jayesh94 commented Jan 3, 2025

@RaheemJnr did this work for you in iOS as well? Downgrading version works on Android, but doesn't work on iOS.

I have the below versions with another fix to make voyager work with kotlin 2.1.0 as suggested in iOS Doesn't build with kotlin 2.1.0 and voyager 1.1.0-beta03 or lower

I have also tried upgrading the compose version to 1.8.0-alpha06, still the same result.

compose = "1.7.6" 
compose-plugin = "1.7.3"
kotlin = "2.1.0"
voyager = "1.1.0-alpha04"

@RaheemJnr
Copy link
Author

RaheemJnr commented Jan 4, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants