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

[DataGridPro] Fix column reordering on Android #9394

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

m4theushw
Copy link
Member

@m4theushw m4theushw commented Jun 19, 2023

@m4theushw m4theushw added the component: data grid This is the name of the generic UI component, not the React module! label Jun 19, 2023
@mui-bot
Copy link

mui-bot commented Jun 19, 2023

Netlify deploy preview

Netlify deploy preview: https://deploy-preview-9394--material-ui-x.netlify.app/

Updated pages

No updates.

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 428.7 883.8 678.1 630.52 171.745
Sort 100k rows ms 474 880.5 819.7 766.04 147.712
Select 100k rows ms 186.7 291.7 253.8 250.92 35.327
Deselect 100k rows ms 128.7 296 202.3 195.34 58.293

Generated by 🚫 dangerJS against 71feb8b

@m4theushw
Copy link
Member Author

m4theushw commented Jun 19, 2023

@mui/xgrid Could someone test on an iPhone/iPad if the fix works?

@m4theushw m4theushw changed the title [DataGridPro] Fix column reordering on mobile [DataGridPro] Fix column reordering on Android Jul 3, 2023
@m4theushw m4theushw marked this pull request as ready for review July 3, 2023 20:47
event.stopPropagation();
}, []);
const handleDragEnter = useEventCallback(
(params: GridCellParams | GridColumnHeaderParams, event: React.DragEvent) => {
Copy link
Member

Choose a reason for hiding this comment

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

We can avoid typing arguments here by adding this overload for useEventCallback that would match the React.useCallback signature:

declare module '@mui/utils' {
  // eslint-disable-next-line @typescript-eslint/naming-convention
  export function unstable_useEventCallback<T extends Function>(fn: T): T;
}

Then it will be easier to switch from React.useCallback to useEventCallback:

-const handleDragEnter = React.useCallback<
+const handleDragEnter = useEventCallback<
    GridEventListener<'cellDragEnter' | 'columnHeaderDragEnter'>
  >((params, event) => {

Meanwhile, I'll add this overload for unstable_useEventCallback in the core repo.

Co-authored-by: Andrew Cherniavskii <[email protected]>
Signed-off-by: Matheus Wichman <[email protected]>
…/useGridColumnReorder.tsx

Co-authored-by: Danail Hadjiatanasov <[email protected]>
Signed-off-by: Matheus Wichman <[email protected]>
Signed-off-by: Matheus Wichman <[email protected]>
@m4theushw
Copy link
Member Author

@cherniavskii could you test again on iOS? After changing the MIME type to text/html it stopped working on Android so I'm trying text now.

@cherniavskii
Copy link
Member

I've checked different MIME types on iOS 16.5.1:

MIME type Safari Chrome
text ❌ (opens search page on drag end)
text/plain ❌ (opens search page on drag end)
text/html
text/x-data-grid

Comment on lines +326 to +327
event.clientY < rect.top ||
event.clientY > rect.bottom;
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, this doesn't work in Safari.
For some reason, clientX/clientY values are wrong during the dragend event:

safari-clientY.mov

I've found a similar issue mentioned here:

the clientX/screenX and clientY/screenY coordinates are simply wrong. I have no idea what they report. They don't even depend on where you touch.
https://horstmann.com/unblog/2018-12-16/index.html

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried text/x-data-grid and it also doesn't work on Android. I don't know which MIME type to use since no one works correctly in both platforms. I think it would be better to ditch the HTML drag'n'drop API on mobile and use touch events like https://github.com/react-dnd/react-dnd/ does.

@m4theushw
Copy link
Member Author

@cherniavskii could you test again? I added a condition to use different MIME types depending on the platform.

@cherniavskii
Copy link
Member

@m4theushw Yes, the MIME type works in both Safari and Chrome on iOS.
But there's still an issue with clientX/clientY in Safari - see #9394 (comment)
Maybe we could use event.dataTransfer.dropEffect by default, and calculate hasDroppedOutside on Android only?

@michelengelen michelengelen changed the base branch from master to next November 6, 2023 14:27
@flaviendelangle
Copy link
Member

@cherniavskii @DanailH does it make sense to keep this PR?
If so, somebody should probably take the ownership

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 7, 2024
Copy link

github-actions bot commented Feb 7, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@MBilalShafi MBilalShafi changed the base branch from next to master March 21, 2024 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! PR: out-of-date The pull request has merge conflicts and can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGridPro] Column reordering does not work on touchscreen
5 participants