Skip to content

Disable Drag & Drop by default #24536

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

Merged
merged 12 commits into from
Aug 22, 2023
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ThemeStylesProvider from './styles/ThemeStylesProvider';
import {CurrentReportIDContextProvider} from './components/withCurrentReportID';
import {EnvironmentProvider} from './components/withEnvironment';
import * as Session from './libs/actions/Session';
import useDefaultDragAndDrop from './hooks/useDefaultDragAndDrop';

// For easier debugging and development, when we are in web we expose Onyx to the window, so you can more easily set data into Onyx
if (window && Environment.isDevelopment()) {
Expand All @@ -40,6 +41,7 @@ LogBox.ignoreLogs([
const fill = {flex: 1};

function App() {
useDefaultDragAndDrop();
return (
<GestureHandlerRootView style={fill}>
<ComposeProviders
Expand Down
16 changes: 16 additions & 0 deletions src/hooks/useDefaultDragAndDrop/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {useEffect} from 'react';

export default function useDefaultDragAndDrop() {
const dropDragListener = (event) => {
event.preventDefault();
// eslint-disable-next-line no-param-reassign
event.dataTransfer.dropEffect = 'none';
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to define this inside the effect as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙏


useEffect(() => {
document.addEventListener('dragover', dropDragListener);
document.addEventListener('dragenter', dropDragListener);
document.addEventListener('dragleave', dropDragListener);
document.addEventListener('drop', dropDragListener);
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget to unsubscribe these listeners.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙏

}, []);
}
1 change: 1 addition & 0 deletions src/hooks/useDefaultDragAndDrop/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => {};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import styles from '../../../../styles/styles';
import CONST from '../../../../CONST';
import PressableWithoutFeedback from '../../../../components/Pressable/PressableWithoutFeedback';
import useLocalize from '../../../../hooks/useLocalize';
import NoDropZone from '../../../../components/DragAndDrop/NoDropZone';

const propTypes = {
/* State from useNavigationBuilder */
Expand Down Expand Up @@ -53,28 +52,26 @@ function ThreePaneView(props) {
);
}
if (route.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR) {
const Wrapper = props.state.index === i ? NoDropZone : React.Fragment;
return (
<Wrapper key={route.key}>
<View
style={[
styles.flexRow,
styles.pAbsolute,
styles.w100,
styles.h100,
StyleUtils.getBackgroundColorWithOpacityStyle(themeColors.shadow, CONST.RIGHT_MODAL_BACKGROUND_OVERLAY_OPACITY),
StyleUtils.displayIfTrue(props.state.index === i),
]}
>
<PressableWithoutFeedback
style={[styles.flex1]}
onPress={() => props.navigation.goBack()}
accessibilityLabel={translate('common.close')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
/>
<View style={styles.rightPanelContainer}>{props.descriptors[route.key].render()}</View>
</View>
</Wrapper>
<View
key={route.key}
style={[
styles.flexRow,
styles.pAbsolute,
styles.w100,
styles.h100,
StyleUtils.getBackgroundColorWithOpacityStyle(themeColors.shadow, CONST.RIGHT_MODAL_BACKGROUND_OVERLAY_OPACITY),
StyleUtils.displayIfTrue(props.state.index === i),
]}
>
<PressableWithoutFeedback
style={[styles.flex1]}
onPress={() => props.navigation.goBack()}
accessibilityLabel={translate('common.close')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
/>
<View style={styles.rightPanelContainer}>{props.descriptors[route.key].render()}</View>
</View>
);
}
return (
Expand Down