2016-06-09 17:34:41 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-06-09 17:34:41 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00: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 17:34:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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-03-28 12:30:00 +00:00
|
|
|
@implementation RCTPropsAnimatedNode
|
|
|
|
{
|
2017-01-27 02:14:40 +00:00
|
|
|
NSNumber *_connectedViewTag;
|
|
|
|
NSString *_connectedViewName;
|
2017-10-23 20:16:24 +00:00
|
|
|
__weak RCTUIManager *_uiManager;
|
2017-03-28 12:30:00 +00:00
|
|
|
NSMutableDictionary<NSString *, NSObject *> *_propsDictionary;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithTag:(NSNumber *)tag
|
|
|
|
config:(NSDictionary<NSString *, id> *)config;
|
|
|
|
{
|
|
|
|
if (self = [super initWithTag:tag config:config]) {
|
|
|
|
_propsDictionary = [NSMutableDictionary new];
|
|
|
|
}
|
|
|
|
return self;
|
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
|
2017-05-25 13:02:35 +00:00
|
|
|
{
|
|
|
|
_connectedViewTag = nil;
|
|
|
|
_connectedViewName = nil;
|
|
|
|
_uiManager = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)restoreDefaultValues
|
2016-06-09 17:34:41 +00:00
|
|
|
{
|
2017-03-28 12:30:00 +00:00
|
|
|
// 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) {
|
|
|
|
[_uiManager synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
|
|
|
viewName:_connectedViewName
|
|
|
|
props:_propsDictionary];
|
|
|
|
}
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
- (NSString *)propertyNameForParentTag:(NSNumber *)parentTag
|
|
|
|
{
|
|
|
|
__block NSString *propertyName;
|
2017-03-28 12:30:00 +00:00
|
|
|
[self.config[@"props"] enumerateKeysAndObjectsUsingBlock:^(NSString *_Nonnull property, NSNumber *_Nonnull tag, BOOL *_Nonnull stop) {
|
2016-11-28 19:09:46 +00:00
|
|
|
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];
|
|
|
|
|
2017-03-28 12:30:00 +00:00
|
|
|
// 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.
|
2017-01-27 02:14:40 +00:00
|
|
|
if (!_connectedViewTag) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-23 20:16:24 +00:00
|
|
|
|
|
|
|
for (NSNumber *parentTag in self.parentNodes.keyEnumerator) {
|
|
|
|
RCTAnimatedNode *parentNode = [self.parentNodes objectForKey:parentTag];
|
2016-11-28 19:09:46 +00:00
|
|
|
if ([parentNode isKindOfClass:[RCTStyleAnimatedNode class]]) {
|
2017-03-28 12:30:00 +00:00
|
|
|
[self->_propsDictionary addEntriesFromDictionary:[(RCTStyleAnimatedNode *)parentNode propsDictionary]];
|
2017-10-23 20:16:24 +00:00
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
} else if ([parentNode isKindOfClass:[RCTValueAnimatedNode class]]) {
|
|
|
|
NSString *property = [self propertyNameForParentTag:parentTag];
|
|
|
|
CGFloat value = [(RCTValueAnimatedNode *)parentNode value];
|
2017-03-28 12:30:00 +00:00
|
|
|
self->_propsDictionary[property] = @(value);
|
2016-11-28 19:09:46 +00:00
|
|
|
}
|
2017-10-23 20:16:24 +00:00
|
|
|
}
|
2016-11-28 19:09:46 +00:00
|
|
|
|
2017-03-28 12:30:00 +00:00
|
|
|
if (_propsDictionary.count) {
|
2017-01-27 02:14:40 +00:00
|
|
|
[_uiManager synchronouslyUpdateViewOnUIThread:_connectedViewTag
|
|
|
|
viewName:_connectedViewName
|
2017-03-28 12:30:00 +00:00
|
|
|
props:_propsDictionary];
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|