-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Added tapable links to user's login information on DetailsPage #3870
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cfc8420
added tapable links to user's login info
parasharrajat 5008009
remove Console logs
parasharrajat fae93e5
moved tapping behavipour to a component
parasharrajat 9481a68
Merge branch 'main' of github.com:Expensify/Expensify.cash into tap-d…
parasharrajat 26123f9
used constants
parasharrajat 4e1aae3
rename and refactor
parasharrajat 42e8a12
comment updated
parasharrajat 7a34f08
refactor
parasharrajat 4f3f1db
rename style prop
parasharrajat a681442
Pulled latest changes
parasharrajat ddff57b
simplified code
parasharrajat 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from 'react'; | ||
import {View, Pressable, Linking} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '../styles/styles'; | ||
import compose from '../libs/compose'; | ||
import {Checkmark, Clipboard as ClipboardIcon} from './Icon/Expensicons'; | ||
import Clipboard from '../libs/Clipboard'; | ||
import ContextMenuItem from './ContextMenuItem'; | ||
import withLocalize, {withLocalizePropTypes} from './withLocalize'; | ||
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; | ||
import CONST from '../CONST'; | ||
|
||
const propTypes = { | ||
/** Children to wrap in CommunicationsLink. */ | ||
children: PropTypes.node.isRequired, | ||
|
||
/** Styles to be assigned to Container */ | ||
containerStyles: PropTypes.arrayOf(PropTypes.object), | ||
|
||
/** Decides Tap behaviour. */ | ||
type: PropTypes.oneOf([CONST.LOGIN_TYPE.PHONE, CONST.LOGIN_TYPE.EMAIL]), | ||
|
||
/** Value to be copied or passed via tap. */ | ||
value: PropTypes.string.isRequired, | ||
|
||
...windowDimensionsPropTypes, | ||
...withLocalizePropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
containerStyles: [], | ||
type: undefined, | ||
}; | ||
|
||
const CommunicationsLink = props => ( | ||
<View style={[styles.flexRow, styles.pRelative, ...props.containerStyles]}> | ||
{props.type && props.isSmallScreenWidth | ||
? ( | ||
<Pressable | ||
onPress={() => Linking.openURL( | ||
props.type === CONST.LOGIN_TYPE.PHONE | ||
? `tel:${props.value}` | ||
: `mailto:${props.value}`, | ||
)} | ||
> | ||
{props.children} | ||
</Pressable> | ||
) | ||
: props.children} | ||
{props.type && !props.isSmallScreenWidth | ||
&& ( | ||
<View style={[ | ||
styles.pAbsolute, | ||
styles.alignItemsCenter, | ||
styles.justifyContentCenter, | ||
styles.communicationsLinkIcon]} | ||
> | ||
<ContextMenuItem | ||
icon={ClipboardIcon} | ||
text={props.translate('contextMenuItem.copyToClipboard')} | ||
successIcon={Checkmark} | ||
successText={props.translate('contextMenuItem.copied')} | ||
isMini | ||
autoReset | ||
onPress={() => Clipboard.setString(props.value)} | ||
/> | ||
</View> | ||
)} | ||
</View> | ||
); | ||
|
||
CommunicationsLink.propTypes = propTypes; | ||
CommunicationsLink.defaultProps = defaultProps; | ||
CommunicationsLink.displayName = 'CommunicationsLink'; | ||
|
||
export default compose( | ||
withWindowDimensions, | ||
withLocalize, | ||
)(CommunicationsLink); |
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
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.
Still don't get the checks for
props.type
. What is using this without a type? If there's notype
we showprops.children
? We should not use it at all in that case.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.
To make
CommunicationLink
uses cleaner I did this. Otherwise, we have to conditionally show the content wrapped inCommunicationLink
which will duplicate a few lines on the main Component and This approach gives it a cleaner usage. https://github.com/parasharrajat/Expensify.cash/blob/a6814422a60fbba13d04e19f2807190a82450c2f/src/pages/DetailsPage.js#L95.I will welcome suggestions to improve it.
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.
Ok, I am removing the confusing uses of Type. Instead, just use the conditional block here https://github.com/parasharrajat/Expensify.cash/blob/a6814422a60fbba13d04e19f2807190a82450c2f/src/pages/DetailsPage.js#L95
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.
Perfect thanks!
I have a different opinion. To me it's not clear why we should use a component that might do nothing at all. It's as if we are calling a function with an optional argument that specifies whether we should call the function or not. In this case, it's clearer to just not call the function in the first place.
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.
Thanks for clarifying.