@@ -15,6 +15,13 @@ import MapPolygon from './MapPolygon';
15
15
import MapCircle from './MapCircle' ;
16
16
import MapCallout from './MapCallout' ;
17
17
import MapUrlTile from './MapUrlTile' ;
18
+ import {
19
+ contextTypes as childContextTypes ,
20
+ getAirMapName ,
21
+ googleMapIsInstalled ,
22
+ createNotSupportedComponent ,
23
+ } from './decorateMapComponent' ;
24
+ import * as ProviderConstants from './ProviderConstants' ;
18
25
19
26
const MAP_TYPES = {
20
27
STANDARD : 'standard' ,
@@ -30,14 +37,23 @@ const ANDROID_ONLY_MAP_TYPES = [
30
37
] ;
31
38
32
39
const viewConfig = {
33
- uiViewClassName : 'AIRMap ' ,
40
+ uiViewClassName : 'AIR<provider>Map ' ,
34
41
validAttributes : {
35
42
region : true ,
36
43
} ,
37
44
} ;
38
45
39
46
const propTypes = {
40
47
...View . propTypes ,
48
+ /**
49
+ * When provider is "google", we will use GoogleMaps.
50
+ * Any value other than "google" will default to using
51
+ * MapKit in iOS or GoogleMaps in android as the map provider.
52
+ */
53
+ provider : PropTypes . oneOf ( [
54
+ 'google' ,
55
+ ] ) ,
56
+
41
57
/**
42
58
* Used to style and layout the `MapView`. See `StyleSheet.js` and
43
59
* `ViewStylePropTypes.js` for more info.
@@ -341,6 +357,10 @@ class MapView extends React.Component {
341
357
this . _onLayout = this . _onLayout . bind ( this ) ;
342
358
}
343
359
360
+ getChildContext ( ) {
361
+ return { provider : this . props . provider } ;
362
+ }
363
+
344
364
componentDidMount ( ) {
345
365
const { region, initialRegion } = this . props ;
346
366
if ( region && this . state . isReady ) {
@@ -421,6 +441,14 @@ class MapView extends React.Component {
421
441
this . _runCommand ( 'takeSnapshot' , [ width , height , finalRegion , callback ] ) ;
422
442
}
423
443
444
+ _uiManagerCommand ( name ) {
445
+ return NativeModules . UIManager [ getAirMapName ( this . props . provider ) ] . Commands [ name ] ;
446
+ }
447
+
448
+ _mapManagerCommand ( name ) {
449
+ return NativeModules [ `${ getAirMapName ( this . props . provider ) } Manager` ] [ name ] ;
450
+ }
451
+
424
452
_getHandle ( ) {
425
453
return findNodeHandle ( this . map ) ;
426
454
}
@@ -430,16 +458,13 @@ class MapView extends React.Component {
430
458
case 'android' :
431
459
NativeModules . UIManager . dispatchViewManagerCommand (
432
460
this . _getHandle ( ) ,
433
- NativeModules . UIManager . AIRMap . Commands [ name ] ,
461
+ this . _uiManagerCommand ( name ) ,
434
462
args
435
463
) ;
436
464
break ;
437
465
438
466
case 'ios' :
439
- NativeModules . AIRMapManager [ name ] . apply (
440
- NativeModules . AIRMapManager [ name ] ,
441
- [ this . _getHandle ( ) , ...args ]
442
- ) ;
467
+ this . _mapManagerCommand ( name ) ( this . _getHandle ( ) , ...args ) ;
443
468
break ;
444
469
445
470
default :
@@ -483,6 +508,8 @@ class MapView extends React.Component {
483
508
) ;
484
509
}
485
510
511
+ const AIRMap = getAirMapComponent ( this . props . provider ) ;
512
+
486
513
return (
487
514
< AIRMap
488
515
ref = { ref => { this . map = ref ; } }
@@ -494,31 +521,45 @@ class MapView extends React.Component {
494
521
495
522
MapView . propTypes = propTypes ;
496
523
MapView . viewConfig = viewConfig ;
524
+ MapView . childContextTypes = childContextTypes ;
497
525
498
526
MapView . MAP_TYPES = MAP_TYPES ;
499
527
500
- const AIRMap = requireNativeComponent ( 'AIRMap' , MapView , {
528
+ const nativeComponent = Component => requireNativeComponent ( Component , MapView , {
501
529
nativeOnly : {
502
530
onChange : true ,
503
531
onMapReady : true ,
504
532
handlePanDrag : true ,
505
533
} ,
506
534
} ) ;
535
+ const airMaps = {
536
+ default : nativeComponent ( 'AIRMap' ) ,
537
+ } ;
538
+ if ( Platform . OS === 'android' ) {
539
+ airMaps . google = airMaps . default ;
540
+ } else {
541
+ airMaps . google = googleMapIsInstalled ? nativeComponent ( 'AIRGoogleMap' ) :
542
+ createNotSupportedComponent ( 'react-native-maps: AirGoogleMaps dir must be added to your xCode project to support GoogleMaps on iOS.' ) ; // eslint-disable-line max-len
543
+ }
544
+ const getAirMapComponent = provider => airMaps [ provider || 'default' ] ;
507
545
508
- const AIRMapLite = requireNativeComponent ( 'AIRMapLite' , MapView , {
509
- nativeOnly : {
510
- onChange : true ,
511
- onMapReady : true ,
512
- handlePanDrag : true ,
513
- } ,
514
- } ) ;
546
+ const AIRMapLite = NativeModules . UIManager . AIRMapLite &&
547
+ requireNativeComponent ( 'AIRMapLite' , MapView , {
548
+ nativeOnly : {
549
+ onChange : true ,
550
+ onMapReady : true ,
551
+ handlePanDrag : true ,
552
+ } ,
553
+ } ) ;
515
554
516
555
MapView . Marker = MapMarker ;
517
556
MapView . Polyline = MapPolyline ;
518
557
MapView . Polygon = MapPolygon ;
519
558
MapView . Circle = MapCircle ;
520
559
MapView . UrlTile = MapUrlTile ;
521
560
MapView . Callout = MapCallout ;
561
+ Object . assign ( MapView , ProviderConstants ) ;
562
+ MapView . ProviderPropType = PropTypes . oneOf ( Object . values ( ProviderConstants ) ) ;
522
563
523
564
MapView . Animated = Animated . createAnimatedComponent ( MapView ) ;
524
565
0 commit comments