Skip to content

Commit 2a1e12f

Browse files
zeyapmeta-codesync[bot]
authored andcommitted
add dealloc function to RCTAnimatedModuleProvider (#54440)
Summary: Pull Request resolved: #54440 ## Changelog: [Internal] [Changed] - add dealloc function to RCTAnimatedModuleProvider just in case RCTAnimatedModuleProvider is destroyed earlier than AnimatedModule when react instance tears down, then when AnimatedModule (which owns NativeAnimatedNodesManager) is destroyed, even if StopOnRenderCallback is invoked, it doesn't invalidate displayLink (since strongSelf is nullptr) Reviewed By: javache Differential Revision: D86459439 fbshipit-source-id: 707bbe91228b9c062dfbb324fedca1914663650b
1 parent 7c91517 commit 2a1e12f

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

packages/react-native/ReactApple/RCTAnimatedModuleProvider/RCTAnimatedModuleProvider.mm

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@ @implementation RCTAnimatedModuleProvider {
2626
std::function<void()> _onRender;
2727
}
2828

29+
- (void)dealloc
30+
{
31+
if (_displayLink != nil) {
32+
#if TARGET_OS_OSX
33+
RCTPlatformDisplayLink *displayLink = _displayLink;
34+
#else
35+
CADisplayLink *displayLink = _displayLink;
36+
#endif
37+
_displayLink = nil;
38+
if ([NSThread isMainThread]) {
39+
[displayLink invalidate];
40+
} else {
41+
dispatch_sync(dispatch_get_main_queue(), ^{
42+
[displayLink invalidate];
43+
});
44+
}
45+
_onRender = nullptr;
46+
}
47+
}
48+
2949
- (void)_onDisplayLinkTick
3050
{
3151
if (_displayLink != nullptr && _onRender != nullptr) {
@@ -69,11 +89,16 @@ - (void)_onDisplayLinkTick
6989
const auto stop_render = [weakSelf]() {
7090
RCTAnimatedModuleProvider *strongSelf = weakSelf;
7191
if (strongSelf) {
72-
if (strongSelf->_displayLink != nil) {
73-
[strongSelf->_displayLink invalidate];
74-
strongSelf->_displayLink = nil;
75-
strongSelf->_onRender = nullptr;
92+
#if TARGET_OS_OSX
93+
RCTPlatformDisplayLink *displayLink = strongSelf->_displayLink;
94+
#else
95+
CADisplayLink *displayLink = strongSelf->_displayLink;
96+
#endif
97+
strongSelf->_displayLink = nil;
98+
if (displayLink != nil) {
99+
[displayLink invalidate];
76100
}
101+
strongSelf->_onRender = nullptr;
77102
}
78103
};
79104

0 commit comments

Comments
 (0)