截图如下:

/**
* 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. 上传时excel类型accept的MIMI类型

    1.excel文件类型 accept='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/v ...

  2. Navicat Premium 12连接mysql-8.0.15-winx64 出现2059异常

    错误

  3. InheritableThreadLocal——父线程传递本地变量到子线程的解决方式及分析

    转自https://blog.csdn.net/hewenbo111/article/details/80487252 上一个博客提到ThreadLocal变量的基本使用方式,可以看出ThreadLo ...

  4. [Cypress] Use the Most Robust Selector for Cypress Tests

    Which selectors your choose for your tests matter, a lot. In this lesson, we'll see the recommended ...

  5. 基于steam的游戏销量预测 — PART 1 — 爬取steam游戏相关数据的爬虫

    语言:python 环境:ubuntu 爬取内容:steam游戏标签,评论,以及在 steamspy 爬取对应游戏的销量 使用相关:urllib,lxml,selenium,chrome 解释: 流程 ...

  6. git log/show/HEAD step(2)

    git log can see all commit log #git logcommit 2737cfa37f81810072f074dcf19964be0a5eea2e (HEAD -> m ...

  7. 图论小专题B

    2 树 2.1 树的定义 一个只有\(N-1\)条边,且任意两个点连通的图叫做树.通过这样定义的树往往是一棵无根树,而我们通常会任意选定一个根节点使其变成有根树.有根树可以定义"父亲和儿子& ...

  8. The JAVA_HOME environment variable is not defined correctly的错误

    The JAVA_HOME environment variable is not defined correctlyThis environment variable is needed to ru ...

  9. volatile写读的内存语义

    1,当写一个volatile变量时,JMM(java内存模型)会把该线程本地内存中的所有共享变量刷新到主内存中去 2,当读取一个volatile变量时,该线程会将本地内存置为无效,线程将从主内存中读取 ...

  10. 第二届强网杯部分题writeup

    0x00 题目名称 签到 操作内容:   FLAG值: flag{welcome_to_qwb} 0x01 题目名称 Weclome 操作内容: 通过查看文件发现是一个bmp格式的图片文件,然后加上后 ...