Skip to content

Commit

Permalink
perf:抖音、小红书 菜单优化
Browse files Browse the repository at this point in the history
  • Loading branch information
longer96 committed Oct 14, 2021
1 parent 4841bdf commit ee59df7
Showing 1 changed file with 7 additions and 46 deletions.
53 changes: 7 additions & 46 deletions lib/bottom/bottom9/bottom_app_bar_9.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ class _BottomBar9State extends State<BottomBar9> with TickerProviderStateMixin {
late AnimationController animationController;

/// 中间按钮 点击之后动画
late AnimationController centerBtnAnimationController;
late AnimationController centerBtnScaleAnimationController;

/// 底部子菜单动画
late Animation<double> animation;

@override
void initState() {
animationController = AnimationController(
Expand All @@ -52,30 +48,18 @@ class _BottomBar9State extends State<BottomBar9> with TickerProviderStateMixin {
centerBtnScaleAnimationController.addStatusListener((status) {
if (status == AnimationStatus.completed) {
centerBtnScaleAnimationController.reverse();
} else if (status == AnimationStatus.dismissed) {
/// 中间动画执行完毕,执行点击事件回调
widget.addClick();
}
});

centerBtnAnimationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 100 * 2),
);
centerBtnAnimationController.addStatusListener((status) {
debugPrint('longer >>> $status');
if (status == AnimationStatus.dismissed) {
if (!mounted) return;
}
});

animation = Tween<double>(begin: 0.0, end: 1.0).animate(CurvedAnimation(
parent: centerBtnAnimationController, curve: Curves.fastOutSlowIn));

super.initState();
}

@override
void dispose() {
animationController.dispose();
centerBtnAnimationController.dispose();
super.dispose();
}

Expand Down Expand Up @@ -144,30 +128,6 @@ class _BottomBar9State extends State<BottomBar9> with TickerProviderStateMixin {
);
}

Widget line() => Container(height: 20, width: 0.4, color: Colors.grey[400]);

Widget menuItem(String title, IconData iconData) {
return GestureDetector(
onTap: () {
debugPrint('点击了 >>> $title');
centerBtnAnimationController.reverse();
},
behavior: HitTestBehavior.opaque,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(iconData, size: 28, color: Color(0xff2b292b)),
const SizedBox(height: 4),
Text(title,
style: TextStyle(fontSize: 12, color: Color(0xff2b292b)))
],
),
),
);
}

/// 中间的按钮
Widget centerButton() {
return Container(
Expand All @@ -180,10 +140,11 @@ class _BottomBar9State extends State<BottomBar9> with TickerProviderStateMixin {
highlightColor: Colors.transparent,
focusColor: Colors.transparent,
onTap: () {
widget.addClick();
// 执行旋转动画 && 缩放动画
centerBtnAnimationController.forward();
/// 缩放动画
centerBtnScaleAnimationController.forward();

/// 振动
HapticFeedback.mediumImpact();
},
child: SizedBox(
width: 40,
Expand Down

0 comments on commit ee59df7

Please sign in to comment.