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

Recompose problems #66

Closed
daimonkor opened this issue Nov 7, 2022 · 14 comments
Closed

Recompose problems #66

daimonkor opened this issue Nov 7, 2022 · 14 comments

Comments

@daimonkor
Copy link

daimonkor commented Nov 7, 2022

@alorma
Hm, can not recompose switchers Material 3 component when changed language

@Composable
fun SetLanguage(locale: Locale) {
    val configuration = LocalConfiguration.current
    configuration.setLocale(locale)
    val resources = LocalContext.current.resources
    resources.updateConfiguration(configuration, resources.displayMetrics)
}
 setContent {
            SetLanguage(locale = Locale.forLanguageTag(settingsViewModel.settings.languageTag))
-----
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Settings(
    navController: NavController,
    isDarkMode: Boolean,
) {
val darkSwitcherState = rememberBooleanSettingState(isDarkMode)
SettingsSwitch(
                state = darkSwitcherState,
                modifier = Modifier
                    .background(MaterialTheme.colorScheme.background),
                icon = {
                    Icon(
                        imageVector = Icons.Default.DarkMode,
                        contentDescription = stringResource(R.string.dark_mode),
                        tint = MaterialTheme.colorScheme.onBackground
                    )
                },
                title = {
                    Text(
                        stringResource(R.string.dark_mode),
                        color = MaterialTheme.colorScheme.onBackground
                    )
                },
                onCheckedChange = onDarkModeChange
            )
}

Looks like https://prnt.sc/GG-Owt-VbALQ
I mean recompose does not work for your switchers when changed configuration (locale).
Please try check, thanks a lot.

@alorma
Copy link
Owner

alorma commented Nov 7, 2022

Hi!

Can you provide a small project to reproduce the case?

@daimonkor
Copy link
Author

UtilityServices-1.zip
Please check

@alorma
Copy link
Owner

alorma commented Nov 7, 2022

I will check, thanks

@daimonkor
Copy link
Author

@alorma Thanks a lot.

@alorma
Copy link
Owner

alorma commented Nov 7, 2022

Hi!

The project is cool, but it doesn't contains compose-settings on it 😅

@daimonkor
Copy link
Author

@alorma
image

@alorma
Copy link
Owner

alorma commented Nov 7, 2022

I mean.. on the zip you provided, at least on the "develop" branch, I've removed the git and keystores files as I don't want that info

@alorma
Copy link
Owner

alorma commented Nov 7, 2022

BTW, there are few things I see...

Maybe

val darkSwitcherState = rememberBooleanSettingState(isDarkMode)

shouldn't belong to the settings composable, instead try to pass it through params, so it has to change whenever theme change

@daimonkor
Copy link
Author

please check again, I unpacked archive
image

@alorma
Copy link
Owner

alorma commented Nov 7, 2022

oh, I see it now.. on git. checking

@daimonkor
Copy link
Author

@alorma I tried check guides and bla bla, so I saw no state values as properties, only plain objects

@alorma
Copy link
Owner

alorma commented Nov 7, 2022

Well... I get the problem, but not understand why it's happening...

@alorma
Copy link
Owner

alorma commented Nov 7, 2022

I have a temporal solution... while I investigate more

Instead of

      SettingsSwitch(
          title = { Text(text = stringResource(R.string.dark_mode)) } // declare `stringResource` here
      )

Use

      val darkModeText = stringResource(R.string.dark_mode) // declare `stringResource` here, OUTSIDE of settings
      SettingsSwitch(
          title = { Text(text = darkModeText) },
      )

That sloves the problem... not sure why recomposition is not happening there... but at least problem is mitigated

@daimonkor
Copy link
Author

daimonkor commented Nov 7, 2022

@alorma magic, I will test, thanks a lot. Magic, but it works

@alorma alorma closed this as completed Nov 15, 2022
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

2 participants