-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
98 lines (83 loc) · 2.61 KB
/
index.android.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict'
import React, { Component, PropTypes } from 'react';
import { NativeMethodsMixin, NativeModules, requireNativeComponent, findNodeHandle } from 'react-native';
var RCTUIManager = NativeModules.UIManager;
var NativeMapView = requireNativeComponent('MapViewAndroid', null);
var MAP_VIEW_REF = 'mapView';
var MapViewAndroid = React.createClass({
mixins: [NativeMethodsMixin],
propTypes: {
scrollEnabled: PropTypes.bool,
rotateEnabled: PropTypes.bool,
zoomEnabled: PropTypes.bool,
showsUserLocation: PropTypes.bool,
onRegionChangeComplete: PropTypes.func,
onUserLocationUpdate: PropTypes.func
},
getDefaultProps() {
return {
showsUserLocation: true,
rotateEnabled: false,
scrollEnabled: true,
zoomEnabled: true
}
},
_onChange(event) {
this.props.onRegionChangeComplete && this.props.onRegionChangeComplete(event.nativeEvent);
},
_onUserLocationUpdate(event) {
this.props.onUserLocationUpdate && this.props.onUserLocationUpdate(event.nativeEvent);
},
setCenterCoordinate(latitude, longitude) {
RCTUIManager.dispatchViewManagerCommand(
React.findNodeHandle(this),
RCTUIManager.MapViewAndroid.Commands.setCenterCoordinate,
[latitude, longitude, false]
);
},
setCenterCoordinateAnimated(latitude, longitude) {
RCTUIManager.dispatchViewManagerCommand(
findNodeHandle(this),
RCTUIManager.MapViewAndroid.Commands.setCenterCoordinate,
[latitude, longitude, true]
);
},
setZoomLevel(zoom) {
RCTUIManager.dispatchViewManagerCommand(
findNodeHandle(this),
RCTUIManager.MapViewAndroid.Commands.setZoomLevel,
[zoom, false]
);
},
setZoomLevelAnimated(zoom) {
RCTUIManager.dispatchViewManagerCommand(
findNodeHandle(this),
RCTUIManager.MapViewAndroid.Commands.setZoomLevel,
[zoom, true]
);
},
setCenterCoordinateZoomLevel(latitude, longitude, zoom) {
RCTUIManager.dispatchViewManagerCommand(
findNodeHandle(this),
RCTUIManager.MapViewAndroid.Commands.setCenterCoordinateZoomLevel,
[latitude, longitude, zoom, false]
);
},
setCenterCoordinateZoomLevelAnimated(latitude, longitude, zoom) {
RCTUIManager.dispatchViewManagerCommand(
findNodeHandle(this),
RCTUIManager.MapViewAndroid.Commands.setCenterCoordinateZoomLevel,
[latitude, longitude, zoom, true]
);
},
render() {
return (
<NativeMapView
ref={MAP_VIEW_REF}
onChange={this._onChange}
onUserLocationUpdate={this._onUserLocationUpdate}
{...this.props}/>
);
}
});
module.exports = MapViewAndroid;