ReactNative-触摸事件
生活随笔
收集整理的這篇文章主要介紹了
ReactNative-触摸事件
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
鏈接:http://blog.csdn.net/u014360817/article/details/52410563
在ReactNative好像只有在Text組件中支持觸摸事件其默認(rèn)是不支持觸摸事件的ReactNative給我們提供幾個API以供組件支持觸摸:TouchableOpacity,TouchableHighlight,TouchableNativeFeedback,TouchableWithoutFeedback,?
這里使用方法一樣只是反饋效果有點(diǎn)差別,這里只演示TouchableOpacity.
經(jīng)常用到的觸摸回調(diào)函數(shù):?
–onPressIn:點(diǎn)擊開始;?
–onPressOut:點(diǎn)擊結(jié)束或者離開;?
–onPress:單擊事件回調(diào);?
–onLongPress:長按事件回調(diào)。
使用方法只需將需要使用觸摸功能的組件包裹即可
/*** Created by gaocai on 16/9/2.*/ import React, {Component} from 'react'; import {AppRegistry,StyleSheet,Text,View,TouchableOpacity,TouchableHighlight,TouchableNativeFeedback,TouchableWithoutFeedback, } from 'react-native'class TouchG extends Component {render() {return (<View><TouchableOpacity//當(dāng)開始按下時調(diào)用onPressIn={() => console.log('onPressIn')}//當(dāng)松開時調(diào)用onPressOut={() => console.log('onPressOut')}//當(dāng)按下時調(diào)用onPress={() => console.log('onPress')}//當(dāng)長按時調(diào)用onLongPress={() => console.log('onLogPress')}><View style={{width: 100, height: 100, backgroundColor: 'red'}}/></TouchableOpacity><Text//當(dāng)開始按下時調(diào)用onPressIn={() => console.log('onPressIn')}//當(dāng)松開時調(diào)用onPressOut={() => console.log('onPressOut')}//當(dāng)按下時調(diào)用onPress={() => console.log('onPress')}//當(dāng)長按時調(diào)用onLongPress={() => console.log('onLogPress')}>Text支持點(diǎn)擊</Text></View>)} }module.exports = TouchG;- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
這里只是簡單介紹下觸摸事件的使用,詳細(xì)可看以下博客:
http://www.race604.com/react-native-touch-event/
http://www.reactnative.pw/reactnative%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A30-21/panresponder.html
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎
總結(jié)
以上是生活随笔為你收集整理的ReactNative-触摸事件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ReactNative-WebView组
- 下一篇: ReactNative(API)Aler