React Native 之View组件的回调

前端之家收集整理的这篇文章主要介绍了React Native 之View组件的回调前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React,{ Component } from 'react';
import {
  AppRegistry,StyleSheet,Text,View
} from 'react-native';

export default class ViewProject extends Component {
  render() {
    return (
      <View style={styles.container}
        onTouchStart={this._onTouchStart}
        onTouchMove={this._onTouchMove}
        onTouchEnd={this._onTouchEnd}
      >
      </View>
    );
  }
  _onTouchMove(event){
   console.log("touch move:"+event.timeStamp+",X:"+event.nativeEvent.locationX+",Y:"+event.nativeEvent.locationY);
  }
  _onTouchStart(event){
   console.log("touch start:"+event.timeStamp+",Y:"+event.nativeEvent.locationY);
  }
  _onTouchEnd(event){
   console.log("touch end:"+event.timeStamp+",Y:"+event.nativeEvent.locationY);
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,backgroundColor:"#F5FCFF",}
});
AppRegistry.registerComponent('ViewProject',() => ViewProject);

在React Native 开发中,通常在最上层的组件中(render 函数靠后渲染的组件)处理触摸事件,但这三个回调函数总能收到事件,而不管用户当前触摸区域是空白的,还是其它组件以及处理了触摸事件。

猜你在找的React相关文章