ReactNative一个自己撸的menu组件
来源:互联网 发布:主流监控软件 编辑:程序博客网 时间:2024/05/29 16:04
有群里的小伙伴需要一个类似qq的那种标题栏右边的menu组件 自己顺便写了一个 试试 方便以后用的 废话不多说 先上图
不会上传动图 实际效果是点击更多 弹出menu 有动画 再次点击 关闭menu 或者点击背景 也能关闭menu
直接贴代码 需要的拿去 直接跑 可以在这个基础上做更多的定制
/** * Created by wangqiang on 2017/7/27. */import React from 'react';import {View,Animated,Dimensions,Easing, Text, StyleSheet, TouchableOpacity} from 'react-native';export default class MenuDemo extends React.PureComponent { // 构造 constructor(props) { super(props); // 初始状态 this.state = { menu: new Animated.Value(0), flag: true }; } startAnimated() { Animated.timing(this.state.menu, { toValue: 1, duration: 300, easing: Easing.out(Easing.back()) }).start(() => { this.setState({ flag: !this.state.flag }) }); } stopAnimated() { Animated.timing(this.state.menu, { toValue: 0, duration: 300, easing: Easing.inOut(Easing.quad), }).start(() => { this.setState({ flag: !this.state.flag }) }); } onPress(e) { if (this.state.flag) { this.startAnimated(); } else { this.stopAnimated(); } } close(){ this.stopAnimated(); } render() { const mWidth = this.state.menu.interpolate({ inputRange: [0, 1], outputRange: [0, 130] }); const mHeight = this.state.menu.interpolate({ inputRange: [0, 1], outputRange: [0, 200] }); const mOpacity = this.state.menu.interpolate({ inputRange: [0, 1], outputRange: [0, 1] }); return ( <View style={styles.container}> <View style={styles.title}> <TouchableOpacity activeOpacity={0.8} style={styles.leftView} onPress={(e) => { this.onPress(e) }}> <Text style={styles.text}>更多</Text> </TouchableOpacity> </View> <Animated.View style={[styles.sanjiao, {opacity: mOpacity }]}> </Animated.View> <Animated.View style={[styles.menu, { width: mWidth, height: mHeight, opacity: mOpacity }]} > </Animated.View> <Animated.View style={[styles.back,{opacity:mOpacity}]}> <TouchableOpacity onPress={()=>{this.close()}} activeOpacity={1} style={{flex:1}} /> </Animated.View> </View> ) }}const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#fff', }, title: { height: 60, backgroundColor: 'red', }, leftView: { position: 'absolute', right: 20, bottom: 0, width:30, height:30, borderColor:'transparent' }, text: { color: '#fff' }, menu: { position: 'absolute', right: 5, top: 64, backgroundColor: '#fff', borderRadius: 5, zIndex:3, borderColor:'transparent' }, back:{ backgroundColor:'rgba(0,0,0,0.2)', flex:1, width:Dimensions.get('window').width, height:Dimensions.get('window').height, }, sanjiao:{ width:0, height:0, borderWidth:10, borderColor:'transparent', borderBottomColor:'#fff', position: 'absolute', top: 45, right: 25, zIndex:2, }});还是自己写的方便多 样式什么都好修改 我这个只是个最基础的 更深的功能需要你自己去扩展
阅读全文
0 0
- ReactNative一个自己撸的menu组件
- ReactNative的组件架构设计
- ReactNative的组件架构设计
- ReactNative – 组件的生命周期
- 自己写的一个参数封装组件
- 我自己写的一个表情组件
- 自己封装一个获取组件的方法
- 一个简单的ReactNative demo
- 记录一个ReactNative的问题
- Android组件的使用:Menu
- Android的context menu组件
- ReactNative开发之DrawerLayoutAndroid组件的使用
- ReactNative的Navigator组件使用方式
- ReactNative的Navigator组件使用方式
- ReactNative的Navigator组件使用方式
- reactNative中React组件的生命周期
- ReactNative开发——组件的引用
- ReactNative开发——组件的生命周期
- swift_031(Swift 中的枚举/原始值(RawValues))
- Android 通知栏Notification总结一:基本用法
- [MethodImpl(MethodImplOptions.Synchronized)]、lock(this)与lock(typeof(...))
- 解决ScrollView嵌套RecyclerView滑动卡顿问题
- 【Unity学习笔记】——射线应用,光点随鼠标移动
- ReactNative一个自己撸的menu组件
- linux常见脚本命令
- bootstrapTable行内编辑初始方案
- web.xml中DispatcherServlet排除静态资源的拦截 / 图片上传到了WEB-INF目录下,应该如何显示?
- JAVA中获取当前系统时间
- 2016届大学生半年度工作总结
- Intellij Idea 12 生成serialVersionUID的方法
- web项目运行时(如JSON parse)手动注入@Autowired等注解的属性值-1
- Win10系统PDF菜单栏隐藏了怎么恢复?acrobat菜单栏不见了的解决方法!