Giter Site home page Giter Site logo

alorma / compose-settings Goto Github PK

View Code? Open in Web Editor NEW
327.0 5.0 26.0 2.31 MB

Android #JetpackCompose Settings library

License: MIT License

Kotlin 98.05% Swift 0.95% HTML 1.00%
jetpack jetpack-compose jetpack-android compose android android-library settings

compose-settings's People

Contributors

alorma avatar darvld avatar dependabot[bot] avatar dessalines avatar itznotabug avatar jacobras avatar juliusmh avatar kvn-stgl avatar nkje avatar pelmenstar1 avatar renovate[bot] avatar s-h-y-a avatar tinyhai avatar zenyagami avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

compose-settings's Issues

1.1.0 Release issues

A few issues I've found:

  • com.github.alorma:compose-settings-ui-m3:1.1.0 is still missing / not deployed.
  • Using 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.

Checkboks in SettingsListMultiSelect don't respond to clicks.

A click on Row toggles the state of the checkbox, but a click on the checkbox itself does not.

Visual:
example-1

It's probably related to this code:

onCheckedChange = { checked ->
if (checked) {
onRemove(index)
} else {
onAdd(index)
}
}

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.

Update to Compose 1.4.3

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!

min SDK version 21

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?

Make dialogs scrollable

Currently, if there are many items in a dialog, they aren't scrollable, and you won't be able to select the bottom ones.

key in SharedPreferences

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?

Could not find com.github.alorma:compose-settings-storage-datastore:1.0.2

Details:

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

SettingsSwitch causing unnecessary height

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.

studio64_Ear7Yxuqbt

Jetpack DataStore support

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?

Unable to change checked or slider box

I am unable to change the checked setting on both SettingsSwitch and SettingsCheckbox.

CheckedError

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
            },
        )
    }
}

Disable icon?

I did not find the parameter to disable the icon. is there a way to disable it without manual editing?

Edit text preference

Unless I'm missing something, is there an EditTextPreference? A way to enter strings or numbers seems like something needed for many preference screens.

Recompose problems

@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.

Dropdown list selection

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?

[Feature request] Subtitle heigh optional

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!!

Generic `rememberPreference*SettingState`

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 -

  1. rememberSettingsDataStoreState<T>
  2. 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.

Example app crashes on start

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

README out of date.

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.

Update version in Readme

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

Remove dependency on material-icons-extended

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.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v3
  • actions/setup-java v3
.github/workflows/publish.yml
  • actions/checkout v3
  • actions/setup-java v3
gradle
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/gradle-wrapper.properties
  • gradle 8.1

  • Check this box to trigger a request for Renovate to run again on this repository

When using a `SettingsListDropdown` I get a `vertically scrollable component` error

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)
๏ฟฝ

Material 3

Hello. Do you want support Material 3?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.