diff --git a/javascript/components/MapView.js b/javascript/components/MapView.js new file mode 100644 index 0000000..5fa7bf7 --- /dev/null +++ b/javascript/components/MapView.js @@ -0,0 +1,45 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { requireNativeComponent } from 'react-native'; + +const RCTMGLMapView = requireNativeComponent('RCTMGLMapView', MapView); + +const DEFAULT_CENTER_COORDINATE = { + type: 'Point', + coordinates: [-77.036086, 38.910233] +} + +class MapView extends React.Component { + static StyleURL = { + Street: 'mapbox-streets', + Dark: 'mapbox-dark', + Light: 'mapbox-light', + Outdoors: 'mapbox-outdoors', + Satellite: 'mapbox-satellite' + } + + static propTypes = { + animated: PropTypes.bool, + centerCoordinate: PropTypes.object, + heading: PropTypes.number, + ptich: PropTypes.number, + style: PropTypes.any, + styleURL: PropTypes.string, + zoomLevel: PropTypes.number + }; + + static defaultProps = { + animated: true, + centerCoordinate: DEFAULT_CENTER_COORDINATE, + heading: 0, + pitch: 0, + zoomLevel: 16, + styleURL: MapView.StyleURL.Street + }; + + render () { + return ; + } +} + +export default MapView; diff --git a/javascript/index.js b/javascript/index.js new file mode 100644 index 0000000..cbbb7cc --- /dev/null +++ b/javascript/index.js @@ -0,0 +1,8 @@ +import MapView from './components/MapView'; + +let MapboxGL = {}; + +// components +MapboxGL.MapView = MapView; + +export default MapboxGL; diff --git a/javascript/utils/index.js b/javascript/utils/index.js new file mode 100644 index 0000000..ce4eb6f --- /dev/null +++ b/javascript/utils/index.js @@ -0,0 +1,46 @@ +import { + NativeModules, + findNodeHandle, + Platform, + requireNativeComponent, +} from 'react-native'; + +const LOG_TAG = '[ReactNativeMapboxNavigationUtils]'; + +export const IS_ANDROID = Platform.OS === 'android'; + +export function runNativeCommand(module, name, nativeRef, args = []) { + // android native command + const managerInstance = getManagerInstance(module) + if (!managerInstance) { + console.log(LOG_TAG, `Could not find ${module}`); + return; + } + + // get react tag so we can find, this component on the otherside + const handle = findNodeHandle(nativeRef); + + // android native command + if (IS_ANDROID) { + NativeModules.UIManager.dispatchViewManagerCommand( + handle, + managerInstance.Commands[name], + args, + ); + return; + } + + // ios native command + const method = managerInstance[name] + if (!method) { + console.log(LOG_TAG, `Could not find method ${name} on module ${module}`); + return; + } + + method(handle, ...args); +} + +function getManagerInstance(module) { + const obj = IS_ANDROID ? NativeModules.UIManager : NativeModules; + return obj[module]; +}