React Native(第二节点击事件)
来源:互联网 发布:淘宝华硕官方旗舰店 编辑:程序博客网 时间:2024/05/16 14:40
React Native的提供了四种点击事件
- TouchableHighlight
- TouchableNativeFeedback
- TouchableOpacity
- TouchableWithoutFeedback
TouchableHighlight
这是点击透明度发生变化
activeOpacity={0.7}
按下后背景颜色
underlayColor={'red'}
TouchableNativeFeedback
Android设备原生控件
TouchableOpacity
点击背景透明度变化activeOpacity={0.7}
TouchableWithoutFeedback
没有任何反馈效果的
React按钮的事件处理 按钮关联了四个事件:
1. 按钮按下事件:onPress - 按下并松开按钮,会触发该事件(相当于PC的onclick) 2. 按钮长按事件:onLongPress - 按住按钮不松开,会触发该事件(长按事件) 3. 按钮按下事件:onPressIn - 按下按钮不松开,会触发该事件(相当于PC的onkeydown) 4. 按钮松开事件:onPressOut - 按下按钮后松开,或按下按钮后移动手指到按钮区域外,都会触发该事件(相当于PC的onkeyup)
/** * Sample React Native App * https://github.com/facebook/react-native */'use strict';var React = require('react-native');var Button = require('react-native-button')var { AppRegistry, StyleSheet, ToastAndroid, Text, View, TouchableWithoutFeedback, TouchableHighlight, TouchableNativeFeedback, Image,} = React;var TestReactNative = React.createClass({ getInitialState: function() { ToastAndroid.show('哈哈哈哈哈', ToastAndroid.SHORT); return null; }, textOnclick:function() { ToastAndroid.show('点击了', ToastAndroid.SHORT); }, imageOnclick:function() { ToastAndroid.show('图片被点击了', ToastAndroid.SHORT); }, buttonOnclick:function() { ToastAndroid.show('Button被点击了', ToastAndroid.SHORT); }, //绘制视图 render: function() { return ( <View style={styles.container}> <TouchableWithoutFeedback onPress={() => this.textOnclick()}> <View> <Text style={styles.welcome}> Welcome </Text> </View> </TouchableWithoutFeedback> <TouchableWithoutFeedback onPress={() => this.imageOnclick()}> <Image source={{uri: 'http://c1.mifile.cn/f/i/15/item/buyphone/mi5-yin.jpg'}} style={styles.imageStyle}> </Image> </TouchableWithoutFeedback> <Button containerStyle={{padding:10, height: 45, overflow:'hidden', borderRadius:4, backgroundColor:'white', marginTop: 10}} style={{fontSize: 20, color: 'green'}} styleDisable={{color: 'red'}} onPress={this.buttonOnclick}> 这是一个按钮 </Button> <TouchableHighlight style={{marginTop:20}} //按下后背景透明度变化 activeOpacity={0.7} //按下后背景颜色 underlayColor={'red'} onPress={() => ToastAndroid.show('文本被点击了', ToastAndroid.SHORT)}> <Text style={{fontSize:23, color:'blue', backgroundColor:'white'}} > 这是一个文本(测试TouchableHighlight) </Text> </TouchableHighlight> <TouchableNativeFeedback background={TouchableNativeFeedback.SelectableBackground()} onPress={() => ToastAndroid.show('文本被点击了', ToastAndroid.SHORT)}> <View style={{marginTop:10}}> <Text style={{fontSize:23, color:'blue', backgroundColor:'white'}} > TouchableNativeFeedback </Text> </View> </TouchableNativeFeedback> </View> ); },});var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#ff3000', // flexDirection: 'column', }, welcome: { // flex: 1, width:200, //字体大小 fontSize: 20, textAlign: 'center', // margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, imageStyle:{ width: 200, height: 200, }});AppRegistry.registerComponent('TestReactNative', () => TestReactNative);
1 0
- React Native(第二节点击事件)
- React Native 第二天
- react native事件机制(Eventdispather)
- React Native中的事件
- React-native事件处理
- React Native 触摸事件
- React Native学习第二天
- 第二章、React-Native生命周期
- 【React Native 安卓开发】----(Flexbox布局)【第二篇】
- React Native scrollview滚动事件
- react-native监听Android(Android向RN发送事件)
- VS Code --第二大React Native 编辑器
- React native学习第二章:State
- 小度鱼(React-Native)
- React Native 学习 Android 点击事件
- react-native scrollView 中部分有用事件
- React Native 触摸事件处理详解
- React Native 触摸事件处理详解
- HDU1280——前m大的数
- Exercise thinking in java
- Shiro系列之Shiro+Spring MVC整合(Integration)
- c++程序设计笔记(7)
- iTween基础之Punch(摇晃)
- React Native(第二节点击事件)
- 获得当前所在的视图控制器的方法
- c++程序设计笔记(8)
- Android 快速开发系列 打造万能的ListView GridView 适配器
- google-benchmark 渐进学习
- 诡异的 "密码取回" 邮件问题
- myeclipse项目名称修改之后部署到tomcat仍然是旧名称
- Android TextInputLayout修改提示信息文字颜色
- 手机平板要兼顾,探究碎片