-
Notifications
You must be signed in to change notification settings - Fork 70
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
Conversation
redwood-treehouse/src/commonMain/kotlin/app/cash/redwood/treehouse/ZiplineTreehouseUi.kt
Outdated
Show resolved
Hide resolved
private val mutableHostConfiguration = | ||
MutableStateFlow(computeHostConfiguration(context.resources.configuration)) | ||
|
||
override val hostConfiguration: StateFlow<HostConfiguration> | ||
get() = mutableHostConfiguration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wants Kotlin/KEEP#278
4a58b9f
to
2543dff
Compare
public data class HostConfiguration( | ||
val darkMode: Boolean = false, | ||
) { | ||
public companion object |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
infix functions so weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed
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.
2543dff
to
54abf4c
Compare
HostConfiguration
type to Compose through Treehouse
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