Commit 4f47386b authored by 7c00's avatar 7c00

优化事件传递

parent c35dece1
......@@ -3,6 +3,7 @@ package cn.qiuxiang.react.amap3d
import android.view.View
import com.amap.api.maps.model.LatLng
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.annotations.ReactProp
......@@ -27,12 +28,13 @@ internal class AMapMarkerManager : ViewGroupManager<AMapMarker>() {
}
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
return mapOf(
"onMarkerClick" to mapOf("registrationName" to "onMarkerClick"),
"onMarkerDragStart" to mapOf("registrationName" to "onDragStart"),
"onMarkerDrag" to mapOf("registrationName" to "onDrag"),
"onMarkerDragEnd" to mapOf("registrationName" to "onDragEnd"),
"onInfoWindowClick" to mapOf("registrationName" to "onInfoWindowPress"))
return MapBuilder.of(
"onPress", MapBuilder.of("registrationName", "onPress"),
"onDragStart", MapBuilder.of("registrationName", "onDragStart"),
"onDrag", MapBuilder.of("registrationName", "onDrag"),
"onDragEnd", MapBuilder.of("registrationName", "onDragEnd"),
"onInfoWindowPress", MapBuilder.of("registrationName", "onInfoWindowPress")
)
}
@ReactProp(name = "title")
......
......@@ -16,7 +16,7 @@ internal class AMapPolylineManager : ViewGroupManager<AMapPolyline>() {
}
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
return mapOf("onPolylineClick" to mapOf("registrationName" to "onPolylineClick"))
return mapOf("onPress" to mapOf("registrationName" to "onPress"))
}
@ReactProp(name = "coordinates")
......
......@@ -37,14 +37,14 @@ class AMapView(context: Context) : TextureMapView(context) {
val event = Arguments.createMap()
event.putDouble("latitude", latLng.latitude)
event.putDouble("longitude", latLng.longitude)
emit(id, "onMapClick", event)
emit(id, "onPress", event)
}
map.setOnMapLongClickListener { latLng ->
val event = Arguments.createMap()
event.putDouble("latitude", latLng.latitude)
event.putDouble("longitude", latLng.longitude)
emit(id, "onMapLongClick", event)
emit(id, "onLongPress", event)
}
map.setOnMyLocationChangeListener { location ->
......@@ -52,21 +52,21 @@ class AMapView(context: Context) : TextureMapView(context) {
event.putDouble("latitude", location.latitude)
event.putDouble("longitude", location.longitude)
event.putDouble("accuracy", location.accuracy.toDouble())
emit(id, "onLocationChange", event)
emit(id, "onLocation", event)
}
map.setOnMarkerClickListener { marker ->
emit(markers[marker.id]?.id, "onMarkerClick")
emit(markers[marker.id]?.id, "onPress")
false
}
map.setOnMarkerDragListener(object : AMap.OnMarkerDragListener {
override fun onMarkerDragStart(marker: Marker) {
emit(markers[marker.id]?.id, "onMarkerDragStart")
emit(markers[marker.id]?.id, "onDragStart")
}
override fun onMarkerDrag(marker: Marker) {
emit(markers[marker.id]?.id, "onMarkerDrag")
emit(markers[marker.id]?.id, "onDrag")
}
override fun onMarkerDragEnd(marker: Marker) {
......@@ -74,26 +74,26 @@ class AMapView(context: Context) : TextureMapView(context) {
val data = Arguments.createMap()
data.putDouble("latitude", position.latitude)
data.putDouble("longitude", position.longitude)
emit(markers[marker.id]?.id, "onMarkerDragEnd", data)
emit(markers[marker.id]?.id, "onDragEnd", data)
}
})
map.setOnCameraChangeListener(object: AMap.OnCameraChangeListener {
override fun onCameraChangeFinish(position: CameraPosition?) {
emitCameraChangeEvent("onCameraChangeFinish", position)
emitCameraChangeEvent("onStatusChangeComplete", position)
}
override fun onCameraChange(position: CameraPosition?) {
emitCameraChangeEvent("onCameraChange", position)
emitCameraChangeEvent("onStatusChange", position)
}
})
map.setOnInfoWindowClickListener { marker ->
emit(markers[marker.id]?.id, "onInfoWindowClick")
emit(markers[marker.id]?.id, "onInfoWindowPress")
}
map.setOnPolylineClickListener { polyline ->
emit(polylines[polyline.id]?.id, "onPolylineClick")
emit(polylines[polyline.id]?.id, "onPress")
}
map.setInfoWindowAdapter(AMapInfoWindowAdapter(context, markers))
......@@ -113,7 +113,7 @@ class AMapView(context: Context) : TextureMapView(context) {
data.putDouble("rotation", it.bearing.toDouble())
data.putDouble("latitude", it.target.latitude)
data.putDouble("longitude", it.target.longitude)
if (event == "onCameraChangeFinish") {
if (event == "onStatusChangeComplete") {
val southwest = map.projection.visibleRegion.latLngBounds.southwest
val northeast = map.projection.visibleRegion.latLngBounds.northeast
data.putDouble("latitudeDelta", Math.abs(southwest.latitude - northeast.latitude))
......
......@@ -6,6 +6,7 @@ import com.amap.api.maps.CameraUpdateFactory
import com.amap.api.maps.model.LatLng
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.ViewGroupManager
import com.facebook.react.uimanager.annotations.ReactProp
......@@ -50,14 +51,15 @@ internal class AMapViewManager : ViewGroupManager<AMapView>() {
}
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
return mapOf(
"onMapClick" to mapOf("registrationName" to "onPress"),
"onMapLongClick" to mapOf("registrationName" to "onLongPress"),
"onAnimateCancel" to mapOf("registrationName" to "onAnimateCancel"),
"onAnimateFinish" to mapOf("registrationName" to "onAnimateFinish"),
"onCameraChange" to mapOf("registrationName" to "onStatusChange"),
"onCameraChangeFinish" to mapOf("registrationName" to "onStatusChangeComplete"),
"onLocationChange" to mapOf("registrationName" to "onLocation"))
return MapBuilder.of(
"onPress", MapBuilder.of("registrationName", "onPress"),
"onLongPress", MapBuilder.of("registrationName", "onLongPress"),
"onAnimateCancel", MapBuilder.of("registrationName", "onAnimateCancel"),
"onAnimateFinish", MapBuilder.of("registrationName", "onAnimateFinish"),
"onStatusChange", MapBuilder.of("registrationName", "onStatusChange"),
"onStatusChangeComplete", MapBuilder.of("registrationName", "onStatusChangeComplete"),
"onLocation", MapBuilder.of("registrationName", "onLocation")
)
}
@ReactProp(name = "locationEnabled")
......
// @flow
import React, {PropTypes, PureComponent} from 'react'
import {
ViewPropTypes,
UIManager,
requireNativeComponent,
findNodeHandle,
} from 'react-native'
import {LatLng} from './PropTypes'
export default class Drive extends PureComponent {
static propTypes = {
...ViewPropTypes,
/**
* 路径规划成功事件
*/
onCalculateRouteSuccess: React.PropTypes.func,
/**
* 路径规划失败事件
*/
onCalculateRouteFailure: React.PropTypes.func,
}
/**
* 路线规划
*/
calculateRoute(start, end, way = []) {
this._sendCommand('calculateRoute', [start, end, way])
}
/**
* 开始导航
*/
start() {
this._sendCommand('start')
}
/**
* call native method
*
* @private
*/
_sendCommand(command: string, params?: []) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.AMapDrive.Commands[command],
params,
)
}
render() {
return <AMapDrive {...this.props}/>
}
}
const AMapDrive = requireNativeComponent('AMapDrive', Drive)
import React, {PropTypes, PureComponent} from 'react'
import {
Platform,
requireNativeComponent,
StyleSheet,
View,
ViewPropTypes,
Platform,
StyleSheet,
} from 'react-native'
import {LatLng} from './PropTypes'
import Overlay from './Overlay'
......@@ -116,17 +116,8 @@ export default class Marker extends PureComponent {
onInfoWindowPress: React.PropTypes.func,
}
_onPress = event => this.props.onPress && this.props.onPress(event)
render() {
const props = {
...this.props,
...Platform.select({
android: {
onMarkerClick: this._onPress,
},
})
}
const props = {...this.props}
let customInfoWindow = <View collapsable={false}/>
let customMarker = <View collapsable={false}/>
......
import React, {PropTypes, PureComponent} from 'react'
import {
PixelRatio,
Platform,
processColor,
requireNativeComponent,
ViewPropTypes,
PixelRatio,
Platform,
} from 'react-native'
import {LatLng} from './PropTypes'
......@@ -65,8 +65,6 @@ export default class Polyline extends PureComponent {
colors: [],
}
_onPress = event => this.props.onPress && this.props.onPress(event)
render() {
const props = {
...this.props,
......@@ -76,7 +74,6 @@ export default class Polyline extends PureComponent {
colors: this.props.colors.map(processColor),
},
}),
onPolylineClick: this._onPress,
}
return <AMapPolyline {...props}/>
}
......
// @flow
import React, {PropTypes, PureComponent} from 'react'
import {
ViewPropTypes,
UIManager,
requireNativeComponent,
findNodeHandle,
} from 'react-native'
import {LatLng} from './PropTypes'
export default class Ride extends PureComponent {
static propTypes = {
...ViewPropTypes,
/**
* 路径规划成功事件
*/
onCalculateRouteSuccess: React.PropTypes.func,
/**
* 路径规划失败事件
*/
onCalculateRouteFailure: React.PropTypes.func,
}
/**
* 路线规划
*/
calculateRoute(start, end) {
this._sendCommand('calculateRoute', [start, end])
}
/**
* 开始导航
*/
start() {
this._sendCommand('start')
}
/**
* call native method
*
* @private
*/
_sendCommand(command: string, params?: []) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.AMapRide.Commands[command],
params,
)
}
render() {
return <AMapRide {...this.props}/>
}
}
const AMapRide = requireNativeComponent('AMapRide', Ride)
// @flow
import React, {PropTypes, PureComponent} from 'react'
import {
ViewPropTypes,
UIManager,
requireNativeComponent,
findNodeHandle,
} from 'react-native'
import {LatLng} from './PropTypes'
export default class Walk extends PureComponent {
static propTypes = {
...ViewPropTypes,
/**
* 路径规划成功事件
*/
onCalculateRouteSuccess: React.PropTypes.func,
/**
* 路径规划失败事件
*/
onCalculateRouteFailure: React.PropTypes.func,
}
/**
* 路线规划
*/
calculateRoute(start, end) {
this._sendCommand('calculateRoute', [start, end])
}
/**
* 开始导航
*/
start() {
this._sendCommand('start')
}
/**
* call native method
*
* @private
*/
_sendCommand(command: string, params?: []) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this),
UIManager.AMapWalk.Commands[command],
params,
)
}
render() {
return <AMapWalk {...this.props}/>
}
}
const AMapWalk = requireNativeComponent('AMapWalk', Walk)
......@@ -3,6 +3,9 @@ import Marker from './components/Marker'
import Polyline from './components/Polyline'
import Polygon from './components/Polygon'
import Circle from './components/Circle'
import Drive from './components/Drive'
import Walk from './components/Walk'
import Ride from './components/Ride'
import MapUtils from './components/Utils'
MapView.Marker = Marker
......@@ -11,5 +14,14 @@ MapView.Polygon = Polygon
MapView.Circle = Circle
export default MapView
export {MapView, Marker, Polyline, Polygon, Circle, MapUtils}
export {
MapView,
Marker,
Polyline,
Polygon,
Circle,
Drive,
Walk,
Ride,
MapUtils,
}
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