-
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.
Merge pull request #23698 from Expensify/neil-waypoints-list
- Loading branch information
Showing
21 changed files
with
338 additions
and
19 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,40 +1,155 @@ | ||
import React, {useEffect} from 'react'; | ||
import {View} from 'react-native'; | ||
import React, {useEffect, useState} from 'react'; | ||
import {ScrollView, View} from 'react-native'; | ||
import lodashGet from 'lodash/get'; | ||
import _ from 'underscore'; | ||
import PropTypes from 'prop-types'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import Text from './Text'; | ||
import * as IOU from '../libs/actions/IOU'; | ||
import styles from '../styles/styles'; | ||
import ONYXKEYS from '../ONYXKEYS'; | ||
import * as Transaction from '../libs/actions/Transaction'; | ||
import MenuItemWithTopDescription from './MenuItemWithTopDescription'; | ||
import withLocalize, {withLocalizePropTypes} from './withLocalize'; | ||
import compose from '../libs/compose'; | ||
import * as Expensicons from './Icon/Expensicons'; | ||
import theme from '../styles/themes/default'; | ||
import Button from './Button'; | ||
import styles from '../styles/styles'; | ||
import variables from '../styles/variables'; | ||
import LinearGradient from './LinearGradient'; | ||
|
||
const MAX_WAYPOINTS = 25; | ||
const MAX_WAYPOINTS_TO_DISPLAY = 4; | ||
|
||
const propTypes = { | ||
/** The transactionID of this request */ | ||
transactionID: PropTypes.string, | ||
|
||
/** The optimistic transaction for this request */ | ||
transaction: PropTypes.shape({ | ||
/** The transactionID of this request */ | ||
transactionID: PropTypes.string, | ||
|
||
/** The comment object on the transaction */ | ||
comment: PropTypes.shape({ | ||
/** The waypoints defining the distance request */ | ||
waypoints: PropTypes.shape({ | ||
/** The latitude of the waypoint */ | ||
lat: PropTypes.number, | ||
|
||
/** The longitude of the waypoint */ | ||
lng: PropTypes.number, | ||
|
||
/** The address of the waypoint */ | ||
address: PropTypes.string, | ||
}), | ||
}), | ||
}), | ||
|
||
...withLocalizePropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
transactionID: '', | ||
transaction: {}, | ||
}; | ||
|
||
function DistanceRequest(props) { | ||
function DistanceRequest({transactionID, transaction, translate}) { | ||
const [shouldShowGradient, setShouldShowGradient] = useState(false); | ||
const [scrollContainerHeight, setScrollContainerHeight] = useState(0); | ||
const [scrollContentHeight, setScrollContentHeight] = useState(0); | ||
|
||
const waypoints = lodashGet(transaction, 'comment.waypoints', {}); | ||
const numberOfWaypoints = _.size(waypoints); | ||
const lastWaypointIndex = numberOfWaypoints - 1; | ||
|
||
// Show up to the max number of waypoints plus 1/2 of one to hint at scrolling | ||
const halfMenuItemHeight = Math.floor(variables.baseMenuItemHeight / 2); | ||
const scrollContainerMaxHeight = variables.baseMenuItemHeight * MAX_WAYPOINTS_TO_DISPLAY + halfMenuItemHeight; | ||
|
||
useEffect(() => { | ||
if (props.transactionID) { | ||
if (!transaction.transactionID || !_.isEmpty(waypoints)) { | ||
return; | ||
} | ||
IOU.createEmptyTransaction(); | ||
}, [props.transactionID]); | ||
// Create the initial start and stop waypoints | ||
Transaction.createInitialWaypoints(transaction.transactionID); | ||
}, [transaction.transactionID, waypoints]); | ||
|
||
const updateGradientVisibility = (event = {}) => { | ||
// If a waypoint extends past the bottom of the visible area show the gradient, else hide it. | ||
const visibleAreaEnd = lodashGet(event, 'nativeEvent.contentOffset.y', 0) + scrollContainerHeight; | ||
setShouldShowGradient(visibleAreaEnd < scrollContentHeight); | ||
}; | ||
|
||
useEffect(updateGradientVisibility, [scrollContainerHeight, scrollContentHeight]); | ||
|
||
return ( | ||
<View style={[styles.flex1, styles.flexColumn, styles.w100, styles.alignItemsCenter, styles.mt4]}> | ||
<Text>Distance Request</Text> | ||
<Text>transactionID: {props.transactionID}</Text> | ||
</View> | ||
<> | ||
<View | ||
style={{maxHeight: scrollContainerMaxHeight}} | ||
onLayout={(event = {}) => setScrollContainerHeight(lodashGet(event, 'nativeEvent.layout.height', 0))} | ||
> | ||
<ScrollView | ||
onContentSizeChange={(width, height) => setScrollContentHeight(height)} | ||
onScroll={updateGradientVisibility} | ||
scrollEventThrottle={16} | ||
> | ||
{_.map(waypoints, (waypoint, key) => { | ||
// key is of the form waypoint0, waypoint1, ... | ||
const index = Number(key.replace('waypoint', '')); | ||
let descriptionKey = 'distance.waypointDescription.'; | ||
let waypointIcon; | ||
if (index === 0) { | ||
descriptionKey += 'start'; | ||
waypointIcon = Expensicons.DotIndicatorUnfilled; | ||
} else if (index === lastWaypointIndex) { | ||
descriptionKey += 'finish'; | ||
waypointIcon = Expensicons.Location; | ||
} else { | ||
descriptionKey += 'stop'; | ||
waypointIcon = Expensicons.DotIndicator; | ||
} | ||
|
||
return ( | ||
<MenuItemWithTopDescription | ||
description={translate(descriptionKey)} | ||
icon={Expensicons.DragHandles} | ||
secondaryIcon={waypointIcon} | ||
secondaryIconFill={theme.icon} | ||
shouldShowRightIcon | ||
key={key} | ||
/> | ||
); | ||
})} | ||
</ScrollView> | ||
{shouldShowGradient && ( | ||
<LinearGradient | ||
style={[styles.pAbsolute, styles.b0, styles.l0, styles.r0, {height: halfMenuItemHeight}]} | ||
colors={[theme.transparent, theme.modalBackground]} | ||
/> | ||
)} | ||
</View> | ||
<View style={[styles.flexRow, styles.justifyContentCenter, styles.pt1]}> | ||
<Button | ||
small | ||
icon={Expensicons.Plus} | ||
onPress={() => Transaction.addStop(transactionID, lastWaypointIndex + 1)} | ||
text={translate('distance.addStop')} | ||
isDisabled={numberOfWaypoints === MAX_WAYPOINTS} | ||
innerStyles={[styles.ph10]} | ||
/> | ||
</View> | ||
</> | ||
); | ||
} | ||
|
||
DistanceRequest.displayName = 'DistanceRequest'; | ||
DistanceRequest.propTypes = propTypes; | ||
DistanceRequest.defaultProps = defaultProps; | ||
export default withOnyx({ | ||
transactionID: {key: ONYXKEYS.IOU, selector: (iou) => (iou && iou.transactionID) || ''}, | ||
})(DistanceRequest); | ||
export default compose( | ||
withLocalize, | ||
withOnyx({ | ||
transaction: { | ||
key: (props) => `${ONYXKEYS.COLLECTION.TRANSACTION}${props.transactionID}`, | ||
selector: (transaction) => (transaction ? {transactionID: transaction.transactionID, comment: {waypoints: lodashGet(transaction, 'comment.waypoints')}} : null), | ||
}, | ||
}), | ||
)(DistanceRequest); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import LinearGradient from 'react-native-web-linear-gradient'; | ||
|
||
export default LinearGradient; |
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,3 @@ | ||
import LinearGradient from 'react-native-linear-gradient'; | ||
|
||
export default LinearGradient; |
Oops, something went wrong.