2019-10-16 20:03:47 +03:00
|
|
|
/*
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-06-09 20:34:41 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-06-09 20:34:41 +03:00
|
|
|
*/
|
2019-10-16 20:03:47 +03:00
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
CocoaPods frameworks compatibility: Step 2 (#25619)
Summary:
This is my proposal for fixing `use_frameworks!` compatibility without breaking all `<React/*>` imports I outlined in https://github.com/facebook/react-native/pull/25393#issuecomment-508457700. If accepted, it will fix https://github.com/facebook/react-native/issues/25349.
It builds on the changes I made in https://github.com/facebook/react-native/pull/25496 by ensuring each podspec has a unique value for `header_dir` so that framework imports do not conflict. Every podspec which should be included in the `<React/*>` namespace now includes it's headers from `React-Core.podspec`.
The following pods can still be imported with `<React/*>` and so should not have breaking changes: `React-ART`,`React-DevSupport`, `React-CoreModules`, `React-RCTActionSheet`, `React-RCTAnimation`, `React-RCTBlob`, `React-RCTImage`, `React-RCTLinking`, `React-RCTNetwork`, `React-RCTPushNotification`, `React-RCTSettings`, `React-RCTText`, `React-RCTSettings`, `React-RCTVibration`, `React-RCTWebSocket` .
There are still a few breaking changes which I hope will be acceptable:
- `React-Core.podspec` has been moved to the root of the project. Any `Podfile` that references it will need to update the path.
- ~~`React-turbomodule-core`'s headers now live under `<turbomodule/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-turbomodulesamples`'s headers now live under `<turbomodulesamples/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- ~~`React-TypeSaferty`'s headers now live under `<TypeSafety/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511040967.
- ~~`React-jscallinvoker`'s headers now live under `<jscallinvoker/*>`~~ Replaced by https://github.com/facebook/react-native/pull/25619#issuecomment-511091823.
- Each podspec now uses `s.static_framework = true`. This means that a minimum of CocoaPods 1.5 ([released in April 2018](http://blog.cocoapods.org/CocoaPods-1.5.0/)) is now required. This is needed so that the ` __has_include` conditions can still work when frameworks are enabled.
Still to do:
- ~~Including `React-turbomodule-core` with `use_frameworks!` enabled causes the C++ import failures we saw in https://github.com/facebook/react-native/issues/25349. I'm sure it will be possible to fix this but I need to dig deeper (perhaps a custom modulemap would be needed).~~ Addressed by https://github.com/facebook/react-native/pull/25619/commits/33573511f02f3502a28bad48e085e9a4b8608302.
- I haven't got Fabric working yet. I wonder if it would be acceptable to move Fabric out of the `<React/*>` namespace since it is new? �
## Changelog
[iOS] [Fixed] - Fixed compatibility with CocoaPods frameworks.
Pull Request resolved: https://github.com/facebook/react-native/pull/25619
Test Plan:
### FB
```
buck build catalyst
```
### Sample Project
Everything should work exactly as before, where `use_frameworks!` is not in `Podfile`s. I have a branch on my [sample project](https://github.com/jtreanor/react-native-cocoapods-frameworks) here which has `use_frameworks!` in its `Podfile` to demonstrate this is fixed.
You can see that it works with these steps:
1. `git clone git@github.com:jtreanor/react-native-cocoapods-frameworks.git`
2. `git checkout fix-frameworks-subspecs`
3. `cd ios && pod install`
4. `cd .. && react-native run-ios`
The sample app will build and run successfully. To see that it still works without frameworks, remove `use_frameworks!` from the `Podfile` and do steps 3 and 4 again.
### RNTesterPods
`RNTesterPodsPods` can now work with or without `use_frameworks!`.
1. Go to the `RNTester` directory and run `pod install`.
2. Run the tests in `RNTesterPods.xcworkspace` to see that everything still works fine.
3. Uncomment the `use_frameworks!` line at the top of `RNTester/Podfile` and run `pod install` again.
4. Run the tests again and see that it still works with frameworks enabled.
Reviewed By: PeteTheHeat
Differential Revision: D16465247
Pulled By: PeteTheHeat
fbshipit-source-id: cad837e9cced06d30cc5b372af1c65c7780b9e7a
2019-07-25 08:26:42 +03:00
|
|
|
#import <React/RCTNativeAnimatedModule.h>
|
|
|
|
#import <React/RCTNativeAnimatedNodesManager.h>
|
2020-08-25 02:34:58 +03:00
|
|
|
#import <React/RCTLog.h>
|
2016-11-28 22:09:46 +03:00
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
#import <RCTTypeSafety/RCTConvertHelpers.h>
|
|
|
|
|
|
|
|
#import "RCTAnimationPlugins.h"
|
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
typedef void (^AnimatedOperation)(RCTNativeAnimatedNodesManager *nodesManager);
|
2016-06-09 20:34:41 +03:00
|
|
|
|
|
|
|
@implementation RCTNativeAnimatedModule
|
|
|
|
{
|
2016-11-28 22:09:46 +03:00
|
|
|
RCTNativeAnimatedNodesManager *_nodesManager;
|
2017-03-28 15:30:00 +03:00
|
|
|
|
2019-07-23 13:19:41 +03:00
|
|
|
// Operations called after views have been updated.
|
2016-11-28 22:09:46 +03:00
|
|
|
NSMutableArray<AnimatedOperation> *_operations;
|
2017-03-28 15:30:00 +03:00
|
|
|
// Operations called before views have been updated.
|
|
|
|
NSMutableArray<AnimatedOperation> *_preOperations;
|
2019-03-08 04:34:41 +03:00
|
|
|
NSMutableDictionary<NSNumber *, NSNumber *> *_animIdIsManagedByFabric;
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
RCT_EXPORT_MODULE();
|
2016-11-01 13:56:50 +03:00
|
|
|
|
2020-08-25 02:34:58 +03:00
|
|
|
+ (BOOL)requiresMainQueueSetup
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
|
|
|
_operations = [NSMutableArray new];
|
|
|
|
_preOperations = [NSMutableArray new];
|
|
|
|
_animIdIsManagedByFabric = [NSMutableDictionary new];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-01-06 08:48:10 +03:00
|
|
|
- (void)invalidate
|
|
|
|
{
|
2020-09-22 03:28:47 +03:00
|
|
|
[super invalidate];
|
2017-01-06 08:48:10 +03:00
|
|
|
[_nodesManager stopAnimationLoop];
|
2020-12-11 21:39:18 +03:00
|
|
|
[[self.moduleRegistry moduleForName:"EventDispatcher"] removeDispatchObserver:self];
|
2017-05-08 22:40:07 +03:00
|
|
|
[self.bridge.uiManager.observerCoordinator removeObserver:self];
|
2019-03-08 04:34:41 +03:00
|
|
|
[self.bridge.surfacePresenter removeObserver:self];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2016-08-07 22:44:28 +03:00
|
|
|
- (dispatch_queue_t)methodQueue
|
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
// This module needs to be on the same queue as the UIManager to avoid
|
2017-12-12 03:54:52 +03:00
|
|
|
// having to lock `_operations` and `_preOperations` since `uiManagerWillPerformMounting`
|
2017-03-28 15:30:00 +03:00
|
|
|
// will be called from that queue.
|
2016-11-28 22:09:46 +03:00
|
|
|
return RCTGetUIManagerQueue();
|
2016-08-07 22:44:28 +03:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
- (void)setBridge:(RCTBridge *)bridge
|
2016-08-12 04:10:16 +03:00
|
|
|
{
|
2016-11-28 22:09:46 +03:00
|
|
|
[super setBridge:bridge];
|
2020-08-25 02:34:58 +03:00
|
|
|
_nodesManager = [[RCTNativeAnimatedNodesManager alloc] initWithBridge:self.bridge surfacePresenter:bridge.surfacePresenter];
|
2019-03-08 04:34:41 +03:00
|
|
|
[bridge.uiManager.observerCoordinator addObserver:self];
|
|
|
|
[bridge.surfacePresenter addObserver:self];
|
2016-08-12 04:10:16 +03:00
|
|
|
}
|
|
|
|
|
2020-12-11 21:39:18 +03:00
|
|
|
- (void)setModuleRegistry:(RCTModuleRegistry *)moduleRegistry
|
|
|
|
{
|
|
|
|
[super setModuleRegistry:moduleRegistry];
|
|
|
|
[[moduleRegistry moduleForName:"EventDispatcher"] addDispatchObserver:self];
|
|
|
|
}
|
|
|
|
|
2020-08-25 02:34:58 +03:00
|
|
|
/*
|
|
|
|
* This selector should only be invoked in bridgeless mode, which is not compatible with this non turbo module.
|
|
|
|
*/
|
|
|
|
- (void)setSurfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter
|
|
|
|
{
|
|
|
|
RCTLogWarn(@"setSurfacePresenter should only be invoked in RCTNativeAnimatedTurboModule");
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
#pragma mark -- API
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(createAnimatedNode:(double)tag
|
2016-06-09 20:34:41 +03:00
|
|
|
config:(NSDictionary<NSString *, id> *)config)
|
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager createAnimatedNode:[NSNumber numberWithDouble:tag] config:config];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(connectAnimatedNodes:(double)parentTag
|
|
|
|
childTag:(double)childTag)
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager connectAnimatedNodes:[NSNumber numberWithDouble:parentTag] childTag:[NSNumber numberWithDouble:childTag]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(disconnectAnimatedNodes:(double)parentTag
|
|
|
|
childTag:(double)childTag)
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager disconnectAnimatedNodes:[NSNumber numberWithDouble:parentTag] childTag:[NSNumber numberWithDouble:childTag]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(startAnimatingNode:(double)animationId
|
|
|
|
nodeTag:(double)nodeTag
|
2016-06-09 20:34:41 +03:00
|
|
|
config:(NSDictionary<NSString *, id> *)config
|
|
|
|
endCallback:(RCTResponseSenderBlock)callBack)
|
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager startAnimatingNode:[NSNumber numberWithDouble:animationId] nodeTag:[NSNumber numberWithDouble:nodeTag] config:config endCallback:callBack];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2019-09-23 19:28:33 +03:00
|
|
|
|
2020-06-20 04:22:03 +03:00
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
if (![self->_nodesManager isNodeManagedByFabric:[NSNumber numberWithDouble:nodeTag]]) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-23 19:28:33 +03:00
|
|
|
|
2020-06-20 04:22:03 +03:00
|
|
|
RCTExecuteOnUIManagerQueue(^{
|
|
|
|
self->_animIdIsManagedByFabric[[NSNumber numberWithDouble:animationId]] = @YES;
|
|
|
|
[self flushOperationQueues];
|
|
|
|
});
|
|
|
|
});
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(stopAnimation:(double)animationId)
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager stopAnimation:[NSNumber numberWithDouble:animationId]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2019-10-17 04:43:00 +03:00
|
|
|
if ([_animIdIsManagedByFabric[[NSNumber numberWithDouble:animationId]] boolValue]) {
|
2019-03-08 04:34:41 +03:00
|
|
|
[self flushOperationQueues];
|
|
|
|
}
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(setAnimatedNodeValue:(double)nodeTag
|
|
|
|
value:(double)value)
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager setAnimatedNodeValue:[NSNumber numberWithDouble:nodeTag] value:[NSNumber numberWithDouble:value]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(setAnimatedNodeOffset:(double)nodeTag
|
|
|
|
offset:(double)offset)
|
2016-09-26 20:17:29 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager setAnimatedNodeOffset:[NSNumber numberWithDouble:nodeTag] offset:[NSNumber numberWithDouble:offset]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-09-26 20:17:29 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(flattenAnimatedNodeOffset:(double)nodeTag)
|
2016-09-26 20:17:29 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager flattenAnimatedNodeOffset:[NSNumber numberWithDouble:nodeTag]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-09-26 20:17:29 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(extractAnimatedNodeOffset:(double)nodeTag)
|
2016-11-08 07:36:52 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager extractAnimatedNodeOffset:[NSNumber numberWithDouble:nodeTag]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-11-08 07:36:52 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(connectAnimatedNodeToView:(double)nodeTag
|
|
|
|
viewTag:(double)viewTag)
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2019-10-17 04:43:00 +03:00
|
|
|
NSString *viewName = [self.bridge.uiManager viewNameForReactTag:[NSNumber numberWithDouble:viewTag]];
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager connectAnimatedNodeToView:[NSNumber numberWithDouble:nodeTag] viewTag:[NSNumber numberWithDouble:viewTag] viewName:viewName];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(disconnectAnimatedNodeFromView:(double)nodeTag
|
|
|
|
viewTag:(double)viewTag)
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2017-05-25 16:02:35 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager disconnectAnimatedNodeFromView:[NSNumber numberWithDouble:nodeTag] viewTag:[NSNumber numberWithDouble:viewTag]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-11-05 02:37:45 +03:00
|
|
|
RCT_EXPORT_METHOD(restoreDefaultValues:(double)nodeTag)
|
|
|
|
{
|
|
|
|
[self addPreOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
|
|
|
[nodesManager restoreDefaultValues:[NSNumber numberWithDouble:nodeTag]];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(dropAnimatedNode:(double)tag)
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager dropAnimatedNode:[NSNumber numberWithDouble:tag]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(startListeningToAnimatedNodeValue:(double)tag)
|
2016-08-12 04:10:16 +03:00
|
|
|
{
|
2016-11-28 22:09:46 +03:00
|
|
|
__weak id<RCTValueAnimatedNodeObserver> valueObserver = self;
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager startListeningToAnimatedNodeValue:[NSNumber numberWithDouble:tag] valueObserver:valueObserver];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-08-12 04:10:16 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(stopListeningToAnimatedNodeValue:(double)tag)
|
2016-08-12 04:10:16 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager stopListeningToAnimatedNodeValue:[NSNumber numberWithDouble:tag]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-08-12 04:10:16 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(addAnimatedEventToView:(double)viewTag
|
2016-11-01 13:56:50 +03:00
|
|
|
eventName:(nonnull NSString *)eventName
|
2019-10-17 04:43:00 +03:00
|
|
|
eventMapping:(JS::NativeAnimatedModule::EventMapping &)eventMapping)
|
2016-11-01 13:56:50 +03:00
|
|
|
{
|
2019-10-17 04:43:00 +03:00
|
|
|
NSMutableDictionary *eventMappingDict = [NSMutableDictionary new];
|
|
|
|
eventMappingDict[@"nativeEventPath"] = RCTConvertVecToArray(eventMapping.nativeEventPath());
|
|
|
|
|
|
|
|
if (eventMapping.animatedValueTag()) {
|
|
|
|
eventMappingDict[@"animatedValueTag"] = @(*eventMapping.animatedValueTag());
|
|
|
|
}
|
|
|
|
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager addAnimatedEventToView:[NSNumber numberWithDouble:viewTag] eventName:eventName eventMapping:eventMappingDict];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-11-01 13:56:50 +03:00
|
|
|
}
|
|
|
|
|
2019-10-17 04:43:00 +03:00
|
|
|
RCT_EXPORT_METHOD(removeAnimatedEventFromView:(double)viewTag
|
2017-03-10 02:16:01 +03:00
|
|
|
eventName:(nonnull NSString *)eventName
|
2019-10-17 04:43:00 +03:00
|
|
|
animatedNodeTag:(double)animatedNodeTag)
|
2016-11-01 13:56:50 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2019-10-17 04:43:00 +03:00
|
|
|
[nodesManager removeAnimatedEventFromView:[NSNumber numberWithDouble:viewTag] eventName:eventName animatedNodeTag:[NSNumber numberWithDouble:animatedNodeTag]];
|
2016-11-28 22:09:46 +03:00
|
|
|
}];
|
2016-11-01 13:56:50 +03:00
|
|
|
}
|
|
|
|
|
2020-07-28 01:06:57 +03:00
|
|
|
RCT_EXPORT_METHOD(getValue:(double)nodeTag saveValueCallback:(RCTResponseSenderBlock)saveValueCallback) {
|
2020-06-30 03:06:34 +03:00
|
|
|
[self addOperationBlock:^(RCTNativeAnimatedNodesManager *nodesManager) {
|
2020-07-28 01:06:57 +03:00
|
|
|
[nodesManager getValue:[NSNumber numberWithDouble:nodeTag] saveCallback:saveValueCallback];
|
2020-06-30 03:06:34 +03:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
#pragma mark -- Batch handling
|
2016-08-12 04:10:16 +03:00
|
|
|
|
2017-03-28 15:30:00 +03:00
|
|
|
- (void)addOperationBlock:(AnimatedOperation)operation
|
2016-11-01 13:56:50 +03:00
|
|
|
{
|
2017-03-28 15:30:00 +03:00
|
|
|
[_operations addObject:operation];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addPreOperationBlock:(AnimatedOperation)operation
|
|
|
|
{
|
|
|
|
[_preOperations addObject:operation];
|
|
|
|
}
|
|
|
|
|
2019-03-08 04:34:41 +03:00
|
|
|
- (void)flushOperationQueues
|
|
|
|
{
|
|
|
|
if (_preOperations.count == 0 && _operations.count == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NSArray<AnimatedOperation> *preOperations = _preOperations;
|
|
|
|
NSArray<AnimatedOperation> *operations = _operations;
|
|
|
|
_preOperations = [NSMutableArray new];
|
|
|
|
_operations = [NSMutableArray new];
|
|
|
|
|
|
|
|
|
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
for (AnimatedOperation operation in preOperations) {
|
|
|
|
operation(self->_nodesManager);
|
|
|
|
}
|
|
|
|
for (AnimatedOperation operation in operations) {
|
|
|
|
operation(self->_nodesManager);
|
|
|
|
}
|
|
|
|
[self->_nodesManager updateAnimations];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-08 17:13:22 +03:00
|
|
|
#pragma mark - RCTSurfacePresenterObserver
|
2019-03-08 04:34:41 +03:00
|
|
|
|
|
|
|
- (void)willMountComponentsWithRootTag:(NSInteger)rootTag
|
|
|
|
{
|
|
|
|
RCTAssertMainQueue();
|
2019-06-02 06:04:27 +03:00
|
|
|
RCTExecuteOnUIManagerQueue(^{
|
|
|
|
NSArray<AnimatedOperation> *preOperations = self->_preOperations;
|
2019-03-21 20:59:31 +03:00
|
|
|
self->_preOperations = [NSMutableArray new];
|
2019-06-02 06:04:27 +03:00
|
|
|
|
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
for (AnimatedOperation preOperation in preOperations) {
|
|
|
|
preOperation(self->_nodesManager);
|
|
|
|
}
|
|
|
|
});
|
2019-03-21 20:59:31 +03:00
|
|
|
});
|
2019-03-08 04:34:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didMountComponentsWithRootTag:(NSInteger)rootTag
|
|
|
|
{
|
|
|
|
RCTAssertMainQueue();
|
2019-06-02 06:04:27 +03:00
|
|
|
RCTExecuteOnUIManagerQueue(^{
|
|
|
|
NSArray<AnimatedOperation> *operations = self->_operations;
|
2019-03-21 20:59:31 +03:00
|
|
|
self->_operations = [NSMutableArray new];
|
2019-06-02 06:04:27 +03:00
|
|
|
|
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
for (AnimatedOperation operation in operations) {
|
|
|
|
operation(self->_nodesManager);
|
|
|
|
}
|
|
|
|
});
|
2019-03-21 20:59:31 +03:00
|
|
|
});
|
2019-03-08 04:34:41 +03:00
|
|
|
}
|
|
|
|
|
2017-05-08 22:40:07 +03:00
|
|
|
#pragma mark - RCTUIManagerObserver
|
|
|
|
|
2019-03-08 04:34:41 +03:00
|
|
|
- (void)uiManagerWillPerformMounting:(RCTUIManager *)uiManager
|
2017-03-28 15:30:00 +03:00
|
|
|
{
|
|
|
|
if (_preOperations.count == 0 && _operations.count == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray<AnimatedOperation> *preOperations = _preOperations;
|
|
|
|
NSArray<AnimatedOperation> *operations = _operations;
|
|
|
|
_preOperations = [NSMutableArray new];
|
2016-11-28 22:09:46 +03:00
|
|
|
_operations = [NSMutableArray new];
|
2016-11-01 13:56:50 +03:00
|
|
|
|
2017-03-28 15:30:00 +03:00
|
|
|
[uiManager prependUIBlock:^(__unused RCTUIManager *manager, __unused NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
|
|
for (AnimatedOperation operation in preOperations) {
|
2016-11-28 22:09:46 +03:00
|
|
|
operation(self->_nodesManager);
|
2017-03-28 15:30:00 +03:00
|
|
|
}
|
|
|
|
}];
|
|
|
|
[uiManager addUIBlock:^(__unused RCTUIManager *manager, __unused NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
|
|
|
for (AnimatedOperation operation in operations) {
|
|
|
|
operation(self->_nodesManager);
|
|
|
|
}
|
2017-03-28 20:50:00 +03:00
|
|
|
|
|
|
|
[self->_nodesManager updateAnimations];
|
2017-03-28 15:30:00 +03:00
|
|
|
}];
|
2016-11-01 00:21:58 +03:00
|
|
|
}
|
2016-08-12 04:10:16 +03:00
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
#pragma mark -- Events
|
2016-06-09 20:34:41 +03:00
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
- (NSArray<NSString *> *)supportedEvents
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2016-11-28 22:09:46 +03:00
|
|
|
return @[@"onAnimatedValueUpdate"];
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
- (void)animatedNode:(RCTValueAnimatedNode *)node didUpdateValue:(CGFloat)value
|
2016-11-01 13:56:50 +03:00
|
|
|
{
|
2016-11-28 22:09:46 +03:00
|
|
|
[self sendEventWithName:@"onAnimatedValueUpdate"
|
|
|
|
body:@{@"tag": node.nodeTag, @"value": @(value)}];
|
2016-11-01 13:56:50 +03:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:09:46 +03:00
|
|
|
- (void)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event
|
2016-06-09 20:34:41 +03:00
|
|
|
{
|
2017-09-26 09:07:01 +03:00
|
|
|
// Events can be dispatched from any queue so we have to make sure handleAnimatedEvent
|
|
|
|
// is run from the main queue.
|
|
|
|
RCTExecuteOnMainQueue(^{
|
|
|
|
[self->_nodesManager handleAnimatedEvent:event];
|
|
|
|
});
|
2016-06-09 20:34:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2019-10-17 04:43:00 +03:00
|
|
|
|
|
|
|
Class RCTNativeAnimatedModuleCls(void) {
|
|
|
|
return RCTNativeAnimatedModule.class;
|
|
|
|
}
|