当前位置: 首页 > 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,},
});

相关文章:

  • 基于微信小程序的美食点餐订餐系统
  • 【Dify学习笔记】:RagFlow接入Dify基础教程
  • Flowise工作流引擎的本地部署与远程访问实践
  • Python 操作 MySQL 数据库
  • EfficientVLA:面向视觉-语言-动作模型无训练的加速与压缩
  • Linux——linux的基本命令
  • 全面掌握 C++ 基础:关键特性与进化
  • 深入理解 Git:从版本控制原理到企业级实践
  • 医疗AI大数据处理流程的全面解析:从数据源到应用实践
  • 【世纪龙科技】智能网联汽车装调仿真教学软件数智化赋能实训教学
  • 有方 N58 LTE Cat.1 模块联合 SD NAND 贴片式 TF 卡 MKDV1GIL-AST,打造 T-BOX 高性能解决方案
  • 解锁数据宝藏:数据挖掘之数据预处理全解析
  • react扩展
  • Flutter ListTile 深度解析
  • 一[3.4]、ubuntu18.04环境 利用 yolov8n-seg实现“列车轨道”区域分割,并提取正确的轨道线【全网最详细】
  • 退出python解释器的四种方式
  • Flang:LLVM Fortran 前端简介
  • IPv4编址及IPv4路由基础
  • python画三维立体图
  • 【支持向量机】SVM线性可分支持向量机学习算法——硬间隔最大化支持向量机及例题详解
  • 网站如何静态化/专业网站推广引流
  • 网站建设的展望 视频/免费网站做seo
  • 学校网站建立/seoul是什么国家
  • 重庆十大装饰公司排名/北京seo公司工作
  • asp.net网站的404错误页面/郑州网站建设推广有限公司
  • 老客户网站建设/农产品营销方案