Commit 6a4fcea4 authored by Qiu Xiang's avatar Qiu Xiang

优化 android marker 事件处理

parent 8638f60f
......@@ -29,10 +29,10 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
return mapOf(
"onMarkerClick" to mapOf("registrationName" to "onMarkerClick"),
"onMarkerDragStart" to mapOf("registrationName" to "onMarkerDragStart"),
"onMarkerDrag" to mapOf("registrationName" to "onMarkerDrag"),
"onMarkerDragEnd" to mapOf("registrationName" to "onMarkerDragEnd"),
"onInfoWindowClick" to mapOf("registrationName" to "onInfoWindowClick"))
"onMarkerDragStart" to mapOf("registrationName" to "onDragStart"),
"onMarkerDrag" to mapOf("registrationName" to "onDrag"),
"onMarkerDragEnd" to mapOf("registrationName" to "onDragEnd"),
"onInfoWindowClick" to mapOf("registrationName" to "onInfoWindowPress"))
}
@ReactProp(name = "title")
......
import React, {PropTypes, Component} from 'react'
import {requireNativeComponent, View, Platform, StyleSheet} from 'react-native'
import React, {PropTypes, PureComponent} from 'react'
import {
requireNativeComponent,
View,
ViewPropTypes,
Platform,
StyleSheet,
} from 'react-native'
import {LatLng} from './PropTypes'
import Overlay from './Overlay'
export default class Marker extends Component {
export default class Marker extends PureComponent {
static propTypes = {
...View.propTypes,
...ViewPropTypes,
/**
* 坐标
......@@ -117,24 +123,14 @@ export default class Marker extends Component {
onInfoWindowPress: React.PropTypes.func,
}
_handle(name) {
return event => {
if (this.props[name]) {
this.props[name](event)
}
}
}
_onPress = event => this.props.onPress && this.props.onPress(event)
render() {
const props = {
...this.props,
...Platform.select({
android: {
onMarkerClick: this._handle('onPress'),
onMarkerDragStart: this._handle('onDragStart'),
onMarkerDrag: this._handle('onDrag'),
onMarkerDragEnd: this._handle('onDragEnd'),
onInfoWindowClick: this._handle('onInfoWindowPress'),
onMarkerClick: this._onPress,
},
})
}
......@@ -158,7 +154,7 @@ export default class Marker extends Component {
}
}
AMapMarker = requireNativeComponent('AMapMarker', Marker)
const AMapMarker = requireNativeComponent('AMapMarker', Marker)
const styles = StyleSheet.create({
overlay: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment