-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement DistanceMapView with blocking view for Android native
- Loading branch information
Showing
8 changed files
with
141 additions
and
5 deletions.
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
55 changes: 55 additions & 0 deletions
55
src/components/DistanceMapView/distanceMapViewPropTypes.js
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,55 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
const propTypes = { | ||
// Public access token to be used to fetch map data from Mapbox. | ||
accessToken: PropTypes.string.isRequired, | ||
|
||
// Style applied to MapView component. Note some of the View Style props are not available on ViewMap | ||
style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]), | ||
|
||
// Link to the style JSON document. | ||
styleURL: PropTypes.string, | ||
|
||
// Whether map can tilt in the vertical direction. | ||
pitchEnabled: PropTypes.bool, | ||
|
||
// Padding to apply when the map is adjusted to fit waypoints and directions | ||
mapPadding: PropTypes.number, | ||
|
||
// Initial coordinate and zoom level | ||
initialState: PropTypes.shape({ | ||
location: PropTypes.arrayOf(PropTypes.number).isRequired, | ||
zoom: PropTypes.number.isRequired, | ||
}), | ||
|
||
// Locations on which to put markers | ||
waypoints: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
id: PropTypes.string, | ||
coordinate: PropTypes.arrayOf(PropTypes.number), | ||
markerComponent: PropTypes.oneOfType([PropTypes.element, PropTypes.func]), | ||
}), | ||
), | ||
|
||
// List of coordinates which together forms a direction. | ||
directionCoordinates: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)), | ||
|
||
// Callback to call when the map is idle / ready | ||
onMapReady: PropTypes.func, | ||
|
||
// Optional additional styles to be applied to the overlay | ||
overlayStyle: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]), | ||
}; | ||
|
||
const defaultProps = { | ||
styleURL: undefined, | ||
pitchEnabled: false, | ||
mapPadding: 0, | ||
initialState: undefined, | ||
waypoints: undefined, | ||
directionCoordinates: undefined, | ||
onMapReady: () => {}, | ||
overlayStyle: undefined, | ||
}; | ||
|
||
export {propTypes, defaultProps}; |
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,48 @@ | ||
import React, {useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import _ from 'underscore'; | ||
import BlockingView from '../BlockingViews/BlockingView'; | ||
import MapView from '../MapView'; | ||
import styles from '../../styles/styles'; | ||
import useNetwork from '../../hooks/useNetwork'; | ||
import useLocalize from '../../hooks/useLocalize'; | ||
import * as Expensicons from '../Icon/Expensicons'; | ||
import * as StyleUtils from '../../styles/StyleUtils'; | ||
import * as distanceMapViewPropTypes from './distanceMapViewPropTypes'; | ||
|
||
function DistanceMapView(props) { | ||
const [isMapReady, setIsMapReady] = useState(false); | ||
const {isOffline} = useNetwork(); | ||
const {translate} = useLocalize(); | ||
|
||
return ( | ||
<> | ||
<MapView | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{..._.omit(props, 'overlayStyle')} | ||
onMapReady={() => { | ||
if (isMapReady) { | ||
return; | ||
} | ||
setIsMapReady(true); | ||
}} | ||
/> | ||
{!isMapReady && ( | ||
<View style={StyleUtils.combineStyles(styles.mapViewOverlay, props.overlayStyle)}> | ||
<BlockingView | ||
icon={Expensicons.EmptyStateRoutePending} | ||
title={translate('distance.mapPending.title')} | ||
subtitle={isOffline ? translate('distance.mapPending.subtitle') : translate('distance.mapPending.onlineSubtitle')} | ||
shouldShowLink={false} | ||
/> | ||
</View> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
DistanceMapView.propTypes = distanceMapViewPropTypes.propTypes; | ||
DistanceMapView.defaultProps = distanceMapViewPropTypes.defaultProps; | ||
DistanceMapView.displayName = 'DistanceMapView'; | ||
|
||
export default DistanceMapView; |
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,15 @@ | ||
import React from 'react'; | ||
import _ from 'underscore'; | ||
import MapView from '../MapView'; | ||
import * as distanceMapViewPropTypes from './distanceMapViewPropTypes'; | ||
|
||
function DistanceMapView(props) { | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return <MapView {..._.omit(props, 'overlayStyle')} />; | ||
} | ||
|
||
DistanceMapView.propTypes = distanceMapViewPropTypes.propTypes; | ||
DistanceMapView.defaultProps = distanceMapViewPropTypes.defaultProps; | ||
DistanceMapView.displayName = 'DistanceMapView'; | ||
|
||
export default DistanceMapView; |
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