Skip to content

Mac RCTDisplayLink fix plus bonus deprecated API cleanup #854

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

Merged
merged 8 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions React/Base/RCTDisplayLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ - (void)dealloc

- (void)invalidate
{
// ensure observer callbacks do not hold a reference to weak self via pauseCallback
for (RCTModuleData *moduleData in _frameUpdateObservers) {
id<RCTFrameUpdateObserver> observer = (id<RCTFrameUpdateObserver>)moduleData.instance;
[observer setPauseCallback:nil];
}
[_frameUpdateObservers removeAllObjects]; // just to be explicit

[_jsDisplayLink invalidate];
}

Expand Down Expand Up @@ -146,14 +153,13 @@ - (void)updateJSDisplayLinkState
BOOL pauseDisplayLink = YES;
for (RCTModuleData *moduleData in _frameUpdateObservers) {
id<RCTFrameUpdateObserver> observer = (id<RCTFrameUpdateObserver>)moduleData.instance;
BOOL validObserverProtocol = [observer conformsToProtocol:@protocol(RCTFrameUpdateObserver)]; // [TODO: GH#774- add protocol check before accessing data
RCTAssert(validObserverProtocol, @"Observer does not conform to necessary protocol (RCTFrameUpdateObserver)");
if (validObserverProtocol && !observer.paused) { // TODO: GH#774- add protocol check before accessing data]
if (!observer.paused) {
pauseDisplayLink = NO;
break;
}
}

// Update the state of display link (call start/stop)
_jsDisplayLink.paused = pauseDisplayLink;
}

Expand Down
1 change: 1 addition & 0 deletions React/Base/macOS/RCTPlatformDisplayLink.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ - (void)dealloc
if (_displayLink != NULL) {
CVDisplayLinkStop(_displayLink);
CVDisplayLinkRelease(_displayLink);
_displayLink = NULL;
}
}

Expand Down