Skip to content

Commit 7787d2f

Browse files
javachemeta-codesync[bot]
authored andcommitted
Move RCTAnimatedModuleProvider to open-source (#54096)
Summary: Pull Request resolved: #54096 Exporting this since we have some incoming changes to Animated which okwasniewski wants to make and should be applied to CxxAnimated too. This is not hooked up to any OSS apps yet. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D84200113 fbshipit-source-id: 7a278ebf3f9c2b0779971591804d3fbd89ce4723
1 parent e5e8e63 commit 7787d2f

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#import <memory>
11+
#import <string>
12+
13+
#import <Foundation/Foundation.h>
14+
15+
namespace facebook::react {
16+
class CallInvoker;
17+
class TurboModule;
18+
} // namespace facebook::react
19+
20+
@interface RCTAnimatedModuleProvider : NSObject
21+
22+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
23+
jsInvoker:
24+
(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker;
25+
26+
@end
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "RCTAnimatedModuleProvider.h"
9+
10+
#import <functional>
11+
12+
#if TARGET_OS_OSX
13+
#import <React/RCTPlatformDisplayLink.h>
14+
#else
15+
#import <QuartzCore/CADisplayLink.h>
16+
#endif
17+
#import <react/renderer/animated/AnimatedModule.h>
18+
#import <react/renderer/animated/NativeAnimatedNodesManagerProvider.h>
19+
20+
@implementation RCTAnimatedModuleProvider {
21+
#if TARGET_OS_OSX
22+
RCTPlatformDisplayLink *_displayLink;
23+
#else
24+
CADisplayLink *_displayLink;
25+
#endif
26+
std::function<void()> _onRender;
27+
}
28+
29+
- (void)_onDisplayLinkTick
30+
{
31+
if (_displayLink != nullptr && _onRender != nullptr) {
32+
_onRender();
33+
}
34+
}
35+
36+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
37+
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
38+
{
39+
if (facebook::react::ReactNativeFeatureFlags::cxxNativeAnimatedEnabled()) {
40+
if (name == facebook::react::AnimatedModule::kModuleName) {
41+
auto provider = std::make_shared<facebook::react::NativeAnimatedNodesManagerProvider>(
42+
[self](std::function<void()> &&onRender) {
43+
_onRender = onRender;
44+
if (_displayLink == nil) {
45+
#if TARGET_OS_OSX
46+
_displayLink = [RCTPlatformDisplayLink displayLinkWithTarget:self selector:@selector(_onDisplayLinkTick)];
47+
#else
48+
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(_onDisplayLinkTick)];
49+
#endif
50+
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
51+
}
52+
},
53+
[self]() {
54+
if (_displayLink != nil) {
55+
[_displayLink invalidate];
56+
_displayLink = nil;
57+
_onRender = nullptr;
58+
}
59+
});
60+
return std::make_shared<facebook::react::AnimatedModule>(std::move(jsInvoker), std::move(provider));
61+
}
62+
}
63+
return nullptr;
64+
}
65+
66+
@end

0 commit comments

Comments
 (0)