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

remove internal on ListPreferenceDefaults #15

Open
RichardLuo0 opened this issue Dec 5, 2024 · 1 comment
Open

remove internal on ListPreferenceDefaults #15

RichardLuo0 opened this issue Dec 5, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@RichardLuo0
Copy link

I am new to jetpack compose so I am unsure if I am doing this properly.
I want to create a custom wrapper for listPreference. So I do the following:

inline fun <T> LazyListScope.MylistPreference(
    key: String,
    defaultValue: T,
    values: List<T>,
    crossinline title: @Composable (T) -> Unit,
    modifier: Modifier = Modifier.fillMaxWidth(),
    crossinline rememberState: @Composable () -> MutableState<T> = {
        rememberPreferenceState(key, defaultValue)
    },
    crossinline enabled: (T) -> Boolean = { true },
    noinline icon: @Composable ((T) -> Unit)? = null,
    noinline summary: @Composable ((T) -> Unit)? = null,
    type: ListPreferenceType = ListPreferenceType.ALERT_DIALOG,
    noinline valueToText: (T) -> AnnotatedString = { AnnotatedString(it.toString()) },
    noinline item: @Composable (value: T, currentValue: T, onClick: () -> Unit) -> Unit =
        ListPreferenceDefaults.item(type, valueToText),
    // Some other options to customize
) {
    item(key = key, contentType = "ListPreference") {
        // Some other state

        val state = rememberState()
        val value by state
        ListPreference(
            state = state,
            values = values,
            title = { title(value) },
            modifier = modifier,
            enabled = enabled(value),
            icon = icon?.let { { it(value) } },
            summary = summary?.let { { it(value) } },
            type = type,
            valueToText = valueToText,
            item = item,
        )
    }
}

Then android studio complains ListPreferenceDefaults is internal and can not be used. So how do I keep the item while I can still use the default item if not provided? Or am I doing wrong?
Thx in advance.

@zhanghai
Copy link
Owner

zhanghai commented Dec 5, 2024

I want to create a custom wrapper for listPreference

That's indeed not directly supported right now if you want to keep the defaults. That being said, you can make a copy of the defaults, which isn't too long anyway.

@zhanghai zhanghai self-assigned this Dec 5, 2024
@zhanghai zhanghai added the question Further information is requested label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants