-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Initialize CADisplayLink on UI thread #4694
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.
I think we also need to do the same think with displayLink from KeyboardEventObserver
Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
ios/REANodesManager.mm
Outdated
_displayLink.preferredFramesPerSecond = 120; // will fallback to 60 fps for devices without Pro Motion display | ||
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes]; | ||
[_displayLink setPaused:true]; | ||
}); |
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.
Similarly here, with an async init, couldn't it be possible to init this REANodesManager
and immediately try to use _displayLink
before it's initialized in something like - (void)invalidate
or - (void)postOnAnimation:(REAOnAnimationCallback)clb
?
ios/REANodesManager.mm
Outdated
[_displayLink setPaused:true]; | ||
__weak __typeof__(self) weakSelf = self; | ||
|
||
RCTExecuteOnMainQueue(^void() { |
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 feel like a better approach here would be to update displayLink usages to access it using getter. then in the getter we'd optionally initialize. It is important that the display link is both created and accessed on the UI thread. So we could also add some assertions to verify that. Schedulinng initialization may have its own problems as we don't want to guarantee that the field wouldn't be used before the task gets executed
ios/REANodesManager.mm
Outdated
if (_displayLink) { | ||
[_displayLink setPaused:true]; | ||
} | ||
[[self getDisplayLink] setPaused:true]; |
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.
[[self getDisplayLink] setPaused:true]; | |
[[self getDisplayLink] setPaused:YES]; |
ios/REANodesManager.mm
Outdated
@@ -211,19 +216,16 @@ - (instancetype)initWithModule:(REAModule *)reanimatedModule uiManager:(RCTUIMan | |||
_viewRegistry = [_uiManager valueForKey:@"_viewRegistry"]; | |||
_shouldFlushUpdateBuffer = false; | |||
} | |||
#endif | |||
[[self getDisplayLink] setPaused:true]; |
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.
[[self getDisplayLink] setPaused:true]; | |
[[self getDisplayLink] setPaused:YES]; |
@@ -173,6 +173,18 @@ @implementation REANodesManager { | |||
#endif | |||
} | |||
|
|||
- (CADisplayLink *)getDisplayLink | |||
{ | |||
RCTAssertMainQueue(); |
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.
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.
Summary
Some users have observed following thread lock:
Error log
This PR moves initialisation of CADisplayLink into UI thread, which may solve the problem
Test plan