-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
feat: coalesced event #592
Conversation
Co-authored-by: Jacob Parker <jacobparker1992@gmail.com>
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 for this!
Interesting it didn't fully resolve the issue. But at least it's not worse
Co-authored-by: Jacob Parker <jacobparker1992@gmail.com>
Added an example with only a useSafeAreaInsets() (not pushed) to double check and result are (iPad)
After
Even though there's still a double event, all data make sense now. I guess I don't want to add unnecessary complexity to the fabric variant, but I debugged and same results, so will apply there too |
Ok I think I know what's going on here. The batching is still useful to have, but I think the bug we're still having goes like this
I believe the fix here is when the safe area insets change, set a dirty flag rather than immediately firing an event. Then add an event listener for layout change events, and then if the dirty flag is set, fire the event You want to use the Don't feel you have to take this on, we'll still merge this PR because it is important. But if you do take it on, I'm happy to provide pointers |
I'm happy to continue this, but I cannot work on it now. If this can already be shipped it would be great. I need to add |
No - if you add |
@jacobp100 I've set a flag in
=> no events sent
=> I can toggle the flag once the event is emitted in |
Thanks for working on this! Are we good merging this as is? We can look at the other issue later, and might also want to implement in for new arch. Can you just run the formatting script again? |
@janicduplessis updated with clang format |
Summary
onInsetsChange
can sometimes be sent very quickly after another. Using the same technique as the ScrollView, we keep the view propertyonInsetsChange
, but it's triggered from a customRCTEvent
with a coalescingKey.If events are sent 5 times very quickly, only 1 event will be sent with the latest insets and frame.
Fixes #579 #485 #172
Note:
I've tested this in a real app and
onInsetsChange
calls goes from 3 to 1, but in the example app it doesn't change (still 3 calls when rotating) and that's because it doesn't change anything in batching which is good.So, if during a flush to JS 5
onInsetsChange
are sent only the last one will survive, but if the app isn't busy and it can send the 5 events independently it will.EventEmitter
will collect the event in a queue and then flush them. Coalesce changes a flush with multiple events from[onInsetsChange x1 y1, onInsetsChange x2 y2]
to[onInsetsChange x2 y2]
PS:
I've only implemented the old architecte, if this can be reviewed I can then only apply changes to this part and finish the fabric arch.
Requires
RCT_NEW_ARCH_ENABLED=0 pod install
to test.