Skip to content

Add extension overloads for LazyListScope#34

Open
Goooler wants to merge 3 commits into
zhanghai:masterfrom
Goooler:reload-extensions-for-list-scope
Open

Add extension overloads for LazyListScope#34
Goooler wants to merge 3 commits into
zhanghai:masterfrom
Goooler:reload-extensions-for-list-scope

Conversation

@Goooler
Copy link
Copy Markdown

@Goooler Goooler commented Apr 29, 2026

It's handy for reading and updating values from ViewModels.

  • Tests pass
  • Appropriate changes to README are included in PR

@zhanghai
Copy link
Copy Markdown
Owner

Need to update README section talking about 3 kinds of APIs to 4 (https://github.com/zhanghai/ComposePreference#preferences) as well.

@zhanghai zhanghai self-assigned this Apr 29, 2026
@zhanghai zhanghai added the enhancement New feature or request label Apr 29, 2026
@Goooler Goooler force-pushed the reload-extensions-for-list-scope branch from 633038b to dce7eca Compare April 30, 2026 01:35
@Goooler
Copy link
Copy Markdown
Author

Goooler commented Apr 30, 2026

Done.

@Goooler
Copy link
Copy Markdown
Author

Goooler commented May 12, 2026

Any updates?

@zhanghai
Copy link
Copy Markdown
Owner

Please resolve the pending comments.

@Goooler
Copy link
Copy Markdown
Author

Goooler commented May 13, 2026

@zhanghai
Copy link
Copy Markdown
Owner

@Goooler
Copy link
Copy Markdown
Author

Goooler commented May 13, 2026

Sorry, there is nothing about your review comment.

}
}

@Suppress("NOTHING_TO_INLINE")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why inline if nothing to inline? This is app code so seems to me we should rely on compiler and JIT optimizations.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Didn't have time to think about this, but alternatively what about crossinline?)

Copy link
Copy Markdown
Author

@Goooler Goooler May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid we can't. If we mark crossinline for:

  • onValueChange or title, the compiler errors for:
Illegal usage of inline parameter 'crossinline onValueChange: (Boolean) -> Unit'. Add 'noinline' modifier to the parameter declaration.
  • icon or summary, the compiler errors like:
Inline parameter 'crossinline icon: ComposableFunction0<Unit>? = ...' of 'fun LazyListScope.checkboxPreference(key: String, value: Boolean, noinline onValueChange: (Boolean) -> Unit, noinline title: ComposableFunction0<Unit>, modifier: Modifier = ..., enabled: Boolean = ..., crossinline icon: ComposableFunction0<Unit>? = ..., crossinline summary: ComposableFunction0<Unit>? = ...): Unit' cannot be nullable. Add 'noinline' modifier to the parameter declaration or make its type not nullable.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack on icon and summary, they are indeed noinline in the existing overload due to being nullable. But I'm not following why title can't be crossinline here, since it is crossinline in the existing overload. Could you please help explain that?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, that's because the other overload is using title in its own body, but here title is passed on as a parameter. The same goes for onValueChange.

That said, if there's no lambda that can be inlined, why don't we just follow the lint and don't use inline function?

Copy link
Copy Markdown
Author

@Goooler Goooler May 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can. I inlined them here just to align the styles from the existing ones.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread README.md Outdated
1. A `LazyListScope.*Preference` extension function, which is the easiest way to use preferences in this library, and helps developers to avoid boilerplates like having to specify the key twice for the `LazyColumn` and the `Preference`.
2. A `*Preference` composable that takes a `MutableState`, which allows developers to bring in any kind of state they currently have.
3. A `*Preference` composable that takes `value` and `onValueChange`, which allows developers to use the preference without a state and even in non-preference scenarios.
2. A `LazyListScope.*Preference` extension function, reloads the first one for `value` and `onValueChange` params.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you meant overloads instead of reloads? Something like , which is an overload of the first extension function but accepts value and onValueChange.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a typo.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@zhanghai
Copy link
Copy Markdown
Owner

Oh, sorry I didn't realize Pending on GitHub means not sent out - that is called Draft on Gerrit. Whereas Pending on Gerrit means sent out but not resolved yet.

It's handy for reading and updating values from ViewModels.
@Goooler Goooler force-pushed the reload-extensions-for-list-scope branch from dce7eca to de046cd Compare May 13, 2026 04:34
Comment thread README.md Outdated
}
}

@Suppress("NOTHING_TO_INLINE")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack on icon and summary, they are indeed noinline in the existing overload due to being nullable. But I'm not following why title can't be crossinline here, since it is crossinline in the existing overload. Could you please help explain that?

Goooler and others added 2 commits May 15, 2026 15:18
Co-authored-by: Hai Zhang <4469895+zhanghai@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants