Skip to content

Commit

Permalink
Merge pull request #14381 from jatinsonijs/fix-safari-ibeam-on-drag
Browse files Browse the repository at this point in the history
Prevent slider and image drag i-beam cursor on safari
  • Loading branch information
puneetlath authored Jan 18, 2023
2 parents 0f4e09d + 86c05d6 commit 5370c36
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/AvatarCropModal/ImageCropView.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Icon from '../Icon';
import * as Expensicons from '../Icon/Expensicons';
import * as StyleUtils from '../../styles/StyleUtils';
import gestureHandlerPropTypes from './gestureHandlerPropTypes';
import ControlSelection from '../../libs/ControlSelection';

const propTypes = {
/** Link to image for cropping */
Expand Down Expand Up @@ -63,9 +64,11 @@ const ImageCropView = (props) => {
};
}, [props.originalImageHeight, props.originalImageWidth]);

// We're preventing text selection with ControlSelection.blockElement to prevent safari
// default behaviour of cursor - I-beam cursor on drag. See https://github.com/Expensify/App/issues/13688
return (
<PanGestureHandler onGestureEvent={props.panGestureEventHandler}>
<Animated.View style={[containerStyle, styles.imageCropContainer]}>
<Animated.View ref={ControlSelection.blockElement} style={[containerStyle, styles.imageCropContainer]}>
<Animated.Image style={[imageStyle, styles.h100, styles.w100]} source={{uri: props.imageUri}} resizeMode="contain" />
<View style={[containerStyle, styles.l0, styles.b0, styles.pAbsolute]}>
<Icon src={Expensicons.ImageCropMask} width={props.containerSize} height={props.containerSize} />
Expand Down
5 changes: 4 additions & 1 deletion src/components/AvatarCropModal/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {PanGestureHandler} from 'react-native-gesture-handler';
import Animated, {useAnimatedStyle} from 'react-native-reanimated';
import styles from '../../styles/styles';
import gestureHandlerPropTypes from './gestureHandlerPropTypes';
import ControlSelection from '../../libs/ControlSelection';

const propTypes = {
/** React-native-reanimated lib handler which executes when the user is panning slider */
Expand All @@ -27,8 +28,10 @@ const Slider = (props) => {
transform: [{translateX: props.sliderValue.value}],
}));

// We're preventing text selection with ControlSelection.blockElement to prevent safari
// default behaviour of cursor - I-beam cursor on drag. See https://github.com/Expensify/App/issues/13688
return (
<View style={styles.sliderBar}>
<View ref={ControlSelection.blockElement} style={styles.sliderBar}>
<PanGestureHandler onGestureEvent={props.onGesture}>
<Animated.View style={[styles.sliderKnob, rSliderStyle]} />
</PanGestureHandler>
Expand Down
26 changes: 26 additions & 0 deletions src/libs/ControlSelection/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'underscore';

/**
* Block selection on the whole app
*
Expand All @@ -14,7 +16,31 @@ function unblock() {
document.body.classList.remove('disable-select');
}

/**
* Block selection on particular element
* @param {Element} ref
*/
function blockElement(ref) {
if (_.isNull(ref)) { return; }

// eslint-disable-next-line no-param-reassign
ref.onselectstart = () => false;
}

/**
* Unblock selection on particular element
* @param {Element} ref
*/
function unblockElement(ref) {
if (_.isNull(ref)) { return; }

// eslint-disable-next-line no-param-reassign
ref.onselectstart = () => true;
}

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

export default {
block,
unblock,
blockElement,
unblockElement,
};

0 comments on commit 5370c36

Please sign in to comment.