-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[iOS] Fabric: Added ScrollEndDragEvent for scrollEndDrag event #48319
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for working on this. I left some comments as the current solution is not exactly equivalent to the current implementation and we can introduce subtle bugs.
@@ -530,9 +530,8 @@ - (BOOL)_shouldDisableScrollInteraction | |||
return NO; | |||
} | |||
|
|||
- (ScrollViewEventEmitter::Metrics)_scrollViewMetrics | |||
- (void)_setScrollViewMetrics:(ScrollViewEventEmitter::Metrics &)metrics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this approach is not really iOS-sy...
What do you feel about having two methods: _scrollViewMetrics
and _scrollViewMetricsWithVelocity:(CGPoint)velocity andTargetContentOffset:(CGPoint)targetContentOffset
?
The first one, behaves as before. The second one does:
auto metrics = [self __scrollViewMetrics];
metrics.targetContentOffset.x = targetContentOffset->x;
metrics.targetContentOffset.y = targetContentOffset->y;
metrics.velocity.x = velocity.x;
metrics.velocity.y = velocity.y;
return metrics;
This should also minimize the changes in RCTScrollViewComponentView
.
...s/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm
Show resolved
Hide resolved
dispatchScrollViewEvent("scrollEndDrag", scrollEvent); | ||
const ScrollEndDragEvent& scrollEvent) const { | ||
dispatchEvent( | ||
"scrollEndDrag", std::make_shared<ScrollEndDragEvent>(scrollEvent)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need to create a new pointer with make_shared
here.
The type of the scrollEvent is already the right one. If previously we were passing the scrollEvent, we should be able to pass the scrollEvent even now, types should match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cipolleschi Previously we call dispatchScrollViewEvent
but it std::make_shared to create ScrollEvent
shared ptr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ScrollEndDragEvent
event is a subclass of ScrollEvent
, we probably don't need to change this method at all, as you are allowed to pass a subclass to a method that accepts a superclass. The language should take care of it. (LSP - Liskov substitution principle)
Can you remove these changes and test if this works properly without these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a couple of extra comments that I missed yesterday, sorry!
dispatchScrollViewEvent("scrollEndDrag", scrollEvent); | ||
const ScrollEndDragEvent& scrollEvent) const { | ||
dispatchEvent( | ||
"scrollEndDrag", std::make_shared<ScrollEndDragEvent>(scrollEvent)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ScrollEndDragEvent
event is a subclass of ScrollEvent
, we probably don't need to change this method at all, as you are allowed to pass a subclass to a method that accepts a superclass. The language should take care of it. (LSP - Liskov substitution principle)
Can you remove these changes and test if this works properly without these?
using EndDragMetrics = ScrollEndDragEvent; | ||
|
||
void onScroll(const ScrollEvent& scrollEvent) const; | ||
void onScrollBeginDrag(const ScrollEvent& scrollEvent) const; | ||
void onScrollEndDrag(const ScrollEvent& scrollEvent) const; | ||
void onScrollEndDrag(const ScrollEndDragEvent& scrollEvent) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for LSP, these changes should not be needed.
@@ -26,7 +26,15 @@ void ScrollViewEventEmitter::onScrollBeginDrag( | |||
|
|||
void ScrollViewEventEmitter::onScrollEndDrag( | |||
const ScrollEvent& scrollEvent) const { | |||
dispatchScrollViewEvent("scrollEndDrag", scrollEvent); | |||
const auto* endDragScrollEvent = | |||
dynamic_cast<const ScrollEndDragEvent*>(&scrollEvent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cipolleschi Hi, this is the another way by dynamic_cast
scrollEvent
to ScrollEndDragEvent
if we removed those changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uhm... sorry for the extra back and forth.
I tested locally and actually I prefer the previous version with the properly typed methods and without the cast.
I haven't realized that even if the dispatchScrollViewEvent
takes an endDragScrollEvent
, it then creates a shared pointer of type ScrollEvent
: creating the new event pointer with explicit ScrollEvent type makes us lose the information of the actual subclass and therefore we can't serialize the event properly. :(
I modified the imported code, nothing required to do on your side! 😉
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary:
Fixes #42533 .
Changelog:
[IOS] [FIXED] - Fabric: Added ScrollEndDragEvent for scrollEndDrag event
Test Plan:
Repro please see #42533 .