react-native实现搜索栏渐过渡动画
来源:互联网 发布:小说地图制作软件 编辑:程序博客网 时间:2024/09/21 06:33
实现效果:
代码
import React, {Component} from 'react';import { Animated, Easing, View, StyleSheet, TouchableOpacity, TextInput} from 'react-native';var Dimenions = require('Dimensions');var Width = Dimenions.get('window').width;export default class Ours extends Component { constructor() { super(); this.animatedValue = new Animated.Value(0); this.state = { hidden: true, currentAlpha: 0, inputText: '', placeholder: '', opacity: 1, } } Animate() { this.state.currentAlpha = this.state.currentAlpha == 0 ? 1 : 0;//判断动画运动起止状态 this.setState({ opacity: 1 }); // this.animatedValue.setValue(0); Animated.timing( this.animatedValue, { toValue: this.state.currentAlpha, duration: 300, easing: Easing.linear } ).start(); if (this.state.currentAlpha == 0) { this.refs.textInput.blur(); this.setState({ inputText: '', }); } } //获取焦点 _Focus() { this.refs.textInput.focus(); } //提示文字消失 _Opacity(text) { this.setState({ inputText: text, opacity: 0 }); } render() { const ViewWidth = this.animatedValue.interpolate({ inputRange: [0, 1], outputRange: [Width * 0.9, Width * 0.8] }); const Opacity = this.animatedValue.interpolate({ inputRange: [0, 1], outputRange: [0, 1] }); const marginLeft = this.animatedValue.interpolate({ inputRange: [0, 1], outputRange: [Width * 0.3, Width * 0.1] }); return ( <View style={styles.container}> <View style={styles.search}> <TouchableOpacity onPress={this.Animate.bind(this)} style={styles.image}> <Animated.Text style={{ opacity: Opacity }}>取消</Animated.Text> </TouchableOpacity> <Animated.View style={{ height: 35, width: ViewWidth, backgroundColor: '#efefef', position: 'absolute', top: 0, borderRadius: 10, left: 10 }} /> <TextInput style={styles.inputs} onFocus={this.Animate.bind(this)} underlineColorAndroid='transparent' // placeholder= "请输入搜索关键字" ref="textInput" onChangeText={this._Opacity.bind(this)} value={this.state.inputText} /> <TouchableOpacity style={styles.ProText} onPress={this._Focus.bind(this)}> <Animated.Text style={{ left: marginLeft, opacity: this.state.opacity }}> 请输入搜索关键字 </Animated.Text> </TouchableOpacity> </View> </View> ); }}const styles = StyleSheet.create({ container: { flex: 1, position: 'relative', top: 10 }, search: { height: 35, width: Width, position: 'relative', top: 0, }, ProText: { width: Width * 0.8, position: 'absolute', top: 6, left: 0, }, image: { width: Width * 0.1, height: Width * 0.1, position: 'absolute', top: 10, right: Width * 0.035, }, inputs: { width: Width * 0.7, height: 30, borderWidth: 1, paddingLeft: 5, borderColor: '#efefef', borderRadius: 4, position: 'absolute', left: Width * 0.05, top: 4 },});
阅读全文
0 0
- react-native实现搜索栏渐过渡动画
- React Native 之 动画
- 详解React Native动画
- 详解React Native动画
- [React Native]动画-LayoutAnimation
- [React Native]动画-Animated
- React Native动画-Animated
- React Native LayoutAnimation动画
- React Native Animated动画
- react-native-动画
- React Native 动画 ---Animated
- react native动画
- 搜索框和导航栏(React Native)
- [java]过渡动画实现
- React-Native进阶_7.TextInput的使用实现搜索功能
- 只需4个步骤:使用 React 实现页面过渡动画
- react-native-Art动画基础
- react-native-Art动画基础
- kylin报错 java.lang.ArrayIndexOutOfBoundsException: -1
- xutils3使用方法
- Go实战--golang生成uuid(The way to go)
- dtree中点击节点跳转相应的action
- leetcode 453. Minimum Moves to Equal Array Elements
- react-native实现搜索栏渐过渡动画
- python 数字和字符串转换问题
- thinkphp3.2 实用的函数index
- 数据库优化
- 【maven】项目增加jetty插件
- 安装sql server管理工具
- SOCKET.IO,理解SOCKET.IO
- UNIX网络编程卷1:套接字联网API-第2章:传输层 TCP/UDP和SCTP
- Huffman哈夫曼编码译码器(文件输入输出流)C语言(C++)