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

get drag impact refactor #92

Merged
merged 17 commits into from
Sep 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/state/action-creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export type CompleteLiftAction = {|
id: DraggableId,
type: TypeId,
client: InitialDragLocation,
page: InitialDragLocation,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed page from all these actions - easy to compute once with windowScroll in the reducer

windowScroll: Position,
isScrollAllowed: boolean,
|}
Expand All @@ -78,7 +77,6 @@ export type CompleteLiftAction = {|
const completeLift = (id: DraggableId,
type: TypeId,
client: InitialDragLocation,
page: InitialDragLocation,
windowScroll: Position,
isScrollAllowed: boolean,
): CompleteLiftAction => ({
Expand All @@ -87,7 +85,6 @@ const completeLift = (id: DraggableId,
id,
type,
client,
page,
windowScroll,
isScrollAllowed,
},
Expand Down Expand Up @@ -154,20 +151,17 @@ export type MoveAction = {|
payload: {|
id: DraggableId,
client: Position,
page: Position,
windowScroll: Position,
|}
|}

export const move = (id: DraggableId,
client: Position,
page: Position,
windowScroll: Position): MoveAction => ({
type: 'MOVE',
payload: {
id,
client,
page,
windowScroll,
},
});
Expand Down Expand Up @@ -421,7 +415,6 @@ export type LiftAction = {|
id: DraggableId,
type: TypeId,
client: InitialDragLocation,
page: InitialDragLocation,
windowScroll: Position,
isScrollAllowed: boolean,
|}
Expand All @@ -431,7 +424,6 @@ export type LiftAction = {|
export const lift = (id: DraggableId,
type: TypeId,
client: InitialDragLocation,
page: InitialDragLocation,
windowScroll: Position,
isScrollAllowed: boolean,
) => (dispatch: Dispatch, getState: Function) => {
Expand Down Expand Up @@ -471,7 +463,7 @@ export const lift = (id: DraggableId,
if (newState.phase !== 'COLLECTING_DIMENSIONS') {
return;
}
dispatch(completeLift(id, type, client, page, windowScroll, isScrollAllowed));
dispatch(completeLift(id, type, client, windowScroll, isScrollAllowed));
});
});
};
Expand Down
182 changes: 0 additions & 182 deletions src/state/get-drag-impact.js

This file was deleted.

61 changes: 61 additions & 0 deletions src/state/get-drag-impact/in-foreign-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// @flow
import type {
DraggableId,
DroppableId,
DragMovement,
DraggableDimension,
DroppableDimension,
DragImpact,
Axis,
Position,
} from '../../types';
import { add, subtract, patch } from '../position';

type Args = {|
pageCenter: Position,
draggable: DraggableDimension,
destination: DroppableDimension,
insideDestination: DraggableDimension[],
|}

export default ({
pageCenter,
draggable,
destination,
insideDestination,
}: Args): DragImpact => {
const axis: Axis = destination.axis;

const destinationScrollDiff: Position = subtract(
destination.scroll.current, destination.scroll.initial
);

const currentCenter: Position = add(pageCenter, destinationScrollDiff);

const moved: DraggableId[] = insideDestination
.filter((child: DraggableDimension): boolean => {
// Items will be displaced forward if they sit ahead of the dragging item
const threshold: number = child.page.withoutMargin[axis.end];
return threshold > currentCenter[axis.line];
})
.map((dimension: DraggableDimension): DroppableId => dimension.id);

const newIndex: number = insideDestination.length - moved.length;

const movement: DragMovement = {
amount: patch(axis.line, draggable.page.withMargin[axis.size]),
draggables: moved,
isBeyondStartPosition: false,
};

const impact: DragImpact = {
movement,
direction: axis.direction,
destination: {
droppableId: destination.id,
index: newIndex,
},
};

return impact;
};
Loading