-
Notifications
You must be signed in to change notification settings - Fork 273
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
API Proposal: User Event scroll
function
#1450
Comments
|
@flexbox re 5: that would be limited to single test case. i.e. scroll position would be remembered between two subsequent In real RN app, scroll position is most probably a native state (yoga might be involved as well?), you do not manage that through props like you would with a managed |
user.scrollTo({ y: [0, 10], momentumY: [30, 40] })
user.scrollTo({ y: [0], momentumY: [30] })
user.scrollTo({ y: [10], momentumY: [40] }) That leaves up the question of how often should Now if the steps are equivalent to multiple
user.scrollTo({ y: [30], momentumY: [30] }) Does it scroll to 30 with 30 momentum or does it scroll to 60 (30+30 momentum)? If it's the first should we throw if momentum is greater than y? Maybe this behavior could be described through ts-doc
|
re: It looks like it serves two purposes: emitting an onScroll event and also a separate scroll because you can provide momentum for each step (user would stop scrolling between each step). : Momentum will always follow the current direction (it prolongs the gesture) so my original intention was to give the possibility to specify it's value as an addition to the x or y value. re: Now if the steps are equivalent to multiple scrollTo calls I'm not sure it's worth supporting them : Not exactly.
|
@pierrezimmermannbam thanks for comments.
Will emit:
So that would be equivalent to:
|
Oh I see, I didn't understand that, that makes sense. In your example if the drag ends at 10 then shouldn't the momentum begin at 10? I'm still a bit afraid that this API is too complex and not easily understandable. I'm not convinced that steps bring value and imo they make the API way more complicated and also allow for incoherent values for the momentum like [0, 10, 0]. I can't find use cases where I'd use steps but maybe I haven't encountered some before, what cases can you think of? For now I think I'd prefer a more simpler API that would look like this: user.scrollTo({ x: 5, momentumX: 5}); That would emit scrollBeingDrag 0
scroll 5
scrollEndDrag 5 (experimantally there is on `scroll` event equal to `scrollEndDrag`)
momentumScrollBegin 5
scroll 10
momentumScrollEnd 10 You'd need to have the previous position of the scrollview to know in which direction the momentum is though. It's not great either though because it's still a bit unclear wether you scroll to 5 having included the momentum scroll or to 5 + 5. |
@pierrezimmermannbam re momentum scroll:
|
@pierrezimmermannbam, @siepra, @flexbox I wanted to run two ideas with you:
For both of these points we have couple of options:
@pierrezimmermannbam, @siepra, @flexbox I am curious which of these options you would see as the best, or perhaps some other approach? |
I think we should not allow the case where there is just momentum because it doesn't male sense and it's easily doable through typescript. Also you should not be able to have momentumX with y scroll. Maybe we don't even need momentumX or momentumY? We could have a type that would look like this: type NonEmptyArray<T> = [T, ...T[]];
type ScrollParams = ({
x: NonEmptyArray<number>;
} | {
y: NonEmptyArray<number>;
}) & {
momentum?: NonEmptyArray<number>;
} It's harder to prevent inputing values for momentum that make sense using typescript so in this case I think throwing would be my preferred solution. Either that or do nothing but I'm not a huge fan of warnings because they tend to be ignored |
re cross-axis scroll, e.g. re: error/warning/ignore approach: |
Even though it doesn't change much if user provides x and y, I think it's still a better DX to only allow one of them. This makes it clearer what you can and cannot do with the API |
In a real app, momentum will always prolong the current scroll direction, so it probably doesn't make sense to allow using it as a standalone value without providing X or Y first. Although, I think back-and-forth scroll step pattern sounds fine. This is just another idea: Momentum value depends on a velocity so it's hard for the user to accurately estimate it. If we wanted to simplify the API, maybe it's worth to just stick to a boolean, and calculate the momentum basing on length of a drag (let's say 1/4 of it), eg:
would emit
We can even extend the number of emitted |
@siepra
I imagine that majority of scroll tests will focus on scroll final position. Additionally, some test will want to check intermediate scroll position ( re details of intermediate steps:
|
How about instead of momentum increasing the target value, it stops at X but modifies the emitted events? I'd would work similar but maybe less confusing:
Remember I only mention it for sake of API simplification. I think the main question here is what's more important: consistency in terms of direction and final position or control over the number of intermediate events |
@siepra There is still the issue with in case user want's to specify exact scroll steps for drag/momentum scroll. If you have a single |
Of course, I agree. But in this case, someone may do weird combinations like |
I think we can all agree that the base API (single
This API should cover all users who want to test the final position of the scroll, without relying on details of intermediate scroll events. We could reduce the scope of the initial release and remove the explicit scroll steps ( @pierrezimmermannbam, @siepra wdyt? |
Sure, the smaller releases the better. This API seems fine. |
I agree, let's keep it simple for now, it should cover the vast majority of use cases and |
Resolved in #1445. |
@siepra is working User Event
scroll
API design, the code is quite advanced, so it's high time that we have a solid API with nice DX for that feature. There is no RTL's User Event API for scrolling, so we need to come up with our own. As a base for discussion, I have prepare an initial proposal.User Event scroll API
Base case
Note: the function is named
scrollTo
instead ofscroll
to remove ambiguity whether this is target value or relative value. Coincidently this is also the name of imperative handle for scrolling in RN.This will emit a sequence of
onScrollBeginDrag
,onScroll
(x N),onScrollEndDrag
.By default, the first scroll will start from (0, 0) and will emit default of 5
onScroll
intermediate steps between initial position and target position. Subsequent scrolls will start from where the last scroll (using User Event) ended.Intermediate steps
Explicit steps
Alternatively, you can pass exact steps that will be called as an array. First element is the initial position, and all other elements indicate subsequent steps. The number of steps will be equal to the length of the array.
Number of steps (alternative approach)
You can customize the intermediate steps by passing number of steps and/or ininitial position:
We probably should pick only one of the above. Based on my surveys with CK devs, the first one seems to be preferred.
Momentum scroll
Momentum scroll happens after initial sequence of
onScrollBeginDrag
,onScroll
(x N),onScrollEndDrag
when scroll view has some velocity (momentum) after user lifts the finger up. This will result in callingonMomentumScrollBegin
,onScroll
(x N),onMomentumScrollEnd
.By default
scrollBy
will only invoke drag scroll without momentum part. User can activate momentum scroll passingmomentumY
ormomentumX
variables:This can be linked with previous options:
If the user did not pass drag scroll position, then distance from last position, or default (0, 0), to target position will be divided equally between drag scroll and momentum scroll.
Please share your comments on all things involved, naming of function and options, ways of conveying ideas like intermediate steps, etc, etc. Feel free to challenge this design, propose alternatives, etc. The API is very flexible at this stage, changing it later will probably require breaking changes, etc.
Links
scrollTo
docsscrollTo
docsscroll
/scrollTo
docsSpecific questions:
scrollTo
orscroll
?steps
param,y: [0, 10, 20]
array or both? Or other perhaps?momentumY
params,momentum: boolean
param,user.momentumScrollTo()
function, or other perhaps?CC: @pierrezimmermannbam @AugustinLF @MattAgn @thymikee @siepra
The text was updated successfully, but these errors were encountered: