短视频软件开发,实现搜索栏逐渐过渡动画

简介: 短视频软件开发,实现搜索栏逐渐过渡动画

短视频软件开发,实现搜索栏逐渐过渡动画相关的代码

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
    },
 
});

以上就是短视频软件开发,实现搜索栏逐渐过渡动画相关的代码, 更多内容欢迎关注之后的文章

目录
相关文章
|
3月前
|
小程序
【经验分享】使用swiper组件制作文字上下滚动播报效果
【经验分享】使用swiper组件制作文字上下滚动播报效果
58 0
|
5月前
|
前端开发
移动端开发——京东首页制作(流式布局)
移动端开发——京东首页制作(流式布局)
|
9月前
|
C++ Python
|
自然语言处理 C++
制作有道词典——标题栏
制作有道词典——标题栏
制作有道词典——标题栏
|
XML API Android开发
酷炫的Activity切换动画,打造更好的用户体验
酷炫的Activity切换动画,打造更好的用户体验
酷炫的Activity切换动画,打造更好的用户体验
抖音那种一道光闪过转场效果是怎么做的?(1)
抖音那种一道光闪过转场效果是怎么做的?
391 0
抖音那种一道光闪过转场效果是怎么做的?(1)
|
XML Android开发 数据格式
开发App抽屉功能,彻底掌握了吗?
在平时开发中,带有抽屉效果的App,应该还是挺多,今天就来看看这个效果是如何实现的,我们用DrawerLayout控件来实现!
233 0
开发App抽屉功能,彻底掌握了吗?
|
XML Android开发 数据格式
直播电商软件开发,拖动条自定义背景,进度条颜色
直播电商软件开发,拖动条自定义背景,进度条颜色
220 0
直播APP源码开发,改变字体颜色
直播APP源码开发,改变字体颜色
194 0