当前位置:网站首页>32. Compose 优美的触摸动画
32. Compose 优美的触摸动画
2022-06-23 14:22:00 【会编程的猩猩】

@Composable
fun TouchAnimationPage(navCtrl: NavHostController, title: String) {
val currentPositionColor = Color.White
val lastPositionColor = Color.LightGray
var cacheOffset by remember() {
mutableStateOf(Offset.Zero)
}
var lastOffset by remember() {
mutableStateOf(Offset.Zero)
}
val animatedOffset = remember {
Animatable(Offset(0f, 0f), Offset.VectorConverter)
}
val pxValue = with(LocalDensity.current) {
40.dp.toPx() } / 2f
CommonToolbar(navCtrl, title) {
Box(modifier = Modifier
.fillMaxSize()
.background(color = Color.Magenta)
.pointerInput(Unit) {
coroutineScope {
while (true) {
val offset = awaitPointerEventScope {
awaitFirstDown().position
}
lastOffset = cacheOffset
cacheOffset = offset
launch {
animatedOffset.animateTo(
offset,
animationSpec = spring(stiffness = Spring.StiffnessLow)
)
}
}
}
}
.drawBehind {
drawCircle(color = currentPositionColor, radius = pxValue, center = cacheOffset)
drawCircle(color = lastPositionColor, radius = pxValue, center = lastOffset)
}
) {
Box(
Modifier
.offset {
IntOffset(
(animatedOffset.value.x - pxValue).roundToInt(),
(animatedOffset.value.y - pxValue).roundToInt()
)
}
.size(40.dp)
.background(MaterialTheme.colors.primary, CircleShape)
)
}
}
}
边栏推荐
- 一款自动生成单元测试的 IDEA 插件
- 2021-06-07
- Effect evaluation of regression model under credit product quota pricing scenario
- Force deduction solution summary 513- find the value of the lower left corner of the tree
- [datahub] LinkedIn datahub learning notes
- How to make food nutrition label
- 5分钟快速上线Web应用和API(Vercel)
- Self inspection is recommended! The transaction caused by MySQL driver bug is not rolled back. Maybe you are facing this risk!
- 进销存软件排行榜前十名!
- ACM Player Illustration leetcode remove element
猜你喜欢

如何使用笔记软件 FlowUs、Notion 进行间隔重复?基于公式模版

SQL注入漏洞(原理篇)

Tencent ECS failed to send email

百万奖金等你来拿,首届中国元宇宙创新应用大赛联合创业黑马火热招募中!

狂奔的极兔,摔了一跤

Auto - vérification recommandée! Les bogues MySQL ne font pas reculer les transactions, peut - être êtes - vous à risque!

这届文娱人,将副业做成了主业

2021-04-15

The well-known face search engine provokes public anger: just one photo will strip you of your pants in a few seconds

小米为何深陷芯片泥潭?
随机推荐
The first public available pytorch version alphafold2 is reproduced, and Columbia University is open source openfold, with more than 1000 stars
Résumé de la méthode de déduction de la force 513 - trouver la valeur du coin inférieur gauche de l'arbre
When I went to oppo for an interview, I got numb...
2021-05-22
The second Tencent light · public welfare innovation challenge was launched, and the three competition topics focused on the social value of sustainable development
详解Redis分布式锁的原理与实现
General sequence representation learning in kdd'22 "Ali" recommendation system
How to make food nutrition label
Simple tutorial of live streaming with OBS
小米为何深陷芯片泥潭?
Golang-- judge whether the strings are equal
巴比特 | 元宇宙每日必读:Meta、微软等科技巨头成立元宇宙标准论坛组织,华为、阿里加入,英伟达高管称欢迎来自加密世界的参与者...
百萬獎金等你來拿,首届中國元宇宙創新應用大賽聯合創業黑馬火熱招募中!
等保備案是什麼意思?應該去哪裏辦理備案?
知名人脸搜索引擎惹众怒:仅需一张照片,几秒钟把你扒得底裤不剩
物流贸易相关
2021-05-08
建议自查!MySQL驱动Bug引发的事务不回滚问题,也许你正面临该风险!
Use of pyqt5 tool box
WebService interface publishing and calling