zhanghai / ComposePreference

Preference implementation for Jetpack Compose Material 3
Apache License 2.0
185 stars 9 forks source link

Suggestion: Create switch bar preference #9

Open WSTxda opened 1 month ago

WSTxda commented 1 month ago

Just like in settingslib / AOSP settings and other apps, the switch bar is used as a master control for a list of preferences.

This is useful when you need to determine a high priority preference in list, on which the others depend on it.

I think it could be an interesting addition.

Screenshot_2024-09-11-02-56-36-031_app.revanced.android.gms.jpg

Screenshot_2024-09-11-02-56-41-065_app.revanced.android.gms.jpg

zhanghai commented 1 month ago

I did consider this one, the major issue I saw was that there's no good UX spec for the font, color and spacing etc so I didn't add it.

WSTxda commented 1 month ago

I did consider this one, the major issue I saw was that there's no good UX spec for the font, color and spacing etc so I didn't add it.

Are you referring to attributes? I don't know how it is in compose, but a cardview or drawable shape can be used for this with primaryContainer in background color. For text can be usel use textAppearanceTitleLarge with 20sp for text size. For the paddings need to adjust according to the background for visual harmony.

Screenshot_2024-09-12-01-37-35-764_app.revanced.android.gms-edit.jpg

Noting that there must be a limit on the margin that visually respects the corners of the background.

zhanghai commented 1 month ago

It's not as simple as that, because this has a lot of custom design tokens that aren't shared with other preferences so if we add it we'll have to expose all those as separate entries in PreferenceTheme as well. For instance the title font and the rounded corner size, and the different paddings. You may look at https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/packages/SettingsLib/MainSwitchPreference/src/com/android/settingslib/widget/MainSwitchPreference.java to implement one for yourself without supporting theming though, and that will be much simpler.