mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
544d9fb10b
Summary: Right now we rely on the Paper UIManager to update animated node graphs - this hooks us into `RCTSurfacePresenter` in the same way so we are no longer reliant on Paper. Should also help with complex ordering corner cases with pre vs. post operations and restoring defaults when nodes are removed. More info: https://github.com/facebook/react-native/pull/11819/files Note that we don't have a way to differentiate animation nodes related to fabric views vs. paper views, so if paper and fabric are both rendering updates simultaneously it's possible they could get processed by the wrong callback. That should be very rare, rarely cause problems even if it does happen, and won't be a problem at all in a post-Paper world. Reviewed By: shergin Differential Revision: D14336760 fbshipit-source-id: 1c6a72fa67d5fedbaefb21cd4d7e5d75484f4fae
124 lines
3.4 KiB
Objective-C
124 lines
3.4 KiB
Objective-C
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTPropsAnimatedNode.h"
|
|
|
|
#import <React/RCTLog.h>
|
|
#import <React/RCTSurfacePresenterStub.h>
|
|
#import <React/RCTUIManager.h>
|
|
|
|
#import "RCTAnimationUtils.h"
|
|
#import "RCTStyleAnimatedNode.h"
|
|
#import "RCTValueAnimatedNode.h"
|
|
|
|
|
|
|
|
@implementation RCTPropsAnimatedNode
|
|
{
|
|
NSNumber *_connectedViewTag;
|
|
NSNumber *_rootTag;
|
|
NSString *_connectedViewName;
|
|
__weak RCTBridge *_bridge;
|
|
NSMutableDictionary<NSString *, NSObject *> *_propsDictionary; // TODO: use RawProps or folly::dynamic directly
|
|
BOOL _managedByFabric;
|
|
}
|
|
|
|
- (instancetype)initWithTag:(NSNumber *)tag
|
|
config:(NSDictionary<NSString *, id> *)config;
|
|
{
|
|
if (self = [super initWithTag:tag config:config]) {
|
|
_propsDictionary = [NSMutableDictionary new];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)connectToView:(NSNumber *)viewTag
|
|
viewName:(NSString *)viewName
|
|
bridge:(RCTBridge *)bridge
|
|
{
|
|
_bridge = bridge;
|
|
_connectedViewTag = viewTag;
|
|
_connectedViewName = viewName;
|
|
_managedByFabric = RCTUIManagerTypeForTagIsFabric(viewTag);
|
|
_rootTag = nil;
|
|
}
|
|
|
|
- (void)disconnectFromView:(NSNumber *)viewTag
|
|
{
|
|
_bridge = nil;
|
|
_connectedViewTag = nil;
|
|
_connectedViewName = nil;
|
|
_managedByFabric = NO;
|
|
_rootTag = nil;
|
|
}
|
|
|
|
- (void)updateView
|
|
{
|
|
if (_managedByFabric) {
|
|
[_bridge.surfacePresenter synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
|
props:_propsDictionary];
|
|
} else {
|
|
[_bridge.uiManager synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
|
viewName:_connectedViewName
|
|
props:_propsDictionary];
|
|
}
|
|
}
|
|
|
|
- (void)restoreDefaultValues
|
|
{
|
|
// Restore the default value for all props that were modified by this node.
|
|
for (NSString *key in _propsDictionary.allKeys) {
|
|
_propsDictionary[key] = [NSNull null];
|
|
}
|
|
|
|
if (_propsDictionary.count) {
|
|
[self updateView];
|
|
}
|
|
}
|
|
|
|
- (NSString *)propertyNameForParentTag:(NSNumber *)parentTag
|
|
{
|
|
__block NSString *propertyName;
|
|
[self.config[@"props"] enumerateKeysAndObjectsUsingBlock:^(NSString *_Nonnull property, NSNumber *_Nonnull tag, BOOL *_Nonnull stop) {
|
|
if ([tag isEqualToNumber:parentTag]) {
|
|
propertyName = property;
|
|
*stop = YES;
|
|
}
|
|
}];
|
|
return propertyName;
|
|
}
|
|
|
|
- (void)performUpdate
|
|
{
|
|
[super performUpdate];
|
|
|
|
// Since we are updating nodes after detaching them from views there is a time where it's
|
|
// possible that the view was disconnected and still receive an update, this is normal and we can
|
|
// simply skip that update.
|
|
if (!_connectedViewTag) {
|
|
return;
|
|
}
|
|
|
|
for (NSNumber *parentTag in self.parentNodes.keyEnumerator) {
|
|
RCTAnimatedNode *parentNode = [self.parentNodes objectForKey:parentTag];
|
|
if ([parentNode isKindOfClass:[RCTStyleAnimatedNode class]]) {
|
|
[self->_propsDictionary addEntriesFromDictionary:[(RCTStyleAnimatedNode *)parentNode propsDictionary]];
|
|
|
|
} else if ([parentNode isKindOfClass:[RCTValueAnimatedNode class]]) {
|
|
NSString *property = [self propertyNameForParentTag:parentTag];
|
|
CGFloat value = [(RCTValueAnimatedNode *)parentNode value];
|
|
self->_propsDictionary[property] = @(value);
|
|
}
|
|
}
|
|
|
|
if (_propsDictionary.count) {
|
|
[self updateView];
|
|
}
|
|
}
|
|
|
|
@end
|