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 "RCTViewPropertyMapper.h"
|
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2016-11-23 15:47:52 +00:00
|
|
|
#import <React/RCTBridge.h>
|
|
|
|
#import <React/RCTConvert.h>
|
|
|
|
#import <React/RCTUIManager.h>
|
|
|
|
|
2016-06-09 17:34:41 +00:00
|
|
|
#import "RCTNativeAnimatedModule.h"
|
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
@interface RCTViewPropertyMapper ()
|
|
|
|
|
|
|
|
@property (nonatomic, weak) UIView *cachedView;
|
|
|
|
@property (nonatomic, weak) RCTUIManager *uiManager;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2016-06-09 17:34:41 +00:00
|
|
|
@implementation RCTViewPropertyMapper
|
|
|
|
|
|
|
|
- (instancetype)initWithViewTag:(NSNumber *)viewTag
|
2016-11-28 19:09:46 +00:00
|
|
|
uiManager:(RCTUIManager *)uiManager
|
2016-06-09 17:34:41 +00:00
|
|
|
{
|
|
|
|
if ((self = [super init])) {
|
2016-11-28 19:09:46 +00:00
|
|
|
_uiManager = uiManager;
|
2016-06-09 17:34:41 +00:00
|
|
|
_viewTag = viewTag;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
- (void)updateViewWithDictionary:(NSDictionary<NSString *, NSObject *> *)properties
|
2016-06-09 17:34:41 +00:00
|
|
|
{
|
2016-11-28 19:09:46 +00:00
|
|
|
// cache the view for perf reasons (avoid constant lookups)
|
|
|
|
UIView *view = _cachedView = _cachedView ?: [self.uiManager viewForReactTag:_viewTag];
|
|
|
|
if (!view) {
|
|
|
|
RCTLogError(@"No view to update.");
|
2016-08-02 21:23:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-09 17:34:41 +00:00
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
if (!properties.count) {
|
2016-08-02 21:23:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-06-09 17:34:41 +00:00
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
NSNumber *opacity = [RCTConvert NSNumber:properties[@"opacity"]];
|
2016-08-02 21:23:18 +00:00
|
|
|
if (opacity) {
|
|
|
|
view.alpha = opacity.floatValue;
|
|
|
|
}
|
2016-06-09 17:34:41 +00:00
|
|
|
|
2016-11-28 19:09:46 +00:00
|
|
|
NSObject *transform = properties[@"transform"];
|
2016-08-02 21:23:18 +00:00
|
|
|
if ([transform isKindOfClass:[NSValue class]]) {
|
|
|
|
view.layer.allowsEdgeAntialiasing = YES;
|
|
|
|
view.layer.transform = ((NSValue *)transform).CATransform3DValue;
|
2016-06-09 17:34:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|