react动画

In the previous blog post, we covered all of the changes to the APIs related to going edge-to-edge:

在上一篇博客文章中,我们介绍了与边缘到边缘相关的所有API更改:

In this blog post we move forward on with the actual task of animating the keyboard. To demonstrate what is possible, here you can see an example of the same app, running on Android 10 on the left, and Android 11 on the right (at 20% speed):

在此博客文章中,我们将继续进行动画键盘的实际任务。 为了演示可能的方法,在这里您可以看到同一应用的示例,该应用在左侧的Android 10上运行,在右侧的Android 11上运行(速度为20%):

On devices running Android 10 and before, when the user clicks on the text input to type a reply, the keyboard animates into place, but the app snaps between the states. This is the behaviour you’ve seen on your devices for a while, it’s just easier to see at 20% speed.

在运行Android 10及更低版本的设备上,当用户单击输入的文本以键入回复时,键盘会自动设置动画,但是应用会在状态之间切换。 这是您一段时间以来在设备上看到的行为,以20%的速度查看更容易。

On the right you can see the same scenario running on Android 11. This time when the user clicks on the text input, the app moves with the keyboard, creating a more seamless experience.

在右侧,您可以看到在Android 11上运行的相同场景。 这次,当用户单击文本输入时,应用程序键盘一起移动,从而创建了更加无缝的体验。

So how can you add this experience to your app? Well it’s all powered by some new APIs…

那么如何将这种体验添加到您的应用程序中呢? 好吧,这一切都由一些新的API提供支持…

WindowInsetsAnimation (WindowInsetsAnimation)

The API which powers this in Android 11 is the new WindowInsetsAnimation class, which encapsulates an animation involving insets. Apps can listen to animation events through the WindowInsetsAnimation.Callback class, which can be set on a view:

Android 11中支持此功能的API是新的WindowInsetsAnimation类,该类封装了包含插图的动画。 应用程序可以通过WindowInsetsAnimation.Callback类收听动画事件,可以在视图上进行设置:

val cb = object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {// TODO
}view.setWindowInsetsAnimationCallback(cb)

So let’s just a look at the callback class, and the functions it provides:

因此,让我们看一下回调类及其提供的功能:

Imagine that the keyboard is currently closed, and the user has just clicked on an EditText. The system is now about to start showing the keyboard, and since we have a WindowInsetsAnimation.Callback set, we’ll receive the following calls in order:

想象一下,键盘当前处于关闭状态,并且用户刚刚单击了EditText 。 系统现在即将开始显示键盘,并且由于我们设置了WindowInsetsAnimation.Callback ,因此WindowInsetsAnimation.Callback顺序接收以下调用:

