-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
af9c215
commit 2dfb621
Showing
14 changed files
with
230 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
// @flow | ||
import type { State } from '../../types'; | ||
import type { DraggingState, BulkCollectionState } from '../../types'; | ||
|
||
type UserDragState = DraggingState | BulkCollectionState; | ||
|
||
export type AutoScroller = {| | ||
onStateChange: (previous: State, current: State) => void, | ||
cancel: () => void, | ||
jumpScroll: (state: UserDragState) => void, | ||
fluidScroll: (state: UserDragState) => void, | ||
|} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
// @flow | ||
import { bindActionCreators } from 'redux'; | ||
import createAutoScroller from '../auto-scroller'; | ||
import type { AutoScroller } from '../auto-scroller/auto-scroller-types'; | ||
import { | ||
move, | ||
updateDroppableScroll, | ||
} from '../action-creators'; | ||
import scrollWindow from '../../view/window/scroll-window'; | ||
import isDragEnding from './util/is-drag-ending'; | ||
import type { | ||
Store, | ||
State, | ||
Action, | ||
} from '../../types'; | ||
|
||
export default (store: Store) => { | ||
const scroller: AutoScroller = createAutoScroller({ | ||
...bindActionCreators({ | ||
scrollDroppable: updateDroppableScroll, | ||
move, | ||
}, store.dispatch), | ||
scrollWindow, | ||
}); | ||
return (next: (Action) => mixed) => (action: Action): mixed => { | ||
// Need to cancel any pending auto scrolling when drag is ending | ||
if (isDragEnding(action)) { | ||
scroller.cancel(); | ||
next(action); | ||
return; | ||
} | ||
|
||
// auto scroll happens in response to state changes | ||
// releasing all actions to the reducer first | ||
next(action); | ||
|
||
const state: State = store.getState(); | ||
|
||
// Only want to auto scroll in the dragging phase | ||
// Not allowing auto scrolling while bulk collecting | ||
// This is to avoid a mismatch in scroll between the captured | ||
// viewport in one frame and published in the next | ||
// Also, jump scrolling would not occur during a BULK_COLLECTION | ||
// as no changes to the impact are permitted in that time | ||
if (state.phase !== 'DRAGGING') { | ||
return; | ||
} | ||
|
||
if (state.autoScrollMode === 'FLUID') { | ||
scroller.fluidScroll(state); | ||
return; | ||
} | ||
|
||
if (!state.scrollJumpRequest) { | ||
return; | ||
} | ||
|
||
scroller.jumpScroll(state); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
// @flow | ||
import { drop } from '../action-creators'; | ||
import type { | ||
Store, | ||
State, | ||
Action, | ||
} from '../../types'; | ||
|
||
export default (store: Store) => (next: (Action) => mixed) => (action: Action): mixed => { | ||
next(action); | ||
|
||
if (action.type !== 'BULK_REPLACE') { | ||
return; | ||
} | ||
|
||
// A bulk replace occurred - check if | ||
// 1. there was a pending drop | ||
// 2. that the pending drop is no longer waiting | ||
|
||
const postActionState: State = store.getState(); | ||
|
||
if (postActionState.phase !== 'DROP_PENDING') { | ||
return; | ||
} | ||
|
||
if (!postActionState.isWaiting) { | ||
console.log('ending a pending drop'); | ||
store.dispatch(drop({ | ||
reason: postActionState.reason, | ||
})); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// @flow | ||
import type { Action } from '../../../types'; | ||
|
||
export default (action: Action): boolean => | ||
action.type === 'CLEAN' || | ||
action.type === 'DROP_ANIMATE' || | ||
action.type === 'DROP_COMPLETE' || | ||
action.type === 'DROP_PENDING'; |
Oops, something went wrong.