-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: setup dummy scroll endpoint * chore: use ScrollEventBuilder * chore: enhance API endpoint with parameters * chore: emit multiple scroll events * fix: intermediate steps offset values * feat: momentum scroll * chore: add scroll to userEvent * feat: scrollToTop * feat: remember scroll position for element * fix: setting and getting scroll state * chore: validate host component type * chore: validate and emit intermediate callbacks in scrollToTop * chore: fix ts * refactor: rename scroll to scrollTo * refactor: y & x scrollTo params * refactor: refactor y, x params to support explicit steps * chore: fix typecheck * refactor: improve typing * refactor: momentumY, momentumX options * docs: initial docs for `scrollTo` * refactor: descope `scrollToTop` variant * docs: tweaks * refactor: improve TS typing by separating vertical/horizontal scroll * refactor: wrap scroll event in nativeEvent wrapper * refactor: clean up implementation * chore: add FlatList tests * refactor: remove explicit steps * refactor: introduce inertial interpolator for momentum scroll * docs: update docs * chore: update snapshots * refactor: code review changes * feat: validate scroll direction * docs: tweaks * docs: tweak * refactor: add more tests to improve code cov * refactor: improve errors * refactor: code review tweaks * refactor: add wait calls * refactor: tweaks, tweaks, tweaks * refactor: final tweaks --------- Co-authored-by: Maciej Jastrzębski <[email protected]>
- Loading branch information
1 parent
3b9c4da
commit a7ea95d
Showing
19 changed files
with
1,017 additions
and
3 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
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,10 @@ | ||
export function pick<T extends {}>(object: T, keys: (keyof T)[]): Partial<T> { | ||
const result: Partial<T> = {}; | ||
keys.forEach((key) => { | ||
if (object[key] !== undefined) { | ||
result[key] = object[key]; | ||
} | ||
}); | ||
|
||
return result; | ||
} |
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,4 +1,4 @@ | ||
interface EventEntry { | ||
export interface EventEntry { | ||
name: string; | ||
payload: any; | ||
} | ||
|
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,7 +1,9 @@ | ||
import { CommonEventBuilder } from './common'; | ||
import { ScrollViewEventBuilder } from './scroll-view'; | ||
import { TextInputEventBuilder } from './text-input'; | ||
|
||
export const EventBuilder = { | ||
Common: CommonEventBuilder, | ||
ScrollView: ScrollViewEventBuilder, | ||
TextInput: TextInputEventBuilder, | ||
}; |
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,32 @@ | ||
/** | ||
* Experimental values: | ||
* - iOS: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 5.333333333333333}, "contentSize": {"height": 1676.6666259765625, "width": 390}, "layoutMeasurement": {"height": 753, "width": 390}, "zoomScale": 1}` | ||
* - Android: `{"contentInset": {"bottom": 0, "left": 0, "right": 0, "top": 0}, "contentOffset": {"x": 0, "y": 31.619047164916992}, "contentSize": {"height": 1624.761962890625, "width": 411.4285583496094}, "layoutMeasurement": {"height": 785.5238037109375, "width": 411.4285583496094}, "responderIgnoreScroll": true, "target": 139, "velocity": {"x": -1.3633992671966553, "y": -1.3633992671966553}}` | ||
*/ | ||
|
||
/** | ||
* Scroll position of a scrollable element. | ||
*/ | ||
export interface ContentOffset { | ||
y: number; | ||
x: number; | ||
} | ||
|
||
export const ScrollViewEventBuilder = { | ||
scroll: (offset: ContentOffset = { y: 0, x: 0 }) => { | ||
return { | ||
nativeEvent: { | ||
contentInset: { bottom: 0, left: 0, right: 0, top: 0 }, | ||
contentOffset: { y: offset.y, x: offset.x }, | ||
contentSize: { height: 0, width: 0 }, | ||
layoutMeasurement: { | ||
height: 0, | ||
width: 0, | ||
}, | ||
responderIgnoreScroll: true, | ||
target: 0, | ||
velocity: { y: 0, x: 0 }, | ||
}, | ||
}; | ||
}, | ||
}; |
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
161 changes: 161 additions & 0 deletions
161
src/user-event/scroll/__tests__/__snapshots__/scrollTo-flatList.tsx.snap
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,161 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`scrollTo() with FlatList supports vertical drag scroll: scrollTo({ y: 100 }) 1`] = ` | ||
[ | ||
{ | ||
"name": "scrollBeginDrag", | ||
"payload": { | ||
"nativeEvent": { | ||
"contentInset": { | ||
"bottom": 0, | ||
"left": 0, | ||
"right": 0, | ||
"top": 0, | ||
}, | ||
"contentOffset": { | ||
"x": 0, | ||
"y": 0, | ||
}, | ||
"contentSize": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"layoutMeasurement": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"responderIgnoreScroll": true, | ||
"target": 0, | ||
"velocity": { | ||
"x": 0, | ||
"y": 0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"name": "scroll", | ||
"payload": { | ||
"nativeEvent": { | ||
"contentInset": { | ||
"bottom": 0, | ||
"left": 0, | ||
"right": 0, | ||
"top": 0, | ||
}, | ||
"contentOffset": { | ||
"x": 0, | ||
"y": 25, | ||
}, | ||
"contentSize": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"layoutMeasurement": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"responderIgnoreScroll": true, | ||
"target": 0, | ||
"velocity": { | ||
"x": 0, | ||
"y": 0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"name": "scroll", | ||
"payload": { | ||
"nativeEvent": { | ||
"contentInset": { | ||
"bottom": 0, | ||
"left": 0, | ||
"right": 0, | ||
"top": 0, | ||
}, | ||
"contentOffset": { | ||
"x": 0, | ||
"y": 50, | ||
}, | ||
"contentSize": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"layoutMeasurement": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"responderIgnoreScroll": true, | ||
"target": 0, | ||
"velocity": { | ||
"x": 0, | ||
"y": 0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"name": "scroll", | ||
"payload": { | ||
"nativeEvent": { | ||
"contentInset": { | ||
"bottom": 0, | ||
"left": 0, | ||
"right": 0, | ||
"top": 0, | ||
}, | ||
"contentOffset": { | ||
"x": 0, | ||
"y": 75, | ||
}, | ||
"contentSize": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"layoutMeasurement": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"responderIgnoreScroll": true, | ||
"target": 0, | ||
"velocity": { | ||
"x": 0, | ||
"y": 0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
"name": "scrollEndDrag", | ||
"payload": { | ||
"nativeEvent": { | ||
"contentInset": { | ||
"bottom": 0, | ||
"left": 0, | ||
"right": 0, | ||
"top": 0, | ||
}, | ||
"contentOffset": { | ||
"x": 0, | ||
"y": 100, | ||
}, | ||
"contentSize": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"layoutMeasurement": { | ||
"height": 0, | ||
"width": 0, | ||
}, | ||
"responderIgnoreScroll": true, | ||
"target": 0, | ||
"velocity": { | ||
"x": 0, | ||
"y": 0, | ||
}, | ||
}, | ||
}, | ||
}, | ||
] | ||
`; |
Oops, something went wrong.