饿了么 顶部搜索框下拉动画小效果

效果描述:当下拉的时候渐变产生对固定的搜索框

import React, { Component } from "react";
import { connect } from "react-redux";
import {
    Container,
    Header,
    Title,
    Content,
    Button,
    Icon,
    Left,
    Right,
    Body,
    FlatList,
} from "native-base";
import {
    Dimensions,
    Image,
    Animated,
    ListView,
    PixelRatio,
    StyleSheet,
    ScrollView,
    Text,
    View,
    TextInput,
    TouchableOpacity,
    Modal,
    LayoutAnimation,
    Platform,
    RefreshControl,
    TouchableWithoutFeedback
} from "react-native"
import Echarts from ‘native-echarts‘;
var deviceHeight = Dimensions.get(‘window‘).height;
var deviceWidth = Dimensions.get(‘window‘).width;
import common from ‘../../../widgets/common‘;
import LoadingModal from ‘../../../widgets/loading‘;
const isIOS = Platform.OS == "ios"
const { width, height } = Dimensions.get(‘window‘)
const headH = 140
const InputHeight = 28
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
class FServer extends Component {
    static navigationOptions = {
        header: null
    };
    constructor(props) {
        super(props);
        this.state =  {
          scrollY: new Animated.Value(0),
          searchView: new Animated.Value(0),
          modalVisible: false,
          searchBtnShow: true,
          listLoading: false,
          isRefreshing: false
        };
        //第一个透明度的变化
        this.SEARCH_BOX_Y = 48
        this.SEARCH_FIX_Y = headH-64
        this.SEARCH_KEY_P = 58
        this.SEARCH_DIFF_Y = this.SEARCH_FIX_Y-this.SEARCH_BOX_Y
    }
    _onRefresh(){
        this.setState({isRefreshing: true});
        setTimeout(() => {
          this.setState({isRefreshing: false});
        }, 2000)
      }
  _renderHeader(){
    let lbsOpaticy = this.state.scrollY.interpolate({
      inputRange: [0, this.SEARCH_BOX_Y],
      outputRange: [1, 0]
    })
    let searchY = this.state.scrollY.interpolate({
      inputRange: [0, this.SEARCH_BOX_Y, this.SEARCH_FIX_Y, this.SEARCH_FIX_Y],
      outputRange: [0, 0, this.SEARCH_DIFF_Y, this.SEARCH_DIFF_Y]
    })
    let keyOpaticy = this.state.scrollY.interpolate({
        inputRange: [0, this.SEARCH_BOX_Y, this.SEARCH_KEY_P],
        outputRange: [1, 1, 0]
      })
  return (
    <View style={styles.header}>
      <Animated.View style={[styles.lbsWeather, {opacity: lbsOpaticy,}]}>
          <View style={styles.lbs}>
            <Text style={{fontSize: 18, fontWeight: ‘bold‘, color:"#fff", paddingHorizontal: 5}}>太平洋企业中心</Text>
          </View>
        <View style={styles.weather}>
          <View style={{marginRight: 5}}>
            <Text style={{color: "#fff", fontSize: 11, textAlign: "center"}}>{"3°"}</Text>
            <Text style={{color: "#fff", fontSize:11}}>{"阵雨"}</Text>
          </View>
        </View>
      </Animated.View>

      <Animated.View style={{
          marginTop:15,
          transform: [{
            translateY: searchY
          }]
        }}>
            <View style={[styles.searchBtn, {backgroundColor: "#fff"}]}>
              <Text style={{fontSize: 13, color:"#666", marginLeft: 5}}>{"输入商家,商品名称"}</Text>
            </View>
      </Animated.View>

      <Animated.View style={[styles.keywords, {opacity: keyOpaticy}]}>
      {
        [‘肯德基‘,‘烤肉‘,‘吉野家‘,‘粥‘,‘必胜客‘,‘一品生煎‘,‘星巴克‘].map((item, i) => {
          return (
            <TouchableWithoutFeedback key={i}>
              <View style={{marginRight: 12}}>
                <Text style={{fontSize: 12, color:"#fff"}}>{item}</Text>
              </View>
            </TouchableWithoutFeedback>
          )
        })
      }
    </Animated.View>
    </View>
  )
}
 _renderFixHeader(){
    let showY = this.state.scrollY.interpolate({
      inputRange: [0, this.SEARCH_BOX_Y, this.SEARCH_FIX_Y, this.SEARCH_FIX_Y,this.SEARCH_FIX_Y],
      outputRange: [-9999, -9999, 0, 0,0]
    })
    return (
      <Animated.View style={[styles.header, {
        position: "absolute",
        left: 0,
        right: 0,
        top: 0,
        bottom:0,
        height: 64,
        paddingTop: 25,
        transform: [
          {translateY: showY}
        ]
      }]}>
        <TouchableWithoutFeedback onPress={()=>{}}>
          <View style={[styles.searchBtn, {backgroundColor: "#fff"}]}>

            <Text style={{fontSize: 13, color:"#666", marginLeft: 5}}>{"输入商家,商品名称"}</Text>
          </View>
        </TouchableWithoutFeedback>
      </Animated.View>
    )
  }
    render() {
        return (
          <View style={{backgroundColor:‘#fff‘}}>
              <ScrollView
                onScroll={Animated.event(
                  [{nativeEvent: {contentOffset: {y: this.state.scrollY}}}]
                )}
                scrollEventThrottle={16}
                refreshControl={
                  <RefreshControl
                    refreshing={this.state.isRefreshing}
                    onRefresh={this._onRefresh.bind(this)}
                    tintColor="#0398ff"
                    title="拼命加载中..."
                  />
                }
              >
                {this._renderHeader()}
                <View style={{height:1000}}>
                </View>
              </ScrollView>
              {this._renderFixHeader()}
          </View>
        );
    }
}
const styles = StyleSheet.create({
  header: {
    backgroundColor: "#0398ff",
    height: headH,
    paddingTop: 30,
    paddingHorizontal: 16
  },
  typesView: {
    paddingBottom: 10,
    flex: 1,
    backgroundColor: "#fff",
    flexDirection: "row",
    flexWrap: "wrap"
  },
  typesItem: {
    backgroundColor: "#fff",
    justifyContent: "center",
    alignItems: "center"
  },
  lbsWeather: {
    height: InputHeight,
    overflow: "hidden",
    flexDirection: "row",
    justifyContent: "space-between"
  },
  placeholder: {
    height: InputHeight,
    position: "absolute",
    left: 0,
    top: 0,
    right: 0,
    borderRadius: 14,
    backgroundColor: "#fff",
    alignItems: "center"
  },
  lbs: {
    flexDirection: "row",
    justifyContent: "center",
    alignItems: "center"
  },
  weather: {
    flexDirection: "row",
    alignItems: "center"
  },
  textInput:{
    flex: 1,
    fontSize: 13,
    paddingLeft: 10,
    paddingRight: 10,
    height: InputHeight,
    borderRadius: 14,
    backgroundColor: "#fff"
  },
  searchHeadBox: {
    height: InputHeight,
    flexDirection: "row",
    alignItems: "center"
  },
  searchBtn: {
    borderRadius: InputHeight,
    height: InputHeight,
    flexDirection: "row",
    backgroundColor: "#fff",
    justifyContent: "center",
    alignItems: "center"
  },
  keywords: {
    marginTop: 14,
    flexDirection: "row"
  },
  recom: {
    flexDirection: "row",
    backgroundColor: "#fff",
    marginTop: 10,
    flexWrap: "wrap"
  },
  card: {
    backgroundColor: "#fff",
    marginTop: 10,
    paddingHorizontal: 16,
    paddingVertical: 16
  },
  business: {
    backgroundColor: "#fff",
    marginTop: 10,
    paddingVertical: 16
  },
  time: {
    paddingHorizontal: 3,
    backgroundColor: "#333",
    fontSize: 11,
    color: "#fff",
    marginHorizontal: 3
  },
  recomItem: {
    width: width/2,
    height: 70,
    backgroundColor: "#fff",
    alignItems: "center",
    flexDirection: "row"
  },
  recomWrap: {
    flex: 1,
    height: 70,
    paddingHorizontal: 16,
    backgroundColor: "#fff",
    flexDirection: "row",
    justifyContent: "space-between",
    alignItems: "center"
  },
  lTimeScrollView: {
  },
  lTimeList: {
    backgroundColor:"#fff",
    alignItems: "center"
  },
  qtag: {
    fontSize: 12,
    borderWidth: 1,
    color: "#00abff",
    borderColor: "#00abff",
    paddingHorizontal: 4,
    paddingVertical: 3,
    borderRadius: 5
  },
  gift: {
    flex: 1,
    justifyContent: "space-between",
    alignItems: "center",
    flexDirection: "row",
    backgroundColor: "#fff"
  },
  fixSearch: {
    backgroundColor: "#0398ff",
    height: isIOS ? 64 : 42,
    paddingTop: isIOS ? 20 : 0,
    paddingHorizontal: 16,
    position: "absolute",
    left: 0,
    right: 0,
    top: 0
  }
})

export default FServer;
时间: 2024-10-06 12:16:34

饿了么 顶部搜索框下拉动画小效果的相关文章

360浏览器搜索框下拉选择图片js模拟select效果

最近360浏览器网址导航的主页增加了一个下拉选择图片搜索的功能,也就是用js模拟出了select的效果,今天在单位闲了无事干,就把空上功能给摸索出来了,虽然做的不是太完善,但对要求不高的用户来说,已经可以了,而且也可以为学习Js的朋友提供参考. <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>

UI中经常出现的下拉框下拉自动筛选效果的实现

小需求是当你在第一个下拉框选择了国家时,会自动更新第二个省份的下拉框,效果如下 两个下拉选择Html如下: <select id="country_select"> <option> All Countries</option> <option> Afghanistan</option> <option> Albania</option> <option> Algeria</optio

jqGrid的搜索框下拉

当需要在jqGrid的搜索框里配置搜索条件时,如下拉,日期等,代码如下: 1 datePick = function(elem) 2 { 3 jQuery(elem).datepicker();4 } 1 colNames : [ "OP_ID", "OP_Module", "OP_Type", "OP_Content", "Operator", "OperatorType", &quo

行内表单 在统一行显示搜索框 下拉框 按钮

05===> 在同一行显示 搜索表单 下拉框表单 搜索按钮 清空按钮 使用了[行内表单] inline 属性可以让表单域变为行内的表单域 (让表单显示在同一行) <el-form ref="formInline" :inline="true" :model="formInline" class="demo-form-inline"></el-form> demo-form-inline是自带的 f

自定义SWT控件三之搜索功能下拉框

3.搜索功能下拉弹出框 package com.view.control.select; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import log.HikLog; import org.apache.commons.lang3.StringUtils; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLa

Android 使用动画效果后的控件位置处理 类似系统通知栏下拉动画

Android的动画的使用,请参考.Android的动画,在设计方面,我有点不太理解,觉得这样搞很怪,因为在控件动画后,即使设置了停留在动画结束时的位置,我们也确实看到了控件停在那个位置,但其实该控件的真实位置还是在原来动画前的那里.举个例子,如果有个Button,你给它设置了动画,让它移动到其他位置,当移动完成后,你会发现,点击Button没有任何效果,而在Button原来的位置,就是动画前的位置点击,明明没有任何控件,却看到了点击Button的效果.不知道Google为什么要这样设计.解决思

JavaScript---网络编程(11)--DHTML技术演示(4)-单选框/下拉菜单/添加文件

本节讲述单选框/下拉菜单/添加文件,综合css,html和JavaScript. 单选框: 实现的功能是:(类似平时的性格测试) 先隐藏一部分页面,然后通过点击单选框来显示. 再通过选项的选择-(每个选项有不同的积分)积分的多少来给出评语 演示代码: <html> <head> <title>DHTML技术演示---radio的使用</title> <meta http-equiv="content-Type" content=&q

iOS快速集成搜索界面下拉菜单框架

前言 这次推出的控件,比较常用,搜索界面下拉菜单,如果喜欢我的文章,可以关注我微博:吖了个峥,也可以来小码哥,了解下我们的iOS培训课程.后续还会更新更多内容,有任何问题,欢迎简书留言峥吖... Demo效果: 效果图.gif Demo演示: 1.创建下拉菜单 YZPullDownMenu *menu = [[YZPullDownMenu alloc] init]; menu.frame = CGRectMake(0, 20, YZScreenW, 44); [self.view addSubv

【android开发】使用PopupWindow实现页面点击顶部弹出下拉菜单

没有太多花样,也没有很复杂的技术,就是简单的PopupWindow的使用,可以实现点击弹出一个自定义的view,view里可以随便设计,常用的可以放一个listview. demo中我只是一个点击展示,简单的使用了fade in out的动画效果,也没有精美的图片资源,看着也丑,不过这么短的时间,让你掌握一个很好用的技术,可以自己扩展,不很好么? 废话不说了,直接上代码: MainActivity.java [java] view plaincopy public class MainActiv