2016-06-09 17:34:41 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTPropsAnimatedNode.h"
|
2016-11-28 19:09:46 +00:00
|
|
|
|
2017-01-27 02:14:40 +00:00
|
|
|
#import <React/RCTLog.h>
|
|
|
|
#import <React/RCTUIManager.h>
|
|
|
|
|
2016-06-09 17:34:41 +00:00
|
|
|
#import "RCTAnimationUtils.h"
|
|
|
|
#import "RCTStyleAnimatedNode.h"
|
2016-11-28 19:09:46 +00:00
|
|
|
#import "RCTValueAnimatedNode.h"
|
2016-06-09 17:34:41 +00:00
|
|
|
|
2017-01-27 02:14:40 +00:00
|
|
|
@implementation RCTPropsAnimatedNode {
|
|
|
|
NSNumber *_connectedViewTag;
|
|
|
|
NSString *_connectedViewName;
|
|
|
|
RCTUIManager *_uiManager;
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 02:14:40 +00:00
|
|
|
- (void)connectToView:(NSNumber *)viewTag
|
|
|
|
viewName:(NSString *)viewName
|
|
|
|
uiManager:(RCTUIManager *)uiManager
|
2016-06-09 17:34:41 +00:00
|
|
|
{
|
2017-01-27 02:14:40 +00:00
|
|
|
_connectedViewTag = viewTag;
|
|
|
|
_connectedViewName = viewName;
|
|
|
|
_uiManager = uiManager;
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 02:14:40 +00:00
|
|
|
- (void)disconnectFromView:(NSNumber *)viewTag
|
2016-06-09 17:34:41 +00:00
|
|
|
{
|
2017-01-27 02:14:40 +00:00
|
|
|
_connectedViewTag = nil;
|
|
|
|
_connectedViewName = nil;
|
|
|
|
_uiManager = nil;
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
- (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;
|
|
|
|
}
|
|
|
|
|
2017-01-27 02:14:40 +00:00
|
|
|
- (void)performUpdate
|
2016-06-09 17:34:41 +00:00
|
|
|
{
|
2017-01-27 02:14:40 +00:00
|
|
|
[super performUpdate];
|
|
|
|
|
|
|
|
if (!_connectedViewTag) {
|
|
|
|
RCTLogError(@"Node has not been attached to a view");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
NSMutableDictionary *props = [NSMutableDictionary dictionary];
|
|
|
|
[self.parentNodes enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull parentTag, RCTAnimatedNode * _Nonnull parentNode, BOOL * _Nonnull stop) {
|
|
|
|
|
|
|
|
if ([parentNode isKindOfClass:[RCTStyleAnimatedNode class]]) {
|
|
|
|
[props addEntriesFromDictionary:[(RCTStyleAnimatedNode *)parentNode propsDictionary]];
|
|
|
|
|
|
|
|
} else if ([parentNode isKindOfClass:[RCTValueAnimatedNode class]]) {
|
|
|
|
NSString *property = [self propertyNameForParentTag:parentTag];
|
|
|
|
CGFloat value = [(RCTValueAnimatedNode *)parentNode value];
|
|
|
|
[props setObject:@(value) forKey:property];
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (props.count) {
|
2017-01-27 02:14:40 +00:00
|
|
|
[_uiManager synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
|
|
|
viewName:_connectedViewName
|
|
|
|
props:props];
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|