Skip to content

Commit

Permalink
viewport is back in action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed May 21, 2018
1 parent 572df8b commit f5df39a
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 1,572 deletions.
2 changes: 2 additions & 0 deletions src/state/auto-scroller/jump-scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ export default ({
return;
}

console.warn('manual keyboard move', windowRemainder);

// The entire scroll could not be absorbed by the droppable and window
// so we manually move whatever is left
moveByOffset(state, windowRemainder);
Expand Down
5 changes: 5 additions & 0 deletions src/state/move-to-next-index/in-home-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export default ({
viewport: viewport.frame,
});

console.log('new page center', newPageBorderBoxCenter, 'is visible in frame', viewport.frame, isVisibleInNewLocation);


const displaced: Displacement[] = (() => {
if (isMovingTowardStart) {
return withFirstRemoved({
Expand Down Expand Up @@ -131,6 +134,8 @@ export default ({
const distance: Position = subtract(newPageBorderBoxCenter, previousPageBorderBoxCenter);
const distanceWithScroll: Position = withDroppableDisplacement(droppable, distance);

console.log('request jump scroll', distanceWithScroll);

return {
pageBorderBoxCenter: previousPageBorderBoxCenter,
impact: newImpact,
Expand Down
12 changes: 11 additions & 1 deletion src/state/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,17 @@ export default (state: State = idle, action: Action): State => {
return state;
}

invariant(isMovementAllowed(state), `MOVE not permitted in phase ${state.phase}`);

const { client, shouldAnimate } = action.payload;

// If we are jump scrolling - manual movements should not update the impact
const impact: ?DragImpact = state.autoScrollMode === 'JUMP' ? state.impact : null;

return moveWithPositionUpdates({
state,
clientSelection: client,
impact,
shouldAnimate,
});
}
Expand Down Expand Up @@ -425,9 +431,10 @@ export default (state: State = idle, action: Action): State => {
const isJumpScrolling: boolean = state.autoScrollMode === 'JUMP';
const impact: ?DragImpact = isJumpScrolling ? state.impact : null;

console.log('scrolling viewport in state');
const viewport: Viewport = scrollViewport(state.viewport, newScroll);

console.log('MOVE_BY_WINDOW_SCROLL: updating viewport to', viewport.frame);

return moveWithPositionUpdates({
state,
clientSelection: state.current.client.selection,
Expand All @@ -443,6 +450,8 @@ export default (state: State = idle, action: Action): State => {
return state;
}

console.warn(action.type);

invariant(state.phase === 'DRAGGING', `${action.type} received while not in DRAGGING phase`);

const { droppable, isMainAxisMovementAllowed } = (() => {
Expand Down Expand Up @@ -491,6 +500,7 @@ export default (state: State = idle, action: Action): State => {
if (!result) {
return state;
}

const impact: DragImpact = result.impact;
const pageBorderBoxCenter: Position = result.pageBorderBoxCenter;
// TODO: not sure if this is correct
Expand Down
8 changes: 4 additions & 4 deletions src/state/scroll-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export default (viewport: Viewport, newScroll: Position): Viewport => {
const diff: Position = subtract(newScroll, viewport.scroll.initial);
const displacement: Position = negate(diff);

// We need to update the frame so that it is always a live value
// The top / left of the frame should always match the newScroll position
const change: Position = subtract(diff, viewport.scroll.current);
const frame: Rect = getRect(
offsetByPosition(viewport.frame, diff)
offsetByPosition(viewport.frame, change)
);

console.log('scroll change recorded:', diff);
console.log('window scroll is now', newScroll)

const updated: Viewport = {
frame,
scroll: {
Expand Down
2 changes: 2 additions & 0 deletions src/view/drag-handle/sensor/create-keyboard-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export default ({

// cannot lift at this time
if (!canStartCapturing(event)) {
// need to block to prevent default browser behaviour
event.preventDefault();
return;
}

Expand Down
1 change: 1 addition & 0 deletions src/view/drag-handle/sensor/create-touch-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ export default ({
return;
}

// TODO: call prevent default here?
if (!canStartCapturing(event)) {
return;
}
Expand Down
224 changes: 0 additions & 224 deletions test/unit/state/action-creators.spec.js

This file was deleted.

16 changes: 8 additions & 8 deletions test/unit/state/auto-scroll/can-scroll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const scrollable: DroppableDimension = getDroppableDimension({
});

const customViewport: Viewport = createViewport({
subject: getRect({
frame: getRect({
top: 0,
left: 0,
right: 100,
Expand Down Expand Up @@ -414,7 +414,7 @@ describe('can scroll', () => {
describe('can scroll window', () => {
it('should return true if the window is able to be scrolled', () => {
const viewport: Viewport = createViewport({
subject: customViewport.subject,
frame: customViewport.frame,
scrollHeight: 200,
scrollWidth: 100,
scroll: origin,
Expand All @@ -427,7 +427,7 @@ describe('can scroll', () => {

it('should return false if the window is not able to be scrolled', () => {
const viewport: Viewport = createViewport({
subject: customViewport.subject,
frame: customViewport.frame,
scrollHeight: 200,
scrollWidth: 100,
// already at the max scroll
Expand Down Expand Up @@ -500,7 +500,7 @@ describe('can scroll', () => {
describe('get window overlap', () => {
it('should return null if the window cannot be scrolled', () => {
const viewport: Viewport = createViewport({
subject: customViewport.subject,
frame: customViewport.frame,
scrollHeight: 200,
scrollWidth: 100,
// already at the max scroll
Expand All @@ -518,7 +518,7 @@ describe('can scroll', () => {
// tested in get remainder
it('should return the overlap', () => {
const viewport: Viewport = createViewport({
subject: customViewport.subject,
frame: customViewport.frame,
scrollHeight: 200,
scrollWidth: 200,
scroll: {
Expand All @@ -531,8 +531,8 @@ describe('can scroll', () => {
const maxScroll: Position = getMaxScroll({
scrollHeight: 200,
scrollWidth: 200,
height: viewport.subject.height,
width: viewport.subject.width,
height: viewport.frame.height,
width: viewport.frame.width,
});
expect(maxScroll).toEqual({ x: 100, y: 100 });

Expand All @@ -551,7 +551,7 @@ describe('can scroll', () => {

it('should return null if there is no overlap', () => {
const viewport: Viewport = createViewport({
subject: customViewport.subject,
frame: customViewport.frame,
scrollHeight: 200,
scrollWidth: 200,
scroll: origin,
Expand Down
Loading

0 comments on commit f5df39a

Please sign in to comment.