Skip to content

Commit 7eb6c62

Browse files
LFDanLureidbarber
andauthored
fixing multiple row dragging in Android (#3174)
Co-authored-by: Reid Barber <[email protected]>
1 parent 32be2d9 commit 7eb6c62

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

packages/@react-spectrum/list/stories/ListView.stories.tsx

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,7 @@ storiesOf('ListView/Drag and Drop', module)
398398
<DragExample listViewProps={{onAction: action('onAction'), ...args}} dragHookOptions={{onDragStart: action('dragStart'), onDragEnd: action('dragEnd')}} />
399399
</Flex>
400400
), {description: {data: 'Folders are non-draggable.'}}
401-
)
402-
.add(
403-
'draggable rows, selectionStyle: highlight, onAction',
404-
args => (
405-
<Flex direction="row" wrap alignItems="center">
406-
<input />
407-
<Droppable />
408-
<DragExample listViewProps={{selectionStyle: 'highlight', onAction: action('onAction'), ...args}} dragHookOptions={{onDragStart: action('dragStart'), onDragEnd: action('dragEnd')}} />
409-
</Flex>
410-
), {description: {data: 'Folders are non-draggable.'}});
401+
);
411402

412403
function renderActionsExample(renderActions, props?) {
413404
return (
@@ -678,12 +669,12 @@ export function ReorderExample(props) {
678669
let key;
679670
if (item.types.has(dragType)) {
680671
key = JSON.parse(await item.getText(dragType));
672+
keys.push(key);
681673
} else if (item.types.has('text/plain')) {
682674
// Fallback for Chrome Android case: https://bugs.chromium.org/p/chromium/issues/detail?id=1293803
683-
key = JSON.parse(await item.getText('text/plain'));
684-
}
685-
if (key) {
686-
keys.push(key);
675+
// Multiple drag items are contained in a single string so we need to split them out
676+
key = await item.getText('text/plain');
677+
keys = key.split('\n').map(val => val.replaceAll('"', ''));
687678
}
688679
}
689680
}
@@ -768,12 +759,12 @@ export function DragIntoItemExample(props) {
768759
let key;
769760
if (item.types.has(dragType)) {
770761
key = JSON.parse(await item.getText(dragType));
762+
keys.push(key);
771763
} else if (item.types.has('text/plain')) {
772764
// Fallback for Chrome Android case: https://bugs.chromium.org/p/chromium/issues/detail?id=1293803
773-
key = JSON.parse(await item.getText('text/plain'));
774-
}
775-
if (key) {
776-
keys.push(key);
765+
// Multiple drag items are contained in a single string so we need to split them out
766+
key = await item.getText('text/plain');
767+
keys = key.split('\n').map(val => val.replaceAll('"', ''));
777768
}
778769
}
779770
}
@@ -876,12 +867,12 @@ export function DragBetweenListsExample(props) {
876867
let key;
877868
if (item.types.has(dragType)) {
878869
key = JSON.parse(await item.getText(dragType));
870+
keys.push(key);
879871
} else if (item.types.has('text/plain')) {
880872
// Fallback for Chrome Android case: https://bugs.chromium.org/p/chromium/issues/detail?id=1293803
881-
key = JSON.parse(await item.getText('text/plain'));
882-
}
883-
if (key) {
884-
keys.push(key);
873+
// Multiple drag items are contained in a single string so we need to split them out
874+
key = await item.getText('text/plain');
875+
keys = key.split('\n').map(val => val.replaceAll('"', ''));
885876
}
886877
}
887878
}
@@ -996,12 +987,12 @@ export function DragBetweenListsRootOnlyExample(props) {
996987
let key;
997988
if (item.types.has('list2')) {
998989
key = JSON.parse(await item.getText('list2'));
990+
keys.push(key);
999991
} else if (item.types.has('text/plain')) {
1000992
// Fallback for Chrome Android case: https://bugs.chromium.org/p/chromium/issues/detail?id=1293803
1001-
key = JSON.parse(await item.getText('text/plain'));
1002-
}
1003-
if (key) {
1004-
keys.push(key);
993+
// Multiple drag items are contained in a single string so we need to split them out
994+
key = await item.getText('text/plain');
995+
keys = key.split('\n').map(val => val.replaceAll('"', ''));
1005996
}
1006997
}
1007998
}
@@ -1010,7 +1001,7 @@ export function DragBetweenListsRootOnlyExample(props) {
10101001
}
10111002
},
10121003
getDropOperation(target, types) {
1013-
if (target.type === 'root' && types.has('list2')) {
1004+
if (target.type === 'root' && (types.has('list2') || types.has('text/plain'))) {
10141005
return 'move';
10151006
}
10161007

@@ -1028,12 +1019,12 @@ export function DragBetweenListsRootOnlyExample(props) {
10281019
let key;
10291020
if (item.types.has('list1')) {
10301021
key = JSON.parse(await item.getText('list1'));
1022+
keys.push(key);
10311023
} else if (item.types.has('text/plain')) {
10321024
// Fallback for Chrome Android case: https://bugs.chromium.org/p/chromium/issues/detail?id=1293803
1033-
key = JSON.parse(await item.getText('text/plain'));
1034-
}
1035-
if (key) {
1036-
keys.push(key);
1025+
// Multiple drag items are contained in a single string so we need to split them out
1026+
key = await item.getText('text/plain');
1027+
keys = key.split('\n').map(val => val.replaceAll('"', ''));
10371028
}
10381029
}
10391030
}
@@ -1042,7 +1033,7 @@ export function DragBetweenListsRootOnlyExample(props) {
10421033
}
10431034
},
10441035
getDropOperation(target, types) {
1045-
if (target.type === 'root' && types.has('list1')) {
1036+
if (target.type === 'root' && (types.has('list1') || types.has('text/plain'))) {
10461037
return 'move';
10471038
}
10481039

0 commit comments

Comments
 (0)