admin管理员组文章数量:1410717
I am working on my first Android Compose app and need to validate whether this way of accessing resources like dimens, colors, and spacing is correct or not.
I created some classes like this:
@Immutable
class Spacing(
val none: Dp = 0.dp,
val small: Dp = 5.dp,
val medium: Dp = 10.dp,
val large: Dp = 20.dp,
val extraLarge: Dp = 30.dp,
val extraLarger: Dp = 40.dp,
val big: Dp = 100.dp,
)
One for Spacing
, one for Sizing
, one for Colors
, etc.
Is it OK to create a Singleton class and access from it? like this:
/**
* Singleton object that contains all the theme related values to be accessed from anywhere.
*/
object AppTheme {
val fontSizing = FontSizing()
val spacing = Spacing()
val color = Colors()
val sizing = Sizing()
}
So in my composable UI, the idea is to access it like this:
BottomSheetScaffold(
scaffoldState = scaffoldState,
sheetShape = RoundedCornerShape(topStart = AppTheme.spacing.large, topEnd = AppTheme.spacing.large),
sheetPeekHeight = AppTheme.sizing.bottomSheetPeekHeight,
sheetContent = {
DrawSheetContent(modifier, viewState, viewModel)
}
...
本文标签: Android Compose access Themeresource values like DimensColorsStack Overflow
版权声明:本文标题:Android Compose access Themeresource values like Dimens, Colors - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744816215a2626713.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论