当前位置:网站首页>Kotlin compose custom compositionlocalprovider compositionlocal
Kotlin compose custom compositionlocalprovider compositionlocal
2022-06-27 03:48:00 【Ango cannot move】
effect

Or you can change some styles by implicitly passing parameters
Customize MyCard.kt
package com.anguomob.jecpack.activity.compose.composition.local
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Card
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.graphics.Color
data class Elevations(val card: Dp = 0.dp)
val LocalElevations = compositionLocalOf {
Elevations()
}
object CardElevation {
val height: Elevations
get() = Elevations(card = 10.dp)
val low: Elevations
get() = Elevations(card = 5.dp)
}
@Composable
fun MyCard(
elevation: Dp = LocalElevations.current.card,
backgroundColor: Color,
content: @Composable () -> Unit
) {
Card(
elevation = elevation,
modifier = Modifier.size(200.dp),
backgroundColor = backgroundColor,
content = content
)
}Use
package com.anguomob.jecpack.activity.compose.composition.local
import androidx.compose.foundation.layout.Column
import androidx.compose.material.*
import androidx.compose.material.SnackbarDefaults.backgroundColor
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
import com.anguomob.jecpack.R
@Composable
fun CompositionSample2() {
Column() {
CompositionLocalProvider(LocalElevations provides CardElevation.height) {
MyCard(
backgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.05f)
) {
}
}
MyCard(backgroundColor = MaterialTheme.colors.onSurface.copy(alpha = 0.05f)) {
}
}
}
I'm still ignorant of my first study CompositionLocal
Now it is very simple and easy to understand
Chapter one :
Kotlin Compose Implicit parameters CompositionLocalProvider_ Ango Mobile Blog -CSDN Blog
边栏推荐
- Super detailed, 20000 word detailed explanation, thoroughly understand es!
- IOS development: understanding of dynamic library shared cache (dyld)
- ERP需求和销售管理 金蝶
- PostgreSQL基础命令教程:创建新用户admin来访问PostgreSQL
- Anaconda3安装过程及安装后缺失大量文件,没有scripts等目录
- 记录unity 自带读取excel的方法和遇到的一些坑的解决办法
- MATLAB | 三个趣的圆相关的数理性质可视化
- Human soberness: bottom logic and top cognition
- 2020:MUTANT: A Training Paradigm for Out-of-Distribution Generalizationin Visual Question Answering
- 2021:Greedy Gradient Ensemble for Robust Visual Question Answering
猜你喜欢

Facing the "industry, University and research" gap in AI talent training, how can shengteng AI enrich the black land of industrial talents?

Resnet152 pepper pest image recognition 1.0

Kotlin Compose compositionLocalOf 与 staticCompositionLocalOf

Qingscan use

Il manque beaucoup de fichiers et de répertoires tels que scripts pendant et après l'installation d'anaconda3

静态时序分析-OCV和time derate

ESP8266

mysql数据库基础:DQL数据查询语言

流沙画模拟器源码

2016Analyzing the Behavior of Visual Question Answering Models
随机推荐
Ldr6028 OTG data transmission scheme for mobile devices while charging
为什么 C# 访问 null 字段会抛异常?
2021:Graphhopper: Multi-Hop Scene Graph Reasoning for Visual Question Answering
Six possible challenges when practicing Devops
How can e-commerce products be promoted and advertised on Zhihu?
Basic functions of promise [IV. promise source code]
USB DRIVER
Knowledge of iPhone certificate structure
2020:MUTANT: A Training Paradigm for Out-of-Distribution Generalizationin Visual Question Answering
2021:Beyond Question-Based Biases:Assessing Multimodal Shortcut Learning in Visual Question Answeri
Further exploration of handler (I) (the most complete analysis of the core principle of handler)
Career outlook, money outlook and happiness outlook
Qingscan use
Super detailed, 20000 word detailed explanation, thoroughly understand es!
IDEA中好用的插件
Agile development - self use
使用promise的基本功能【四、Promise源码】
手机新领域用法知识
Super détaillé, 20 000 caractères détaillés, mangez à travers es!
2021:adavqa: overlapping language priors with adapted margin cosine loss *