本文原创发布在华为开发者社区。
介绍
本项目实现了点击、滑动都可实现Tab切换动效,包含文字切换。
效果预览
使用说明
安装完成后可以通过点击、滑动查看效果。
实现思路
切换动画开始与结束时触发回调。
.onAnimationStart((index: number, targetIndex: number, event: TabsAnimationEvent) => { // 切换动画开始时触发该回调。下划线跟着页面一起滑动,同时宽度渐变。 this.currentIndex = targetIndex let targetIndexInfo = this.getTextInfo(targetIndex) this.startAnimateTo(this.animationDuration, targetIndexInfo.left, targetIndexInfo.width) }) .onAnimationEnd((index: number,event: TabsAnimationEvent) => { // 切换动画结束时触发该回调。下划线动画停止。 let currentIndicatorInfo = this.getCurrentIndicatorInfo(index,event) this.startAnimateTo(0,currentIndicatorInfo.left,currentIndicatorInfo.width) })
在页面跟手滑动过程中,逐帧触发该回调。
.onGestureSwipe((index: number,event: TabsAnimationEvent) => { let currentIndicatorInfo = this.getCurrentIndicatorInfo(index,event) this.currentIndex = currentIndicatorInfo.index this.indicatorLeftMargin = currentIndicatorInfo.left this.indicatorWidth = currentIndicatorInfo.width })
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。