ReactNative Demo -SearchInput


  import React, {
    Component
  } from 'react';
  import {
    AppRegistry,
    StyleSheet,
    Text,
    View,
    Image,
    ListView,
    PixelRatio,
    TextInput,
    TouchableHighlight,
    TouchableOpacity,
    TouchableWithoutFeedback,
  } from 'react-native';

  var onePT = 1 / PixelRatio.get();
  class AwesomeProject extends Component {


    render() {



      return (
       
        <View style={[styles.flex,styles.topStatus]}>
          <Search></Search>
        </View>
          
      );


    }
  }



 class Search extends Component{
   //show button this.state
   //view 显示的值

   constructor(props) {
     super(props);
     this.state={
       show: false,
       value: null,
     };
   }

   hide(val){
     this.setState(
       {
         show:false,
         value:val,
       }
     );
   }

   getValue(text) {
     this.setState(
       {
         show:true,
         value:text,
       }
     );
   }


   showalert(text) {
     alert(text);
   }
   
   render(){
      return(
        <View style={styles.flex}>
          <View style={[styles.flexDirection]}>
            <View style={[styles.flex,styles.input]}>
            <TextInput 
                placeholder="请输入关键词" keyboardType="web-search" returnKeyType="search" value={this.state.value} onChangeText={this.getValue.bind(this)}></TextInput>
            </View>
            <View style={styles.btn}> 
              <Text style={styles.search} onPress={this.hide.bind(this,this.state.value)}>搜索</Text>
            </View>
          </View>
          {this.state.show ?
            <View style={styles.result}>
               <Text style={styles.item} onPress={this.hide.bind(this,this.state.value + '张传伟QQ')}  numberOfLines={1}>{this.state.value}张传伟QQ</Text>
               <Text style={styles.item} onPress={this.hide.bind(this,this.state.value + '大神')}  numberOfLines={1}>{this.state.value}大神</Text>
               <Text style={styles.item} onPress={this.hide.bind(this,this.state.value + '工程师')}  numberOfLines={1}>{this.state.value}工程师</Text>
               <Text style={styles.item} onPress={this.hide.bind(this,this.state.value + '张小王子')}  numberOfLines={1}>{this.state.value}小王子</Text>
            </View>
            :null

          }

          <View>
            <TouchableHighlight onPress={this.showalert.bind(this,'React Native')} underlayColor='#fa00a0'>
              <Text style={styles.item}>zcw qq 602927062@qq.com</Text>
            </TouchableHighlight>

            <TouchableOpacity onPress={this.showalert.bind(this,'React Native zcw')} >
              <Text style={styles.item}>作者:zcwfeng</Text>
            </TouchableOpacity>

            <TouchableWithoutFeedback onPress={this.showalert.bind(this,'React Native zcw Feedback')} >
              <View><Text style={styles.item}>作者:zcwfeng123</Text></View>
            </TouchableWithoutFeedback>
          </View> 
        
        </View>
        );
    }
 }




  const styles = StyleSheet.create({
    flex: {
      flex:1,
    },

    
    flexDirection :{
      flexDirection:'row',
    },

    topStatus : {
      marginTop : 25,
    } ,

    input:{
      height:45,
      borderColor:'red',
      borderWidth: 1,
      marginLeft:10,
      
      borderRadius:5,
      paddingLeft:10,
    },
    
    btn:{
      height:45,
      width:45,
      marginLeft:-5,
      marginRight:5,
      backgroundColor:'#23BEFF',
      alignItems:'center', 
      justifyContent:'center',
      
    },
    search:{
      color:'#fff',
      fontWeight:'bold',
      fontSize:15,
    },
    result:{
      marginTop:onePT,
      marginLeft:18,
      marginRight:5,
      height:200,

    },
    item:{
    fontSize:16,
    paddingTop:5,
    paddingBottom:10,
    },

  });
  
 

  AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

转载请注明出处:http://www.jianshu.com/u/c864df301e25

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,087评论 25 709
  • 前些日子从@张鑫旭微博处得一份推荐(Front-end-tutorial),号称最全的资源教程-前端涉及的所有知识...
    谷子多阅读 9,734评论 0 44
  • 随着时间的流逝,真担心妈妈的年轻与健康也会被时间带走。别等了,就趁母亲节,和妈妈一起规划她的健康,让时间慢慢走。 ...
    钟升龙阅读 3,034评论 0 0
  • 1 什么是“王阳明时刻” “王阳明时刻”是罗胖在《罗辑思维》中提出来的概念。看过那一期节目的同学应该已经知道了,在...
    w王大铭阅读 6,490评论 2 4
  • 现在的我已经回到上海了,回程依旧延误,8点的航班一直到11点才飞,一下飞机,感觉热浪扑面而来,身上迅速黏哒哒起来,...
    wwwuyf阅读 3,411评论 0 0