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

Expose HostConfiguration type to Compose through Treehouse #393

Merged
merged 1 commit into from
Oct 4, 2022

Conversation

JakeWharton
Copy link
Member

@JakeWharton JakeWharton commented Sep 27, 2022

This will hold more in the future such as the locale, pixel density, etc. For now we propagate whether the host is in dark mode to get things started.

Screen.Recording.2022-09-27.at.11.00.35.AM.mov

Refs #355

Comment on lines +69 to +75
private val mutableHostConfiguration =
MutableStateFlow(computeHostConfiguration(context.resources.configuration))

override val hostConfiguration: StateFlow<HostConfiguration>
get() = mutableHostConfiguration
Copy link
Member Author

Choose a reason for hiding this comment

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

@JakeWharton JakeWharton force-pushed the jw/host-display-stuff/2022-09-12 branch 4 times, most recently from 4a58b9f to 2543dff Compare September 29, 2022 15:07
public data class HostConfiguration(
val darkMode: Boolean = false,
) {
public companion object
Copy link
Collaborator

Choose a reason for hiding this comment

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

weeeird

* @see HostConfiguration
*/
@Suppress("unused") // Emulating a CompositionLocal.
public val HostConfiguration.Companion.current: HostConfiguration
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ahhh there it is

val (initialHostConfiguration, hostConfigurationFlow) = hostConfigurations
composition.setContent {
val hostConfiguration by hostConfigurationFlow.collectAsState(initialHostConfiguration)
CompositionLocalProvider(LocalHostConfiguration provides hostConfiguration) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

infix functions so weird

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed

@swankjesse
Copy link
Collaborator

Really nice

This will hold more in the future such as the locale, pixel density, etc. For now we propagate whether the host is in dark mode to get things started.
@JakeWharton JakeWharton force-pushed the jw/host-display-stuff/2022-09-12 branch from 2543dff to 54abf4c Compare October 4, 2022 14:28
@JakeWharton JakeWharton enabled auto-merge (squash) October 4, 2022 14:29
@JakeWharton JakeWharton changed the title Expose HostConfiguration type to Compose through Treehouse Expose HostConfiguration type to Compose through Treehouse Oct 4, 2022
@JakeWharton JakeWharton merged commit a663a28 into trunk Oct 4, 2022
@JakeWharton JakeWharton deleted the jw/host-display-stuff/2022-09-12 branch October 4, 2022 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants