Ido Flax
12/15/2023, 5:41 PMCLOVIS
12/15/2023, 5:43 PM#
are not hashtags, they're different channels in which different people read messages.
Since this question is about the #glance library, it's more likely you will get good answers by asking them directly, instead of asking in the more general #android in which many people have never heard of #glance.Ido Flax
12/15/2023, 5:44 PMIdo Flax
12/15/2023, 5:44 PMMR3Y
12/15/2023, 6:34 PMIdo Flax
12/15/2023, 6:35 PMIdo Flax
12/15/2023, 6:37 PMMR3Y
12/15/2023, 6:40 PMIdo Flax
12/15/2023, 6:41 PMIdo Flax
12/15/2023, 6:42 PMimport androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.glance.text.FontFamily
import androidx.glance.text.FontStyle
import androidx.glance.text.FontWeight
import androidx.glance.text.TextAlign
import androidx.glance.text.TextDecoration
import androidx.glance.unit.ColorProvider
fun TextStyle.glancify() = androidx.glance.text.TextStyle(
color = ColorProvider(color),
fontSize = fontSize,
fontWeight = fontWeight?.glancify(),
fontStyle = fontStyle?.glancify(),
textAlign = textAlign?.glancify(),
textDecoration = textDecoration?.glancify(),
fontFamily = fontFamily?.glancify(),
)
internal fun Color.glancify() = ColorProvider(this)
internal fun androidx.compose.ui.text.font.FontWeight.glancify() = when (this.weight) {
FontWeight.Normal.value -> FontWeight.Normal
FontWeight.Medium.value -> FontWeight.Medium
FontWeight.Bold.value -> FontWeight.Bold
else -> error("Invalid fontWeight: $this")
}
internal fun androidx.compose.ui.text.font.FontStyle.glancify() = when (this.value) {
0 -> FontStyle.Normal
1 -> FontStyle.Italic
else -> error("Invalid fontStyle: $this")
}
internal fun androidx.compose.ui.text.style.TextAlign.glancify() = TextAlign.values().firstOrNull { it.toString() == this.toString() }
?: error("Invalid textAlign: $this")
internal fun androidx.compose.ui.text.style.TextDecoration.glancify() = when (this.mask) {
0x0 -> TextDecoration.None
0x1 -> TextDecoration.Underline
0x2 -> TextDecoration.LineThrough
else -> error("Invalid textDecoration: $this")
}
internal fun androidx.compose.ui.text.font.FontFamily.glancify() = when (toString()) {
FontFamily.SansSerif.toString() -> FontFamily.SansSerif
FontFamily.Serif.toString() -> FontFamily.Serif
FontFamily.Monospace.toString() -> FontFamily.Monospace
else -> error("Invalid fontFamily: $this")
}
Ido Flax
12/15/2023, 6:43 PMIdo Flax
12/15/2023, 6:43 PMMR3Y
12/15/2023, 6:45 PMIdo Flax
12/15/2023, 6:48 PMMR3Y
12/15/2023, 6:53 PMIdo Flax
12/15/2023, 6:57 PMCLOVIS
12/15/2023, 8:44 PMBut it could be a potential library idea: GlancifyIt's interesting that this would be suggested in a thread in which I participated 😅 Well, I'm working on exactly this: polymorphism for Compose. The goal is to allow creating "high-level components" that are implemented once per design system, per platform. This allows: • Switching between multiple design systems without changing application-level code (sell your application to multiple clients) • Adapting the application to each platform's design system (the layout automatically adapts to what is natural on iOS or Android) • Allow using the same composable functions transparently for technologies that use different appliers (e.g. Jetpack Compose and Glance) It's still very early stages, but you can follow the development in our repository or in the #decouple channel 🙂 If you're interested in how it works, the technical explanation is here.
MR3Y
12/15/2023, 9:04 PMCLOVIS
12/15/2023, 9:33 PMCLOVIS
12/15/2023, 9:37 PMMR3Y
12/15/2023, 10:13 PMIdo Flax
12/16/2023, 4:52 PMIdo Flax
12/16/2023, 5:10 PMCLOVIS
12/16/2023, 5:12 PMIdo Flax
12/16/2023, 8:19 PMMR3Y
12/16/2023, 9:22 PMMR3Y
12/16/2023, 9:23 PM