Skip to content
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

Fix URL rendering #6392

Merged
merged 8 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@ const BaseAnchorForCommentsOnly = (props) => {
)
: (
<PressableWithSecondaryInteraction
inline
onSecondaryInteraction={
(event) => {
showContextMenu(
CONTEXT_MENU_TYPES.LINK,
event,
props.href,
lodashGet(linkRef, 'current'),
);
}
(event) => {
showContextMenu(
CONTEXT_MENU_TYPES.LINK,
event,
props.href,
lodashGet(linkRef, 'current'),
);
}
}
>
<Text
ref={el => linkRef = el}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ const BaseAnchorForCommentsOnly = (props) => {
)
: (
<PressableWithSecondaryInteraction
inline
onSecondaryInteraction={
(event) => {
showContextMenu(
CONTEXT_MENU_TYPES.LINK,
event,
props.href,
lodashGet(linkRef, 'current'),
);
}
}
(event) => {
showContextMenu(
CONTEXT_MENU_TYPES.LINK,
event,
props.href,
lodashGet(linkRef, 'current'),
);
}
}
onPress={() => Linking.openURL(props.href)}
>
<Text
Expand Down
31 changes: 17 additions & 14 deletions src/components/PressableWithSecondaryInteraction/index.android.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'underscore';
import React, {forwardRef} from 'react';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import {Pressable, Platform} from 'react-native';
import {Pressable, Platform, Text as RNText} from 'react-native';
import {propTypes, defaultProps} from './pressableWithSecondaryInteractionPropTypes';

/**
Expand Down Expand Up @@ -31,19 +31,22 @@ function handleLongPress(event, props) {
* @param {Object} props
* @returns {React.Component}
*/
const PressableWithSecondaryInteraction = props => (
<Pressable
ref={props.forwardedRef}
onPress={props.onPress}
onPressIn={props.onPressIn}
onLongPress={event => handleLongPress(event, props)}
onPressOut={props.onPressOut}
// eslint-disable-next-line react/jsx-props-no-spreading
{...(_.omit(props, 'onLongPress'))}
>
{props.children}
</Pressable>
);
const PressableWithSecondaryInteraction = (props) => {
const Node = props.inline ? RNText : Pressable;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

return (
<Node
ref={props.forwardedRef}
onPress={props.onPress}
onPressIn={props.onPressIn}
onLongPress={event => handleLongPress(event, props)}
onPressOut={props.onPressOut}
// eslint-disable-next-line react/jsx-props-no-spreading
{...(_.omit(props, 'onLongPress'))}
>
{props.children}
</Node>
);
};

PressableWithSecondaryInteraction.propTypes = propTypes;
PressableWithSecondaryInteraction.defaultProps = defaultProps;
Expand Down
43 changes: 23 additions & 20 deletions src/components/PressableWithSecondaryInteraction/index.ios.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'underscore';
import React, {forwardRef} from 'react';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import {Pressable} from 'react-native';
import {Pressable, Text as RNText} from 'react-native';
import {propTypes, defaultProps} from './pressableWithSecondaryInteractionPropTypes';

/**
Expand All @@ -10,25 +10,28 @@ import {propTypes, defaultProps} from './pressableWithSecondaryInteractionPropTy
* @param {Object} props
* @returns {React.Component}
*/
const PressableWithSecondaryInteraction = props => (
<Pressable
ref={props.forwardedRef}
onPress={props.onPress}
onPressIn={props.onPressIn}
onLongPress={(e) => {
e.preventDefault();
ReactNativeHapticFeedback.trigger('selection', {
enableVibrateFallback: true,
});
props.onSecondaryInteraction(e);
}}
onPressOut={props.onPressOut}
// eslint-disable-next-line react/jsx-props-no-spreading
{...(_.omit(props, 'onLongPress'))}
>
{props.children}
</Pressable>
);
const PressableWithSecondaryInteraction = (props) => {
const Node = props.inline ? RNText : Pressable;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parasharrajat I think it might be worth adding a little comment explaining this option here as well. I know you have added the comment to the PropType, but one compact line in here would be handy. Can you please add one? Thank you 🙌

return (
<Node
ref={props.forwardedRef}
onPress={props.onPress}
onPressIn={props.onPressIn}
onLongPress={(e) => {
e.preventDefault();
ReactNativeHapticFeedback.trigger('selection', {
enableVibrateFallback: true,
});
props.onSecondaryInteraction(e);
}}
onPressOut={props.onPressOut}
// eslint-disable-next-line react/jsx-props-no-spreading
{...(_.omit(props, 'onLongPress'))}
>
{props.children}
</Node>
);
};

PressableWithSecondaryInteraction.propTypes = propTypes;
PressableWithSecondaryInteraction.defaultProps = defaultProps;
Expand Down
5 changes: 4 additions & 1 deletion src/components/PressableWithSecondaryInteraction/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import _ from 'underscore';
import React, {Component} from 'react';
import {Pressable} from 'react-native';
import {propTypes, defaultProps} from './pressableWithSecondaryInteractionPropTypes';
import styles from '../../styles/styles';

/**
* This is a special Pressable that calls onSecondaryInteraction when LongPressed, or right-clicked.
Expand Down Expand Up @@ -39,10 +40,12 @@ class PressableWithSecondaryInteraction extends Component {

render() {
const defaultPressableProps = _.omit(this.props, ['onSecondaryInteraction', 'children', 'onLongPress']);

// On Web, Text does not support LongPress events thus manage inline mode with styling instead of using Text.
return (
<Pressable
style={this.props.inline && styles.dInline}
onPressIn={this.props.onPressIn}
delayLongPress={200}
onLongPress={this.props.onSecondaryInteraction}
onPressOut={this.props.onPressOut}
onPress={this.props.onPress}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ const propTypes = {

/** Prevent the default ContextMenu on web/Desktop */
preventDefaultContentMenu: PropTypes.bool,

/** Use Text instead of Presable to create inline layout.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB: Typo

Suggested change
/** Use Text instead of Presable to create inline layout.
/** Use Text instead of Pressable to create inline layout.

* It has few limitations in comparison to Pressable.
*
* - No support for delayLongPress.
* - No support for pressIn and pressOut events.
*/
inline: PropTypes.bool,
};

const defaultProps = {
forwardedRef: () => {},
onPressIn: () => {},
onPressOut: () => {},
preventDefaultContentMenu: true,
inline: false,
};

export {propTypes, defaultProps};