mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Move RCTAnimatedModuleProvider to open-source (#54096)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
1 parent
e5e8e637db
commit
7787d2fbb5
2 files changed
+92
No files matched your search
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <memory>
|
||||
#import <string>
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
namespace facebook::react {
|
||||
class CallInvoker;
|
||||
class TurboModule;
|
||||
} // namespace facebook::react
|
||||
|
||||
@interface RCTAnimatedModuleProvider : NSObject
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
||||
jsInvoker:
|
||||
(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker;
|
||||
|
||||
@end
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTAnimatedModuleProvider.h"
|
||||
|
||||
#import <functional>
|
||||
|
||||
#if TARGET_OS_OSX
|
||||
#import <React/RCTPlatformDisplayLink.h>
|
||||
#else
|
||||
#import <QuartzCore/CADisplayLink.h>
|
||||
#endif
|
||||
#import <react/renderer/animated/AnimatedModule.h>
|
||||
#import <react/renderer/animated/NativeAnimatedNodesManagerProvider.h>
|
||||
|
||||
@implementation RCTAnimatedModuleProvider {
|
||||
#if TARGET_OS_OSX
|
||||
RCTPlatformDisplayLink *_displayLink;
|
||||
#else
|
||||
CADisplayLink *_displayLink;
|
||||
#endif
|
||||
std::function<void()> _onRender;
|
||||
}
|
||||
|
||||
- (void)_onDisplayLinkTick
|
||||
{
|
||||
if (_displayLink != nullptr && _onRender != nullptr) {
|
||||
_onRender();
|
||||
}
|
||||
}
|
||||
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:(const std::string &)name
|
||||
jsInvoker:(std::shared_ptr<facebook::react::CallInvoker>)jsInvoker
|
||||
{
|
||||
if (facebook::react::ReactNativeFeatureFlags::cxxNativeAnimatedEnabled()) {
|
||||
if (name == facebook::react::AnimatedModule::kModuleName) {
|
||||
auto provider = std::make_shared<facebook::react::NativeAnimatedNodesManagerProvider>(
|
||||
[self](std::function<void()> &&onRender) {
|
||||
_onRender = onRender;
|
||||
if (_displayLink == nil) {
|
||||
#if TARGET_OS_OSX
|
||||
_displayLink = [RCTPlatformDisplayLink displayLinkWithTarget:self selector:@selector(_onDisplayLinkTick)];
|
||||
#else
|
||||
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(_onDisplayLinkTick)];
|
||||
#endif
|
||||
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
|
||||
}
|
||||
},
|
||||
[self]() {
|
||||
if (_displayLink != nil) {
|
||||
[_displayLink invalidate];
|
||||
_displayLink = nil;
|
||||
_onRender = nullptr;
|
||||
}
|
||||
});
|
||||
return std::make_shared<facebook::react::AnimatedModule>(std::move(jsInvoker), std::move(provider));
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user