截图如下:

/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/ import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
AlertIOS,
} from 'react-native'; // ES5写法
var ViewDemo = React.createClass({ getInitialState(){ return{
title: '不透明触摸'
}
},
render() {
return ( <View style={styles.container} onPress = {this.rendPress()}> <TouchableOpacity activeOpacity = {0.2}
onPress = {()=>this.activeEvent('点击了啦!!!')}
onPressin = {()=>this.activeEvent('按下了啦!!!')}
onPressout = {()=>this.activeEvent('抬起了啦!!!')}
onLongPress = {()=>this.activeEvent('长按了啦!!!')}
>
<View style = {styles.innerStyle}>
<Text>点击事件</Text>
</View>
</TouchableOpacity>
<View>
<Text>{this.state.title}</Text>
</View>
</View>
);
}, // ,号在ES5必须写,ES6可以不写 // 当按下鼠标
rendPress(){
AlertIOS.alert('点击了')
},
activeEvent(event){
this.setState({
title: event
})
}
}); // ES6写法 /*
class ViewDemo extends Component { render() {
return ( <View style={styles.container} onPress = {this.rendPress()}> <TouchableOpacity activeOpacity = {0.2}>
<View style = {styles.innerStyle}>
<Text>我是文本,但是可以点击!!!</Text>
</View>
</TouchableOpacity>
</View>
);
} // 当按下鼠标
rendPress(){
AlertIOS.alert('点击了')
}
}
*/ const styles = StyleSheet.create({
container: { backgroundColor: 'green', // 设置背景颜色
width: , // 宽度
height: // 高度 最后一个样式的,可以不写,其余的必须写,不然报错
},
innerStyle: {
backgroundColor: 'red',
width: ,
height: ,
marginTop: ,
},
innerStyle1: {
backgroundColor: 'yellow',
width:
},
}); AppRegistry.registerComponent('ViewDemo', () => ViewDemo);

代码如下:

React Native中Touchable组件的使用的更多相关文章

  1. React Native 中吐司组件react-native-easy-toast

    https://github.com/crazycodeboy/react-native-easy-toast 用法: import Toast from 'react-native-easy-toa ...

  2. React Native中加载指示器组件ActivityIndicator使用方法

    这里讲一下React Native中的一个组件——ActivityIndicator,这是一个加载指示器,俗称菊花,很常见的,效果如下所示: 可以看到图中有两个加载指示器,一大一小,这是尺寸不是我设置 ...

  3. React Native中组件的props和state

    一.组件的属性(props)和状态(state) 1.属性(props) 它是组件的不可变属性(组件自己不可以自己修改props). 组件自身定义了一组props作为对外提供的接口,展示一个组件时只需 ...

  4. React Native 之 Touchable 介绍与使用

    前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...

  5. [转] 「指尖上的魔法」 - 谈谈 React Native 中的手势

    http://gold.xitu.io/entry/55fa202960b28497519db23f React-Native是一款由Facebook开发并开源的框架,主要卖点是使用JavaScrip ...

  6. react native 触摸Touchable***的区别(TouchableWithoutFeedback、TouchableOpacity、TouchableHighlight、TouchableNativeFeedback)

    一.问题背景: react native的跨平台开发没有button的概念,而是使用touchable系列实现点击触发效果. 而touchable系列就有四个之多,而且相互之间仍有较大差别,这就给我们 ...

  7. react native之组织组件

    这些组件包括<TabView>,<NavigatorView>和<ListView>,他们实现了手机端最常用的交互和导航.你会发现这些组件在实际的项目中会非常有用. ...

  8. React Native之Image组件

    同 HTML 的 img 元素一样,React Native 提供的 Image 组件可以用来显示各种途径的图片,比如网络图片.本地图片.照相机图片等. 虽然效果是一样的.然而用法还是有区别的. 1. ...

  9. 在React Native中,使用fetch网络请求 实现get 和 post

    //在React Native中,使用fetch实现网络请求 /* fetch 是一个封装程度更高的网络API, 使用了Promise * Promise 是异步编程的一种解决方案 * Promise ...

随机推荐

  1. 【转】Everything you need to know about NoSQL databases

    原文: https://dev.to/lmolivera/everything-you-need-to-know-about-nosql-databases-3o3h ---------------- ...

  2. python dict list 遍历的几种常见方法

    list 遍历index,value list = ['one', 'two', 'three'] for i in list: print(list.index(i),i) #rangefor i ...

  3. 关于IO的同步,异步,阻塞,非阻塞

    上次写了一篇文章:Unix IO 模型学习.恰巧在这次周会的时候,@fp1203 (goldendoc成员之一) 正好在讲解poll和epoll的底层实现.中途正好讨论了网络IO的同步.异步.阻塞.非 ...

  4. FFmpeg常用命令学习笔记(一)基本信息查询命令

    笔者才开始学习音视频开发,FFmpeg学习笔记系列主要是从慕课网李超老师的FFmpeg音视频核心技术精讲与实战课程学习的心得体会. FFmpeg音视频核心技术精讲与实战:https://coding. ...

  5. 04—mybatis的关联映射

    mybatis的关联映射一对一一对多多对多 一.一对一(一个人只能有一个身份证号) 1.创建表创建表tb_card CREATE TABLE `tb_card` ( `id` int(11) NOT ...

  6. setup elk with docker-compose

    version: '2' services: elasticsearch: image: docker.calix.local:18080/docker-elasticsearch:6.2.2-1 c ...

  7. Java中的集合List、ArrayList、Vector、Stack(三)

    List接口 List集合代表一个有序集合,集合中每一个元素都有其对应的顺序索引.List集合容许使用重复元素,可以通过索引来访问指定位置的集合对象. ArrayList和Vector实现类 Arra ...

  8. javascript---查找节点

    快捷键: chazhaojiedian(查找节点)     chuangjianjiedian(创建节点) 使用childNodes childElementCount//=====以下是第一种操作D ...

  9. vue 解析时表达式闪烁的问题

    现象: 在使用 vuejs.angularjs 开发时,经常会遇见浏览器页面闪现表达式 ({{ express }} ), 或者是模块(div)的闪烁. 原因: 由于 JavaScript 去操作DO ...

  10. C语言位运算题解

    #include <stdio.h> #include <stdlib.h> #include <string.h> //#define NONBLANK 1 ma ...