前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >短视频软件开发,实现搜索栏逐渐过渡动画

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

原创
作者头像
yunbaokeji柯基
修改2020-12-16 14:44:49
5130
修改2020-12-16 14:44:49
举报
文章被收录于专栏:直播知识

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

代码语言:javascript
复制
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
    },
});

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
实时音视频
实时音视频(Tencent RTC)基于腾讯21年来在网络与音视频技术上的深度积累,以多人音视频通话和低延时互动直播两大场景化方案,通过腾讯云服务向开发者开放,致力于帮助开发者快速搭建低成本、低延时、高品质的音视频互动解决方案。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档