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 "RCTTransformAnimatedNode.h"
|
|
|
|
#import "RCTValueAnimatedNode.h"
|
|
|
|
|
|
|
|
@implementation RCTTransformAnimatedNode
|
|
|
|
{
|
2016-11-28 19:09:46 +00:00
|
|
|
NSMutableDictionary<NSString *, NSObject *> *_propsDictionary;
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (instancetype)initWithTag:(NSNumber *)tag
|
|
|
|
config:(NSDictionary<NSString *, id> *)config;
|
|
|
|
{
|
|
|
|
if ((self = [super initWithTag:tag config:config])) {
|
2016-11-28 19:09:46 +00:00
|
|
|
_propsDictionary = [NSMutableDictionary new];
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
- (NSDictionary *)propsDictionary
|
2016-06-09 17:34:41 +00:00
|
|
|
{
|
2016-11-28 19:09:46 +00:00
|
|
|
return _propsDictionary;
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)performUpdate
|
|
|
|
{
|
|
|
|
[super performUpdate];
|
|
|
|
|
2016-08-02 21:23:18 +00:00
|
|
|
CATransform3D transform = CATransform3DIdentity;
|
|
|
|
|
|
|
|
NSArray<NSDictionary *> *transformConfigs = self.config[@"transforms"];
|
|
|
|
for (NSDictionary *transformConfig in transformConfigs) {
|
2016-08-07 07:44:09 +00:00
|
|
|
NSString *type = transformConfig[@"type"];
|
2016-11-01 04:04:54 +00:00
|
|
|
NSString *property = transformConfig[@"property"];
|
|
|
|
|
|
|
|
CGFloat value;
|
|
|
|
if ([type isEqualToString: @"animated"]) {
|
|
|
|
NSNumber *nodeTag = transformConfig[@"nodeTag"];
|
|
|
|
RCTAnimatedNode *node = self.parentNodes[nodeTag];
|
2016-11-28 19:09:46 +00:00
|
|
|
if (![node isKindOfClass:[RCTValueAnimatedNode class]]) {
|
2016-11-01 04:04:54 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-06-09 17:34:41 +00:00
|
|
|
RCTValueAnimatedNode *parentNode = (RCTValueAnimatedNode *)node;
|
2016-11-01 04:04:54 +00:00
|
|
|
value = parentNode.value;
|
|
|
|
} else {
|
|
|
|
value = [transformConfig[@"value"] floatValue];
|
|
|
|
}
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
if ([property isEqualToString:@"scale"]) {
|
|
|
|
transform = CATransform3DScale(transform, value, value, 1);
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
} else if ([property isEqualToString:@"scaleX"]) {
|
|
|
|
transform = CATransform3DScale(transform, value, 1, 1);
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
} else if ([property isEqualToString:@"scaleY"]) {
|
|
|
|
transform = CATransform3DScale(transform, 1, value, 1);
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
} else if ([property isEqualToString:@"translateX"]) {
|
|
|
|
transform = CATransform3DTranslate(transform, value, 0, 0);
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
} else if ([property isEqualToString:@"translateY"]) {
|
|
|
|
transform = CATransform3DTranslate(transform, 0, value, 0);
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
} else if ([property isEqualToString:@"rotate"]) {
|
|
|
|
transform = CATransform3DRotate(transform, value, 0, 0, 1);
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
} else if ([property isEqualToString:@"rotateX"]) {
|
|
|
|
transform = CATransform3DRotate(transform, value, 1, 0, 0);
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
} else if ([property isEqualToString:@"rotateY"]) {
|
|
|
|
transform = CATransform3DRotate(transform, value, 0, 1, 0);
|
2016-08-02 21:23:18 +00:00
|
|
|
|
2016-11-01 04:04:54 +00:00
|
|
|
} else if ([property isEqualToString:@"perspective"]) {
|
|
|
|
transform.m34 = 1.0 / -value;
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
2016-08-02 21:23:18 +00:00
|
|
|
}
|
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
_propsDictionary[@"transform"] = [NSValue valueWithCATransform3D:transform];
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|