val cb = object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {override fun onPrepare(animation: WindowInsetsAnimation) {// #1: First up, onPrepare is called which allows apps to record any// view state from the current layout}// #2: After onPrepare, the normal WindowInsets will be dispatched to// the view hierarchy, containing the end state. This means that your// view's OnApplyWindowInsetsListener will be called, which will cause// a layout pass to reflect the end state.override fun onStart(animation: WindowInsetsAnimation,bounds: WindowInsetsAnimation.Bounds):  WindowInsetsAnimation.Bounds {// #3: Next up is onStart, which is called at the start of the animation.// This allows apps to record the view state of the target or end state.return bounds}override fun onProgress(insets: WindowInsets,runningAnimations: List<WindowInsetsAnimation>): WindowInsets {// #4: Next up is the important call: onProgress. This is called every time// the insets change in the animation. In the case of the keyboard, which// would be as it slides on screen.return insets}override fun onEnd (animation: WindowInsetsAnimation) {// #5: And finally onEnd is called when the animation has finished. Use this// to clear up any old state.}
}

So that’s how the callback works in theory, now let’s apply it to a scenario…

因此,从理论上讲,这就是回调的工作方式,现在让我们将其应用于场景中……

实施示例 (Implementing the example)

We’re going to use WindowInsetsAnimation.Callback to implement the example which you saw at the beginning of this blog post. So lets start implementing our callback:

我们将使用WindowInsetsAnimation.Callback来实现您在本博文开头看到的示例。 因此,让我们开始实现我们的回调:

onPrepare() (onPrepare())

First we’ll override onPrepare(), and record the bottom coordinate of the view, before any layout changes have happened:

首先,我们将重写onPrepare() ,并在发生任何布局更改之前记录视图的底部坐标

val view = binding.conversationListval cb = object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {var startBottom = 0var endBottom = 0override fun onPrepare(animation: WindowInsetsAnimation) {// #1: First up, onPrepare is called which allows apps to record any// view state from the current layout. We record the bottom of the view// in the windowstartBottom = view.calculateBottomInWindow()}
}

插页调度 (Insets dispatch)

At this point, the end-state insets will be dispatched, and our OnApplyWindowInsetsListener called. Our listener updates the padding of the container view, which results in the content being pushed up.

此时,将调度最终状态插入,并调用我们的OnApplyWindowInsetsListener 。 我们的监听器会更新容器视图的填充,从而导致内容被上推。

The user never sees this though as we’ll see below.

用户将永远不会看到它,如下所示。

onStart() (onStart())

Next we have our onStart() function, which first allows us to record the end position of the view.

接下来,我们有onStart()函数,该函数首先允许我们记录视图的结束位置。

We also visually shift the view back down to its original position using translationY, as we don’t want the user to see the end state right now. The user doesn’t see a flicker, as the system guarantees that any layout triggered from the inset pass above is called in the same frame as onStart().

我们还可以使用translationY直观地将视图移回其原始位置,因为我们不希望用户现在看到结束状态。 用户看不到闪烁,因为系统保证从上述插入过程触发的任何布局都在与onStart()相同的帧中onStart()

val view = binding.conversationListval cb = object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {var startBottom = 0var endBottom = 0override fun onStart(animation: WindowInsetsAnimation,bounds: WindowInsetsAnimation.Bounds):  WindowInsetsAnimation.Bounds {// #3: Next up is onStart, which is called at the start of the animation.// We record the bottom of the view within the windowendBottom = view.calculateBottomInWindow()// And then we translate the view back down, so it is visually// in the start positionview.translationY = startBottom - endBottom// We don't alter the bounds so just pass the value given to usreturn bounds}
}

onProgress() (onProgress())

Finally we override onProgress() which allows us to update our view as the keyboard slides in.

最后,我们重写onProgress() ,它允许我们在键盘滑入时更新视图。

We use translationY again, interpolating between the start and end states to move the view in unison with the keyboard.

我们再次使用translationY ,在开始状态和结束状态之间进行插补,以与键盘一致地移动视图。

val view = binding.conversationListval cb = object : WindowInsetsAnimation.Callback(DISPATCH_MODE_STOP) {var startBottom = 0var endBottom = 0override fun onProgress(insets: WindowInsets,runningAnimations: List<WindowInsetsAnimation>): WindowInsets {// #4: Next up is the important call: onProgress. This is called every time// the insets change in the animation.// We calculate the the offset for our view by linearly interpolating from// the start position, to the end position, using the animation's fractionval offset = lerp(startBottom - endBottom,0,animation.interpolatedFraction)// ...which we then set using translationYview.translationY = offsetreturn insets}
}

键盘协同 (Keyboard synergy)

And with that, we have achieved synchronization between the keyboard and the app’s views. If you would like to see a fully implementation, check out the WindowInsetsAnimation sample:

这样,我们就实现了键盘和应用程序视图之间的同步。 如果您希望看到完整的实现,请查看WindowInsetsAnimation示例:

Let us know on Twitter or the comments below if you add this to your app, and how you found it!

如果您将此添加到您的应用程序中,以及如何找到它,请在Twitter或下面的评论中告诉我们!

In the next blog post we will explore how your apps can control the keyboard, allowing things like list scrolling to automatically open the keyboard. Stay tuned!

在下一篇博客文章中,我们将探讨您的应用程序如何控制键盘,允许列表滚动之类的操作自动打开键盘。 敬请关注!

查看剪裁 (View clipping)

If you try and implement this in your own views you may find that the techniques we talked about in this blog post can lead to view’s being clipped as they are animated. This is because we are translating views which may have been resized through the layout changes from your OnApplyWindowInsetsListener.

如果您尝试在自己的视图中实现此功能,则可能会发现我们在本博文中讨论的技术可能会导致视图被动画化时被裁剪。 这是因为我们正在翻译可能已通过OnApplyWindowInsetsListener的布局更改来调整大小的OnApplyWindowInsetsListener

We will explore in a future blog post how to combat this, but for now I recommend looking through the WindowInsetsAnimation sample, which contains one technique to avoid it.

我们将在以后的博客文章中探讨如何解决此问题,但是现在我建议您浏览WindowInsetsAnimation示例,该示例包含一种避免这种情况的技术。

翻译自: https://medium.com/androiddevelopers/animating-your-keyboard-reacting-to-inset-animations-839be3d4c31b

react动画


http://www.taodudu.cc/news/show-5741011.html

相关文章:

  • ViewDragHelper(二)- 源码及原理解读(进阶篇)
  • Java 微服务框架选型(Dubbo 和 Spring Cloud?)
  • 在 openEuler 上通过 KubeEdge+iSulad 搭建云边协同集群
  • android GridView 在TV上,上下翻页的时候平滑滑动的实现
  • Create Apps with Material Design
  • Python 爬虫实战5 模拟登录淘宝并获取所有订单
  • 【数据分析】个人购物记录采集和可视化分析
  • 记录我在北上广做淘宝的日子
  • 你一定要收藏的全网最完整CAD快捷键大全!三
  • 笔记本外接的显示器突然不能用,显示无信号
  • 笔记本外接屏幕,怎么独立显示,怎么变换鼠标移动方向
  • 联想小新pro13笔记本外接显示屏没信号
  • 联想小新笔记本外接显示屏HDMI无信号
  • 笔记本外接显示屏什么意思
  • 关于笔记本外接显示屏相关问题的解决办法
  • python画五角星填充版
  • python123绘制五角星_Python的画五角星
  • css3五角星绘制,如何用CSS3画五角星
  • 从GitHub上面下载zip压缩包很慢怎么办
  • PHP下载压缩包,提示损坏或者无法打开
  • php案例:打包压缩包并下载
  • conda更新安装github下载的本地压缩包(zip)
  • 重装windows 11系统
  • 重装系统要注意什么问题
  • 重装系统 (小白版)
  • 适合小白的重装系统方式
  • 苹果手机7服务器是什么系统版本,iPhone7 Plus的手机系统是什么
  • 苹果高通携手推人脸识别!手机指纹识别将被打入冷宫
  • 苹果手机: A7双核指纹识别 国行iphone5S跌至4299元
  • 为 iOS APP 添加手机密码、指纹验证

react动画_动画键盘(第2部分):对WindowInset动画做出React相关推荐

  1. python做flash帧动画_[练习]利用CSS steps 实现逐帧动画

    网页逐帧动画的实现方式 网页中的逐帧动画,大致可分为两大类的实现方式, 分别是使用JS控制,和单纯使用CSS实现,两者的优劣总体概括来说就是: JS动画可控性更强,但开销大,实现复杂. CSS动画实现 ...

  2. react安装_超全面详细一条龙教程!从零搭建React项目全家桶(上篇)

    React是近几年来前端项目开发非常火的一个框架,其背景是Facebook团队的技术支持,市场占有率也很高.很多初学者纠结一开始是学react还是vue.个人觉得,有时间的话,最好两个都掌握一下.从学 ...

  3. lottie 动画_使用After Effects和Lottie制作网络动画而不会损失质量

    lottie 动画 A quick getting started guide 快速入门指南 I recently took on a project where the team wanted to ...

  4. ae制h5文字动画_对于8个华丽的HTML5文字动画特效图文赏析

    文字是网页的灵魂,很早以前有人发明了很多漂亮的计算机字体,这让网页变得样式各异.HTML5和CSS3的出现,我们可以让文字变得更加富有个性,在一些需要的场合,我们甚至可以利用HTML5制作文字动画.本 ...

  5. svg配合css3动画_如何使用CSS制作节日SVG图标动画

    svg配合css3动画 正是这个季节,因此在本教程中,我将逐步创建一些CSS动画,以假日为主题的SVG图标. Iconmelon上有一些很棒的图标,该网站上有许多免费的矢量图标集,可让您尽其所能 . ...

  6. 前端css动画_很棒的前端资源和CSS动画课程

    前端css动画 This is the editorial from our latest HTML/CSS Channel newsletter, you can subscribe here. 这 ...

  7. android刷新时的圆形动画_【Android UI】自定义圆形Loading动画

    1.创建环形loading图片 android:fromDegrees="0" android:toDegrees="360" android:pivotX=& ...

  8. js svg语音波动动画_让动效更酷炫!4 个常见且常用的 SVG 交互动画方法

    本文介绍了 4 种常见的 SVG 交互动画方法,帮你了解 SVG 交互动画的原理和简单方法. 优秀的人机交互和舒适合理的动画,一直是 UX 设计师孜孜不倦追求的目标.但 UX 设计师每天都遇到能做出效 ...

  9. 【web前端特效源码】使用HTML5+CSS3+JavaScript制作一个复古手机键盘(带声音)的动画效果~~适合初学者~超简单~

    b站视频演示效果: [web前端特效源码]使用HTML5+CSS3制作一个复古手机键盘(带声音)的动画效果~~适合初学者~超简单~ |前端开发|IT软件 效果图: 完整代码: <!DOCTYPE ...

  10. css定格动画_使用StopGo创建定格动画

    css定格动画 上个月,我们用Krita观看了数字单元动画 . 不过,单元动画只是一种动画,因此本月我们将看一下定格动画. 作为一项附加功能,由于过去几周重点介绍了DIY项目,因此该应用程序产生的动画 ...

最新文章

  1. 每日一问 - 关于决策树算法
  2. 零基础带你快速入门Ribbon技术(浅显易懂、小白都能看懂)
  3. 《编译原理》实验报告——TINY语言的词法分析
  4. 学习《css世界》笔记之使用css实现凹凸效果
  5. php导出csv_原生PHP实现导出csv格式Excel文件的方法示例【附源码下载】
  6. 复述-软考网规--云计算专题
  7. java嵌套类中的方法怎么调用_java类与嵌套嵌套后,怎么使用最外层的类建立对象后使用内部类的方法?...
  8. 哈啰单车失窃数十辆 盗窃者竟有摩拜员工!只因其又新又好骑...
  9. ClickHouse在字节跳动推荐和广告业务部门的最佳实践
  10. String(+) vs StringBuffer(append)
  11. springboot mybatis 事务_真香——Github上的优秀SpringBoot框架
  12. 深化代理模式,Mybaits如何做到调用接口
  13. ENVI学习总结(十一)——NDVI的计算
  14. PostgreSQL之Foreign Data Wrappers使用指南
  15. 60.Linux:虚拟机安装及基本操作
  16. openmp 互斥锁 mysql_OpenMP(四)线程同步之互斥锁函数
  17. iPad PPT演示录屏踩坑及后续ffmpeg处理
  18. python 拟合圆_OpenCV曲线拟合与圆拟合
  19. 程序员数学(15)--分式
  20. A New Voyage

热门文章

  1. c语言 字符串数组 初始化,C 字符串数组初始化问题
  2. 1-appium-初识
  3. GaiaWorld:区块链行业生态初具雏形
  4. USB打印机改成无线打印
  5. python 实现矩阵旋转
  6. Python前景如何?学会Python工作好找吗?
  7. GAN属于计算机视觉领域嘛_【图像上色小综述】生成对抗网络的GAN法
  8. Flask后端笔记(三)Jinja2模板、过滤器、表单、宏、模板继承、包含
  9. 最近华为内部的这篇文章火了!社会内卷的真正原因
  10. jspxcms 4.0 mysql 5.0_Jspxcms网站内容管理系统 安装包 v6.0.1