alorma / compose-settings Goto Github PK
View Code? Open in Web Editor NEWAndroid #JetpackCompose Settings library
License: MIT License
Android #JetpackCompose Settings library
License: MIT License
A few issues I've found:
com.github.alorma:compose-settings-ui-m3:1.1.0
is still missing / not deployed.com.github.alorma:compose-settings-ui-m3:1.1.0
requires an increase in the minSdk from 21 -> 26 for some reason, and also is missing all the rememberIntSettingsState
functions.The readme only shows two examples, it would be good to add the others to the readme / docs also.
A click on Row
toggles the state of the checkbox, but a click on the checkbox itself does not.
It's probably related to this code:
When the checkbox's state is changed to true, the index to the set should be added, not removed. The same thing is when the state is changed to false - the index should be removed.
Hello! Would it be possible to update the libraries to the newer compose 1.4.x? I think since you already use the BOM you can simply update that one!
What is the reason that min SDK version is 23? When you create a compose application the default suggestion is 21. Maybe this library also could be min SDK 21?
These seem to be internal only.
Currently, if there are many items in a dialog, they aren't scrollable, and you won't be able to select the bottom ones.
In the original android implementation for PreferenceScreen the key's where retrieved from the SharedPrefernces. The key's where also updated by the Preference, for instance the SwitchPreference with key 'switch' would save its state to the correct SharedPreference.
This was very handy. Is functionality like this planned?
It seems the latest available version if 1.0.3 (https://mvnrepository.com/artifact/com.github.alorma/compose-settings-ui-m3) while the Releases page shows several releases up to 1.0.9. I noticed those releases failed to publish, any plan to get them out? Would love to use this library in more projects now that it's multiplatform supported.
Could not find com.github.alorma:compose-settings-storage-datastore:1.0.2.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/github/alorma/compose-settings-storage-datastore/1.0.2/compose-settings-storage-datastore-1.0.2.pom
- https://repo.maven.apache.org/maven2/com/github/alorma/compose-settings-storage-datastore/1.0.2/compose-settings-storage-datastore-1.0.2.pom
Library version: 1.0.2
Little comment: I think the library [compose-settings-storage-datastore] is unavailable in maven central, but, it appear that this library have another reference (?)
url: https://mvnrepository.com/artifact/com.github.alorma/compose-settings-storage-preferences/1.0.2
From version 0.25.0 and onwards, making a SettingsSwitch causes the setting item to become almost full height when only a title is used, and full height when title and subtitle.
I remember playing around with the SettingsSwitch composable a while back and I recall its the Switch causing the height to overscale. I don't have that poc anymore but did whip up a quick preview through AS using 0.25.0. Version 0.24.0 does not display this symptom.
It would be great if the library had the explicit support of Jetpack DataStore. It's doable without the support of the library, but the output code is quite hard to support then.
@alorma What do you think about it?
This would be extremely useful in an application I'm building.
I am unable to change the checked setting on both SettingsSwitch and SettingsCheckbox.
Gradle Settings
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.CliftonSoftware.hobbsLogger"
minSdk 29
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
useIR = true
}
buildFeatures {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion compose_version
kotlinCompilerVersion '1.5.21'
}
packagingOptions {
resources {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
}
Here is the code I am using:
@Composable
fun SettingScreenContent(
){
var darkTheme = remember {false}
var icon = remember{Icons.Default.ModeNight}
Column() {
SettingsSwitch(
icon = {
Icon(imageVector = icon , contentDescription = "Theme")
},
title = { Text(text = "Dark Theme") },
checked = darkTheme,
onCheckedChange = {
icon = if(icon == Icons.Default.ModeNight){
Icons.Default.LightMode
}else{
Icons.Default.ModeNight
}
darkTheme = !darkTheme
},
)
}
}
I did not find the parameter to disable the icon. is there a way to disable it without manual editing?
See this: https://developer.android.com/reference/android/preference/Preference.html#attr_android:dependency
Alternatively,
an enabled
state can also be added to allow/disallow interacting with a Setting.
Unless I'm missing something, is there an EditTextPreference? A way to enter strings or numbers seems like something needed for many preference screens.
@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.
The library has a SettingsList
widget that shows a dialog where a user can select an item, but sometimes a more compact dropdown menu list is preferable.
Jetpack Compose has the support for that - see DropdownMenu
.
@alorma What do you think?
Currently there is a limitation of the sutitle size, if the text is more than 2 lines, the subtitle is cutted
example code in SettingsTileScaffold
val maxHeight = if (subtitle == null) 72.dp else 88.dp
event if my composable supports 3 lines, the max line of 88.dp
make this not possible, would be great to add as an optional parameter so we can override or as modifier.
Thanks a lot!!
Can u provide another compose component that accepts string state variable, so we can use rememberPreferenceStringSettingState
directly in ours project? Thanks your great work!
Hi there,
Sorry for creating back-to-back Issues & PRs.
I liked the solution provided by the library & just think that there can be improvements :)
Enhancement / Suggestion :
I think we can use generic api like below instead of explicitly typed rememberPreference*SettingState
-
rememberSettingsDataStoreState<T>
rememberSettingsPreferenceState<T>
Sample usage:
// Using SharedPreference
val switchState = rememberSettingsPreferenceState(key = "themeSwitch", defaultValue = false)
// Using DataStore
val switchState = rememberSettingsDataStoreState(key = "themeSwitch", defaultValue = false)
Let me know what you think.
The stack trace:
Process: com.alorma.compose.settings.example, PID: 16781
android.content.res.Resources$NotFoundException: Resource ID #0x1060028
at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
at android.content.res.Resources.getColor(Resources.java:961)
at androidx.compose.material3.ColorResourceHelper.getColor-WaAFU9c(DynamicTonalPalette.kt:186)
at androidx.compose.material3.DynamicTonalPaletteKt.dynamicTonalPalette(DynamicTonalPalette.kt:41)
at androidx.compose.material3.DynamicTonalPaletteKt.dynamicDarkColorScheme(DynamicTonalPalette.kt:155)
at com.alorma.compose.settings.example.ui.theme.ThemeKt.ComposeSettingsTheme(Theme.kt:20)
at com.alorma.compose.settings.example.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:41)
at com.alorma.compose.settings.example.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:28)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:404)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:250)
at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:249)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:177)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:123)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:122)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:114)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:157)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$3.invoke(Wrapper.android.kt:156)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:156)
at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:140)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:107)
at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:34)
at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:78)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3248)
at androidx.compose.runtime.ComposerImpl$doCompose$2$5.invoke(Composer.kt:3238)
at androidx.compose.runtime.SnapshotStateKt__DerivedStateKt.observeDerivedStateRecalculations(DerivedState.kt:341)
at androidx.compose.runtime.SnapshotStateKt.observeDerivedStateRecalculations(Unknown Source:1)
at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3238)
at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3173)
Looks like something is wrong with resources
Tch and the other day I was going to be in a meeting with you and your
You could probably get rid of most of it, and just update the dependencies / install instructions.
And link to your sample settings file for a how to use it.
The current version displayed in the Readme is 0.7.0
, which is not present in Maven Central. It should be set to 0.7.1
material-icons-extended
is a significantly large library, and it should not be required as a dependency for this library, instead, the library users should choose which icons to use.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.
.github/workflows/build.yml
actions/checkout v3
actions/setup-java v3
.github/workflows/publish.yml
actions/checkout v3
actions/setup-java v3
gradle.properties
settings.gradle
build.gradle
io.github.gradle-nexus:publish-plugin 1.3.0
io.codearte.gradle.nexus:gradle-nexus-staging-plugin 0.30.0
app/build.gradle.kts
app_m3/build.gradle.kts
compose-settings-storage-base/build.gradle.kts
compose-settings-storage-datastore/build.gradle.kts
compose-settings-storage-datastore-proto/build.gradle.kts
compose-settings-storage-preferences/build.gradle.kts
compose-settings-ui/build.gradle.kts
compose-settings-ui-m3/build.gradle.kts
gradle/libs.versions.toml
androidx.activity:activity-compose 1.7.0
androidx.navigation:navigation-compose 2.5.3
androidx.preference:preference 1.2.0
androidx.preference:preference-ktx 1.2.0
com.android.tools.build:gradle 7.4.2
androidx.compose:compose-bom 2023.04.00
androidx.datastore:datastore-preferences-core 1.1.0-alpha04
androidx.datastore:datastore-preferences 1.1.0-alpha04
androidx.datastore:datastore 1.1.0-alpha04
com.google.protobuf:protobuf-javalite 3.22.3
com.google.protobuf:protobuf-kotlin-lite 3.22.3
com.google.protobuf:protoc 3.22.3
org.jetbrains.kotlin:kotlin-gradle-plugin 1.8.10
scripts/publish-module.gradle
scripts/publish-root.gradle
gradle/wrapper/gradle-wrapper.properties
gradle 8.1
The SettingsListMultiSelect
takes in a Set<Int>
, but returns a List<String>
instead of a Set<Int>
for onItemsSelected.
One way I've found to fix this, is to wrap every SettingsListDropdown
in
Modifier.heightIn(max = 88.dp)
I don't get this issue with SettingsList
Full stack trace:
FATAL EXCEPTION: main
Process: com.jerboa.debug, PID: 24310
java.lang.IllegalStateException: Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed. One of the common reasons is nesting layouts like LazyColumn and Column(Modifier.verticalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyColumn scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.
at androidx.compose.foundation.CheckScrollableContainerConstraintsKt.checkScrollableContainerConstraints-K40F9xA(CheckScrollableContainerConstraints.kt:35)
at androidx.compose.foundation.ScrollingLayoutNode.measure-3p2s80s(Scroll.kt:385)
at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
at androidx.compose.foundation.AndroidOverscroll_androidKt$StretchOverscrollNonClippingLayer$2.invoke-3p2s80s(AndroidOverscroll.android.kt:584)
at androidx.compose.foundation.AndroidOverscroll_androidKt$StretchOverscrollNonClippingLayer$2.invoke(AndroidOverscroll.android.kt:583)
at androidx.compose.ui.layout.LayoutModifierImpl.measure-3p2s80s(LayoutModifier.kt:294)
at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
at androidx.compose.foundation.AndroidOverscroll_androidKt$StretchOverscrollNonClippingLayer$1.invoke-3p2s80s(AndroidOverscroll.android.kt:568)
at androidx.compose.foundation.AndroidOverscroll_androidKt$StretchOverscrollNonClippingLayer$1.invoke(AndroidOverscroll.android.kt:567)
at androidx.compose.ui.layout.LayoutModifierImpl.measure-3p2s80s(LayoutModifier.kt:294)
at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
at androidx.compose.ui.graphics.SimpleGraphicsLayerModifier.measure-3p2s80s(GraphicsLayerModifier.kt:646)
at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
at androidx.compose.foundation.layout.PaddingNode.measure-3p2s80s(Padding.kt:397)
at androidx.compose.ui.node.LayoutModifierNodeCoordinator.measure-BRTryo0(LayoutModifierNodeCoordinator.kt:116)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:252)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate$performMeasureBlock$1.invoke(LayoutNodeLayoutDelegate.kt:251)
at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:2303)
at androidx.compose.runtime.snapshots.SnapshotStateObserver$ObservedScopeMap.observe(SnapshotStateObserver.kt:500)
at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:256)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:133)
at androidx.compose.ui.node.OwnerSnapshotObserver.observeMeasureSnapshotReads$ui_release(OwnerSnapshotObserver.kt:113)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate.performMeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:1617)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate.access$performMeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:36)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.remeasure-BRTryo0(LayoutNodeLayoutDelegate.kt:620)
at androidx.compose.ui.node.LayoutNodeLayoutDelegate$MeasurePassDelegate.measure-BRTryo0(LayoutNodeLayoutDelegate.kt:596)
at androidx.compose.foundation.layout.RowColumnMeasurementHelper.measureWithoutPlacing-EkL-Y(RowColumnMeasurementHelper.kt:112)
at androidx.compose.foundation.layout.RowColumnMeasurePolicy.measure-3p2s80s(RowColumnImpl.kt:72)
๏ฟฝ
I need to have a setting for font size, so I suspect its slider, but how do I display the value?
If a dialog is shown using SettingsList and SettingsListMultiSelect, the dialog will be hidden after a configuration update (for example, screen orientation change)
I just want to clarify whether it's expected behavior because I would expect the dialog to be shown again with the same state.
Hello. Do you want support Material 3?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.