[React Native] State and Touch Events -- TextInput, TouchableHighLight
In React, components manage their own state. In this lesson, we'll walk through building a component which manages it's own state as well as using TextInput and TouchableHighlight to handle touch events.
import React, { Component, PropTypes } from 'react';
import { View, Text, StyleSheet, TextInput, TouchableHighlight, ActivityIndicatorIOS } from 'react-native';
var style = StyleSheet.create({
mainContainer: {
flex: 1,
padding: 30,
marginTop: 65,
flexDirection: 'column',
justifyContent: 'center',
backgroundColor: '#48BBEC'
},
title: {
marginBottom: 20,
fontSize: 25,
textAlign: 'center',
color: '#fff'
},
searchInput: {
height: 50,
padding: 4,
marginRight: 5,
fontSize: 23,
borderWidth: 1,
borderColor: 'white',
borderRadius: 8,
color: 'white'
},
buttonText: {
fontSize: 18,
color: '#111',
alignSelf: 'center'
},
button: {
height: 45,
flexDirection: 'row',
backgroundColor:'white',
borderColor:'white',
borderWidth:1,
borderRadius:8,
marginBottom:10,
alignSelf:'stretch',
justifyContent:'center'
}
});
export default class Main extends Component{
constructor(props){
super(props)
this.state = {
username: '',
isLoading: false,
error: false
};
}
handleChange(event){
this.setState({
username: event.nativeEvent.text
})
}
handleSubmit(event){
//update our indicatorIOS spinner
this.setState({
isLoading: true
});
console.log('submit', this.state.username);
//fetch data from github
//reroute to the next passing that github informaiton
}
render(){
return (
<View style={style.mainContainer}>
<Text style={style.title}>Search for a Github User</Text>
<TextInput
style={style.searchInput}
value={this.state.username}
onChange={this.handleChange.bind(this)}
/>
<TouchableHighlight
style={style.button}
onPress={this.handleSubmit.bind(this)}
underlayColor="white"
>
<Text style={style.buttonText}>SEARCH USER</Text>
</TouchableHighlight>
</View>
)
}
}

<TextInput
style={style.searchInput}
value={this.state.username}
onChange={this.handleChange.bind(this)}
/>
Search box, once value changed, set current username state.
<TouchableHighlight
style={style.button}
onPress={this.handleSubmit.bind(this)}
underlayColor="white"
>
Search button, a touch button, so not onClick event but onPress event.
underlayColor: When touch, change background color to white color.
[React Native] State and Touch Events -- TextInput, TouchableHighLight的更多相关文章
- [RN] React Native 键盘管理 在Android TextInput遮盖,上移等问题解决办法
React Native 键盘管理 在Android TextInput遮盖,上移等问题解决办法 解决办法: 打开android工程,在AndroidManifest.xml中配置如下: <ac ...
- React Native(十三)——ios键盘挡住textInput
渐入佳境 用React Native重构的项目也快接近尾声,剩下的就是适配ios的功能了.慢慢地也从中琢磨出了一点门道,于是就遇见了键盘遮挡textInput问题斑斑: 正常页面: android点击 ...
- [React Native]高度自增长的TextInput组件
之前我们学习了从零学React Native之11 TextInput了解了TextInput相关的属性. 在开发中,我们有时候有这样的需求, 希望输入区域的高度随着输入内容的长度而增长, 如下: 这 ...
- [React Native] Complete the Notes view
In this final React Native lesson of the series we will finalize the Notes view component and squash ...
- 📝 没 2 年 React Native 开发经验,你都遇不到这些坑
如果你喜欢我的文章,希望点赞 收藏 评论 三连支持一下,谢谢你,这对我真的很重要! React Native 开发时,如果只是写些简单的页面,基本上按着官方文档 reactnative.dev就能写出 ...
- [RN] 01 - Init: Try a little bit of React Native
Ref: React Native跨平台移动应用开发 后记:这本书博客味有点浓. 本篇涉及新建工程的若干套路,以及一点语法知识. 创建新工程 (1) 解决的一大核心问题: (2) 使用Javascri ...
- [RN] 02 - Overview: React Native Practice of 50 lectures
观看笔记:零基础 React Native 实战开发视频 50讲 本篇效果:RN入门,整体认识 基本原理 # 1 React到RN # 2 一个简单的例子 /** * Sample React Nat ...
- 给所有开发者的React Native详细入门指南
建议先下载好资料后,再阅读本文.demo代码和资料下载 目录 一.前言 二.回答一些问题 1.为什么写此教程 2.本文适合哪些人看 3.如何使用本教程 4.需要先学习JavaScript.HTML.C ...
- react native TextInput
今天我想说一下react native中的一个控件,TextInput 翻译过来就是文本输入,对应着android中的EditText.我们先看一下官方是怎样描述的.TextInput是一个允许用户在 ...
随机推荐
- php stdClass Object 问题
Array ( [0] => stdClass Object ( [term_id] => 3 [name] => apache [slug] => apache [term_ ...
- c# 提取word文件中的图片问题
最近遇到一个项目就是要从一份word中提取出所有的图片信息,功能看起来不是很难,只要使用office自带的Microsoft.Office.Interop.Word就可以解决问题.网上也有不少的文章来 ...
- 在SQL2005实现维护计划-备份数据库
一.備份數據庫維護計劃方案 [注]: 1.先啟動SQL Server Agent服務 2..交易記錄備份 (只限於完整和大量記錄復原模式). 3.下面中”清除備份trn文件” & “清除備份日 ...
- HDU5673 Robot 默慈金数
分析: 注:然后学了一发线性筛逆元的姿势 链接:http://blog.miskcoo.com/2014/09/linear-find-all-invert #include<iostream& ...
- HDU5647 DZY Loves Connecting 树形DP
(先奉上jcvb大神的官方题解)BC 76 div 1 1002 对于每个结点i,统计出f[i]表示包含i的连通集有多少个,那么容易看出答案就是所有f[i]的和. 要计算f[i]是经典的树形DP问题. ...
- python中的pth文件作用
python中有一个.pth文件,该文件的用法是: 首先xxx.pth文件里面会书写一些路径,一行一个. 将xxx.pth文件放在特定位置,则可以让python在加载模块时,读取xxx.pth中指定的 ...
- bootstrap-内联表单 水平(横向)表单 响应式图片 辅助类 [转]
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 【转】CUDA5/CentOS6.4
转载自http://wenzhang.baidu.com/article/view?key=076f36658dd0828c-1393896446 This article explains how ...
- 2015年9月28日html基础了解学习
数据库与C#都是在后台运行的逻辑,而html,css,js,jq是在网页前台显示的一些效果.后台要考虑到优化性能效率等等,而前台要吸引到客户,要有更好的客户体验. 通用化,还是效率更高,在做项目中是要 ...
- 【HTML】Intermediate2:Text: AbbreviationsQuotations Code
1.</abbr> attribute:title 2.Quotations blockquote :standalone often multi-line quotations-cite ...