-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Google Maps on iOS #548
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ee57a01
[google] initial google map support
gilbox 2d37a79
[google] ProviderPropType
gilbox 4640109
[google] decorateMapComponent - don't ignore entire file w/eslint
gilbox ffdd901
[google] remove accidental file ProviderPropType
gilbox 1ff25b5
[google] rmv dead code
gilbox 1a3c819
[google] avoid warning when AIRMapLite doesn't exist
gilbox ce65670
[google] rmv dead imports in examples
gilbox 623945c
[google] eslint-disable-next-line
gilbox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,5 @@ local.properties | |
# | ||
node_modules/ | ||
npm-debug.log | ||
Pods/ | ||
AirMapsExplorer.xcworkspace/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,13 @@ import MapPolygon from './MapPolygon'; | |
import MapCircle from './MapCircle'; | ||
import MapCallout from './MapCallout'; | ||
import MapUrlTile from './MapUrlTile'; | ||
import { | ||
contextTypes as childContextTypes, | ||
getAirMapName, | ||
googleMapIsInstalled, | ||
createNotSupportedComponent, | ||
} from './decorateMapComponent'; | ||
import * as ProviderConstants from './ProviderConstants'; | ||
|
||
const MAP_TYPES = { | ||
STANDARD: 'standard', | ||
|
@@ -30,14 +37,23 @@ const ANDROID_ONLY_MAP_TYPES = [ | |
]; | ||
|
||
const viewConfig = { | ||
uiViewClassName: 'AIRMap', | ||
uiViewClassName: 'AIR<provider>Map', | ||
validAttributes: { | ||
region: true, | ||
}, | ||
}; | ||
|
||
const propTypes = { | ||
...View.propTypes, | ||
/** | ||
* When provider is "google", we will use GoogleMaps. | ||
* Any value other than "google" will default to using | ||
* MapKit in iOS or GoogleMaps in android as the map provider. | ||
*/ | ||
provider: PropTypes.oneOf([ | ||
'google', | ||
]), | ||
|
||
/** | ||
* Used to style and layout the `MapView`. See `StyleSheet.js` and | ||
* `ViewStylePropTypes.js` for more info. | ||
|
@@ -341,6 +357,10 @@ class MapView extends React.Component { | |
this._onLayout = this._onLayout.bind(this); | ||
} | ||
|
||
getChildContext() { | ||
return { provider: this.props.provider }; | ||
} | ||
|
||
componentDidMount() { | ||
const { region, initialRegion } = this.props; | ||
if (region && this.state.isReady) { | ||
|
@@ -421,6 +441,14 @@ class MapView extends React.Component { | |
this._runCommand('takeSnapshot', [width, height, finalRegion, callback]); | ||
} | ||
|
||
_uiManagerCommand(name) { | ||
return NativeModules.UIManager[getAirMapName(this.props.provider)].Commands[name]; | ||
} | ||
|
||
_mapManagerCommand(name) { | ||
return NativeModules[`${getAirMapName(this.props.provider)}Manager`][name]; | ||
} | ||
|
||
_getHandle() { | ||
return findNodeHandle(this.map); | ||
} | ||
|
@@ -430,16 +458,13 @@ class MapView extends React.Component { | |
case 'android': | ||
NativeModules.UIManager.dispatchViewManagerCommand( | ||
this._getHandle(), | ||
NativeModules.UIManager.AIRMap.Commands[name], | ||
this._uiManagerCommand(name), | ||
args | ||
); | ||
break; | ||
|
||
case 'ios': | ||
NativeModules.AIRMapManager[name].apply( | ||
NativeModules.AIRMapManager[name], | ||
[this._getHandle(), ...args] | ||
); | ||
this._mapManagerCommand(name)(this._getHandle(), ...args); | ||
break; | ||
|
||
default: | ||
|
@@ -483,6 +508,8 @@ class MapView extends React.Component { | |
); | ||
} | ||
|
||
const AIRMap = getAirMapComponent(this.props.provider); | ||
|
||
return ( | ||
<AIRMap | ||
ref={ref => { this.map = ref; }} | ||
|
@@ -494,16 +521,27 @@ class MapView extends React.Component { | |
|
||
MapView.propTypes = propTypes; | ||
MapView.viewConfig = viewConfig; | ||
MapView.childContextTypes = childContextTypes; | ||
|
||
MapView.MAP_TYPES = MAP_TYPES; | ||
|
||
const AIRMap = requireNativeComponent('AIRMap', MapView, { | ||
const nativeComponent = Component => requireNativeComponent(Component, MapView, { | ||
nativeOnly: { | ||
onChange: true, | ||
onMapReady: true, | ||
handlePanDrag: true, | ||
}, | ||
}); | ||
const airMaps = { | ||
default: nativeComponent('AIRMap'), | ||
}; | ||
if (Platform.OS === 'android') { | ||
airMaps.google = airMaps.default; | ||
} else { | ||
airMaps.google = googleMapIsInstalled ? nativeComponent('AIRGoogleMap') : | ||
createNotSupportedComponent('react-native-maps: AirGoogleMaps dir must be added to your xCode project to support GoogleMaps on iOS.'); // eslint-disable-line max-len | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's bring in the |
||
} | ||
const getAirMapComponent = provider => airMaps[provider || 'default']; | ||
|
||
const AIRMapLite = requireNativeComponent('AIRMapLite', MapView, { | ||
nativeOnly: { | ||
|
@@ -519,6 +557,7 @@ MapView.Polygon = MapPolygon; | |
MapView.Circle = MapCircle; | ||
MapView.UrlTile = MapUrlTile; | ||
MapView.Callout = MapCallout; | ||
Object.assign(MapView, ProviderConstants); | ||
|
||
MapView.Animated = Animated.createAnimatedComponent(MapView); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const PROVIDER_DEFAULT = null; | ||
export const PROVIDER_GOOGLE = 'google'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Platform.select
might be cleaner here...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but it would mean evaluating both cases