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: blue screen issue on Safari Web #3927

Merged
merged 2 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 4 additions & 6 deletions src/components/PressableWithSecondaryInteraction/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import _ from 'underscore';
import React, {Component} from 'react';
import {Pressable} from 'react-native';
import pressableWithSecondaryInteractionPropTypes from './pressableWithSecondaryInteractionPropTypes';

const defaultProps = {
forwardedRef: () => {},
};
import {propTypes, defaultProps} from './pressableWithSecondaryInteractionPropTypes';

/**
* This is a special Pressable that calls onSecondaryInteraction when LongPressed, or right-clicked.
Expand Down Expand Up @@ -42,7 +38,9 @@ class PressableWithSecondaryInteraction extends Component {
const defaultPressableProps = _.omit(this.props, ['onSecondaryInteraction', 'children', 'onLongPress']);
return (
<Pressable
onPressIn={this.props.onPressIn}
onLongPress={e => this.props.onSecondaryInteraction(e)}
onPressOut={this.props.onPressOut}
ref={el => this.pressableRef = el}
// eslint-disable-next-line react/jsx-props-no-spreading
{...defaultPressableProps}
Expand All @@ -53,7 +51,7 @@ class PressableWithSecondaryInteraction extends Component {
}
}

PressableWithSecondaryInteraction.propTypes = pressableWithSecondaryInteractionPropTypes;
PressableWithSecondaryInteraction.propTypes = propTypes;
PressableWithSecondaryInteraction.defaultProps = defaultProps;
export default React.forwardRef((props, ref) => (
// eslint-disable-next-line react/jsx-props-no-spreading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import _ from 'underscore';
import React, {forwardRef} from 'react';
import {Pressable} from 'react-native';
import pressableWithSecondaryInteractionPropTypes from './pressableWithSecondaryInteractionPropTypes';

const defaultProps = {
forwardedRef: () => {},
};
import {propTypes, defaultProps} from './pressableWithSecondaryInteractionPropTypes';

/**
* This is a special Pressable that calls onSecondaryInteraction when LongPressed.
Expand All @@ -16,18 +12,20 @@ const defaultProps = {
const PressableWithSecondaryInteraction = props => (
<Pressable
ref={props.forwardedRef}
onPressIn={props.onPressIn}
onLongPress={(e) => {
e.preventDefault();
props.onSecondaryInteraction(e);
}}
onPressOut={props.onPressOut}
// eslint-disable-next-line react/jsx-props-no-spreading
{...(_.omit(props, 'onLongPress'))}
>
{props.children}
</Pressable>
);

PressableWithSecondaryInteraction.propTypes = pressableWithSecondaryInteractionPropTypes;
PressableWithSecondaryInteraction.propTypes = propTypes;
PressableWithSecondaryInteraction.defaultProps = defaultProps;
PressableWithSecondaryInteraction.displayName = 'PressableWithSecondaryInteraction';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import PropTypes from 'prop-types';

export default {
const propTypes = {
/** The function that should be called when this pressable is pressedIn */
onPressIn: PropTypes.func,

/** The function that should be called when this pressable is pressedOut */
onPressOut: PropTypes.func,

/** The function that should be called when this pressable is LongPressed or right-clicked. */
onSecondaryInteraction: PropTypes.func.isRequired,

Expand All @@ -10,3 +16,11 @@ export default {
/** The ref to the search input (may be null on small screen widths) */
forwardedRef: PropTypes.func,
};

const defaultProps = {
forwardedRef: () => {},
onPressIn: () => {},
onPressOut: () => {},
};

export {propTypes, defaultProps};
20 changes: 20 additions & 0 deletions src/libs/ControlSelection/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Block selection on the whole app
*
*/
function block() {
document.body.classList.add('disable-select');
}

/**
* Unblock selection on the whole app
*
*/
function unblock() {
document.body.classList.remove('disable-select');
}

export default {
block,
unblock,
};
7 changes: 7 additions & 0 deletions src/libs/ControlSelection/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function block() {}
function unblock() {}

export default {
block,
unblock,
};
6 changes: 6 additions & 0 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import ConfirmModal from '../../../components/ConfirmModal';
import compose from '../../../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import {deleteReportComment} from '../../../libs/actions/Report';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import ControlSelection from '../../../libs/ControlSelection';

const propTypes = {
/** The ID of the report this action is on. */
Expand Down Expand Up @@ -56,6 +58,7 @@ const propTypes = {
onLayout: PropTypes.func.isRequired,

...withLocalizePropTypes,
...windowDimensionsPropTypes,
};

const defaultProps = {
Expand Down Expand Up @@ -269,6 +272,8 @@ class ReportActionItem extends Component {
<>
<PressableWithSecondaryInteraction
ref={el => this.popoverAnchor = el}
onPressIn={() => this.props.isSmallScreenWidth && ControlSelection.block()}
onPressOut={() => ControlSelection.unblock()}
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: Why not include this.props.isSmallScreenWidth && here too?

Copy link
Member Author

@parasharrajat parasharrajat Jul 8, 2021

Choose a reason for hiding this comment

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

This Change will block text selection at the root. But we have a feature where we select text on the web and then open the context menu to copy the selected part.

On the underhand Unblocking is fine to run everywhere as it will have no effect if select is not blocked.

onSecondaryInteraction={this.showPopover}
>
<Hoverable resetsOnClickOutside={false}>
Expand Down Expand Up @@ -354,6 +359,7 @@ ReportActionItem.propTypes = propTypes;
ReportActionItem.defaultProps = defaultProps;

export default compose(
withWindowDimensions,
withLocalize,
withOnyx({
draftMessage: {
Expand Down
4 changes: 4 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
input[type=text] {
-webkit-user-select: text !important;
}
.disable-select * {
-webkit-user-select: none !important;
-webkit-touch-callout: none !important;
}
</style>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1">
<link rel="shortcut icon" id="favicon" href="/favicon.png">
Expand Down