-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Migrate DragNDrop #23589
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
Migrate DragNDrop #23589
Changes from all commits
65cac31
9851ad1
f5f8743
faa216b
931043b
7665425
401e2c6
1918bfa
e0bd6f7
6be2fe0
23f2d4f
5949c3e
2094ca0
f5afe54
989f5fa
c9a1680
58b31c9
a0f6afa
807d819
48ce5e4
0a09b5b
aa27f70
da885c4
ebfb46c
d510e1e
d140024
be377db
f0685c3
c6fa4fa
4373de1
8a4dcf5
834791e
578c22b
ca84268
8a028bb
0e90a13
8972845
8711b49
cce276f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import {useIsFocused as realUseIsFocused} from '@react-navigation/native'; | ||
|
|
||
| // We only want this mocked for storybook, not jest | ||
| const useIsFocused = process.env.NODE_ENV === 'test' ? realUseIsFocused : () => true; | ||
|
|
||
| export * from '@react-navigation/core'; | ||
| export * from '@react-navigation/native'; | ||
| export {useIsFocused}; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| export default { | ||
| /** Children to render inside this component. */ | ||
| children: PropTypes.node.isRequired, | ||
|
|
||
| /** Function to execute when an item is dropped in the drop zone. */ | ||
| onDrop: PropTypes.func.isRequired, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import React, {useContext, useEffect} from 'react'; | ||
| import {Portal} from '@gorhom/portal'; | ||
| import dragAndDropConsumerPropTypes from './dragAndDropConsumerPropTypes'; | ||
| import {DragAndDropContext} from '../Provider'; | ||
|
|
||
| function DragAndDropConsumer({children, onDrop}) { | ||
| const {isDraggingOver, setOnDropHandler, dropZoneID} = useContext(DragAndDropContext); | ||
|
|
||
| useEffect(() => { | ||
| setOnDropHandler(onDrop); | ||
| }, [onDrop, setOnDropHandler]); | ||
|
|
||
| if (!isDraggingOver) { | ||
| return null; | ||
| } | ||
|
|
||
| return <Portal hostName={dropZoneID}>{children}</Portal>; | ||
| } | ||
|
|
||
| DragAndDropConsumer.propTypes = dragAndDropConsumerPropTypes; | ||
| DragAndDropConsumer.displayName = 'DragAndDropConsumer'; | ||
|
|
||
| export default DragAndDropConsumer; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import dragAndDropConsumerPropTypes from './dragAndDropConsumerPropTypes'; | ||
|
|
||
| function DragAndDropConsumer({children}) { | ||
| return children; | ||
| } | ||
|
|
||
| DragAndDropConsumer.propTypes = dragAndDropConsumerPropTypes; | ||
| DragAndDropConsumer.displayName = 'DragAndDropConsumer'; | ||
|
|
||
| export default DragAndDropConsumer; |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,28 @@ | ||
| import {useEffect} from 'react'; | ||
| import React, {useRef} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import PropTypes from 'prop-types'; | ||
| import styles from '../../../styles/styles'; | ||
| import useDragAndDrop from '../../../hooks/useDragAndDrop'; | ||
|
|
||
| const propTypes = { | ||
| /** Content */ | ||
| children: PropTypes.node.isRequired, | ||
| }; | ||
|
|
||
| function NoDropZone(props) { | ||
| function handleDrag(event) { | ||
| event.preventDefault(); | ||
| // eslint-disable-next-line no-param-reassign | ||
| event.dataTransfer.dropEffect = 'none'; | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| document.addEventListener('dragenter', handleDrag); | ||
| document.addEventListener('dragover', handleDrag); | ||
|
|
||
| return () => { | ||
| document.removeEventListener('dragenter', handleDrag); | ||
| document.removeEventListener('dragover', handleDrag); | ||
| }; | ||
| }, []); | ||
|
|
||
| return props.children; | ||
| function NoDropZone({children}) { | ||
| const noDropZone = useRef(null); | ||
| useDragAndDrop({ | ||
| dropZone: noDropZone, | ||
| shouldAllowDrop: false, | ||
| }); | ||
| return ( | ||
| <View | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wrapping View caused this. When creating a new workspace in ThreePaneView component, props.state.routes still contains NAVIGATORS.RIGHT_MODAL_NAVIGATOR route. This causes the App to be wrapped in NoDropZone even after RHN is closed. |
||
| ref={(e) => (noDropZone.current = e)} | ||
| style={[styles.fullScreen]} | ||
| > | ||
| {children} | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| NoDropZone.displayName = 'NoDropZone'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| export default { | ||
| /** Children to render inside this component. */ | ||
| children: PropTypes.node.isRequired, | ||
|
|
||
| /** Should this dropZone be disabled? */ | ||
| isDisabled: PropTypes.bool, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import _ from 'underscore'; | ||
| import React, {useRef, useCallback} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import {PortalHost} from '@gorhom/portal'; | ||
| import Str from 'expensify-common/lib/str'; | ||
| import dragAndDropProviderPropTypes from './dragAndDropProviderPropTypes'; | ||
| import styles from '../../../styles/styles'; | ||
| import useDragAndDrop from '../../../hooks/useDragAndDrop'; | ||
|
|
||
| const DragAndDropContext = React.createContext({}); | ||
|
|
||
| /** | ||
| * @param {Event} event – drag event | ||
| * @returns {Boolean} | ||
| */ | ||
| function shouldAcceptDrop(event) { | ||
| return _.some(event.dataTransfer.types, (type) => type === 'Files'); | ||
| } | ||
|
|
||
| function DragAndDropProvider({children, isDisabled = false}) { | ||
| const dropZone = useRef(null); | ||
| const dropZoneID = useRef(Str.guid('drag-n-drop')); | ||
|
|
||
| const onDropHandler = useRef(() => {}); | ||
| const setOnDropHandler = useCallback((callback) => { | ||
| onDropHandler.current = callback; | ||
| }, []); | ||
|
|
||
| const {isDraggingOver} = useDragAndDrop({ | ||
| dropZone, | ||
| onDrop: onDropHandler.current, | ||
| shouldAcceptDrop, | ||
| isDisabled, | ||
| }); | ||
|
|
||
| return ( | ||
| <DragAndDropContext.Provider value={{isDraggingOver, setOnDropHandler, dropZoneID: dropZoneID.current}}> | ||
| <View | ||
| ref={(e) => (dropZone.current = e)} | ||
| style={[styles.flex1, styles.w100, styles.h100]} | ||
|
roryabraham marked this conversation as resolved.
|
||
| > | ||
| {isDraggingOver && ( | ||
| <View style={[styles.fullScreen, styles.invisibleOverlay]}> | ||
| <PortalHost name={dropZoneID.current} /> | ||
| </View> | ||
| )} | ||
| {children} | ||
| </View> | ||
| </DragAndDropContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| DragAndDropProvider.propTypes = dragAndDropProviderPropTypes; | ||
| DragAndDropProvider.displayName = 'DragAndDropProvider'; | ||
|
|
||
| export default DragAndDropProvider; | ||
| export {DragAndDropContext}; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import dragAndDropProviderPropTypes from './dragAndDropProviderPropTypes'; | ||
|
|
||
| const DragAndDropContext = {}; | ||
|
|
||
| function DragAndDropProvider({children}) { | ||
| return children; | ||
| } | ||
|
|
||
| DragAndDropProvider.propTypes = dragAndDropProviderPropTypes; | ||
| DragAndDropProvider.displayName = 'DragAndDropProvider'; | ||
|
|
||
| export default DragAndDropProvider; | ||
| export {DragAndDropContext}; |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.