当前位置: 首页 > news >正文

React Native【实战范例】弹跳动画菜单导航

最终效果

在这里插入图片描述

范例代码

import React, { useEffect, useRef, useState } from "react";
import {Animated,Easing,StyleSheet,Text,TouchableOpacity,View,
} from "react-native";
export default function Demo() {const width1 = useRef(new Animated.Value(200)).current;const width2 = useRef(new Animated.Value(64)).current;const width3 = useRef(new Animated.Value(64)).current;const width4 = useRef(new Animated.Value(64)).current;const [index, setIndex] = useState(0);useEffect(() => {anim1(index === 0);anim2(index === 1);anim3(index === 2);anim4(index === 3);}, [index]);const anim1 = (isOpen) => {Animated.timing(width1, {toValue: isOpen ? 200 : 64,duration: isOpen ? 500 : 300,easing: isOpen ? Easing.elastic(3) : Easing.ease,useNativeDriver: false,}).start();};const anim2 = (isOpen) => {Animated.timing(width2, {toValue: isOpen ? 200 : 64,duration: isOpen ? 500 : 300,easing: isOpen ? Easing.elastic(3) : Easing.ease,useNativeDriver: false,}).start();};const anim3 = (isOpen) => {Animated.timing(width3, {toValue: isOpen ? 200 : 64,duration: isOpen ? 500 : 300,easing: isOpen ? Easing.elastic(3) : Easing.ease,useNativeDriver: false,}).start();};const anim4 = (isOpen) => {Animated.timing(width4, {toValue: isOpen ? 200 : 64,duration: isOpen ? 500 : 300,easing: isOpen ? Easing.elastic(3) : Easing.ease,useNativeDriver: false,}).start();};return (<View style={styles.root}><TouchableOpacityactiveOpacity={0.8}onPress={() => {setIndex(0);}}><Animated.Viewstyle={[styles.view,{ width: width1, opacity: index === 0 ? 1 : 0.75 },]}><Text style={styles.txt} numberOfLines={1} ellipsizeMode="clip">首页推荐</Text><View style={styles.dot} /></Animated.View></TouchableOpacity><TouchableOpacityactiveOpacity={0.8}onPress={() => {setIndex(1);}}><Animated.Viewstyle={[styles.view,{ width: width2, opacity: index === 1 ? 1 : 0.75 },]}><Text style={styles.txt} numberOfLines={1} ellipsizeMode="clip">热门直播</Text><View style={styles.dot} /></Animated.View></TouchableOpacity><TouchableOpacityactiveOpacity={0.8}onPress={() => {setIndex(2);}}><Animated.Viewstyle={[styles.view,{ width: width3, opacity: index === 2 ? 1 : 0.75 },]}><Text style={styles.txt} numberOfLines={1} ellipsizeMode="clip">我的礼物</Text><View style={styles.dot} /></Animated.View></TouchableOpacity><TouchableOpacityactiveOpacity={0.8}onPress={() => {setIndex(3);}}><Animated.Viewstyle={[styles.view,{ width: width4, opacity: index === 3 ? 1 : 0.75 },]}><Text style={styles.txt} numberOfLines={1} ellipsizeMode="clip">个人信息</Text><View style={styles.dot} /></Animated.View></TouchableOpacity></View>);
}
const styles = StyleSheet.create({root: {width: "100%",height: "100%",backgroundColor: "white",flexDirection: "column",justifyContent: "center",},view: {height: 60,flexDirection: "row",alignItems: "center",marginVertical: 16,borderTopRightRadius: 28,borderBottomRightRadius: 28,backgroundColor: "#2030ff",paddingLeft: 16,overflow: "hidden",},img: {width: 32,height: 32,tintColor: "white",},txt: {fontSize: 18,color: "#ffffffD0",marginLeft: 16,},dot: {width: 10,height: 10,backgroundColor: "#20f020",marginLeft: 28,borderRadius: 5,},
});
http://www.lqws.cn/news/451963.html

相关文章:

  • 学习threejs,三维汽车模拟器,场景有树、云、山等
  • Nginx-Ingress-Controller自定义端口实现TCP/UDP转发
  • 大数据系统架构实践(一):Zookeeper集群部署
  • 局域网投屏工具(将任何设备转换为计算机的辅助屏幕)Deskreen
  • LVS负载均衡群集:Nginx+Tomcat负载均衡群集
  • Lora训练
  • 项目管理利器:甘特图的全面解析与应用指南
  • 计算机网络八股第二期
  • net程序-Serilog 集成 SQL Server LocalDB 日志记录指南
  • 有方 N58 LTE Cat.1 模块联合 SD NAND 贴片式 TF 卡 MKDV1GIL-AST,打造 T-BOX 高性能解决方案
  • 如何在WordPress中添加导航菜单?
  • 基于 CNN-LSTM-GRU 架构的超音速导弹轨迹高级预测
  • Redis如何解决缓存击穿,缓存雪崩,缓存穿透
  • 技术革新赋能楼宇自控:物联网云计算推动应用前景深度拓展
  • 饼图:数据可视化的“切蛋糕”艺术
  • 搜索二叉数(c++)
  • 【Leetcode】字符串之二进制求和、字符串相乘
  • PCB板高速飞拍检测系统 助力电子制造自动化领域
  • idea中push拒绝,merge,rebase的区别
  • C++ 单例模式一种实现方式
  • Cesium、ThreeWebGL详解(二)渲染引擎向GPU传数据、性能优化、引擎对比
  • 使用 C++/OpenCV 构建中文 OCR 系统:实现账单、发票及 PDF 读取
  • 云计算处理器选哪款?性能与能效的平衡艺术
  • 动态WCMP+Flowlet ALB:双引擎驱动智算网络负载均衡
  • 【Pandas】pandas DataFrame explode
  • shel脚本重启Jar服务
  • 对接世界职业院校技能大赛标准,唯众打造高质量物联网实训室
  • 第二章 SQL编程系列-SQL编程基础
  • 人力资源战略重构,AI驱动高质量发展论坛顺利召开
  • OpenGL和OpenGL ES区别