diff --git a/Libraries/NativeAnimation/Nodes/RCTColorAnimatedNode.h b/Libraries/NativeAnimation/Nodes/RCTColorAnimatedNode.h new file mode 100644 index 00000000000000..ae1d132573445a --- /dev/null +++ b/Libraries/NativeAnimation/Nodes/RCTColorAnimatedNode.h @@ -0,0 +1,14 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +@interface RCTColorAnimatedNode : RCTAnimatedNode + +@property (nonatomic, assign) int32_t color; + +@end diff --git a/Libraries/NativeAnimation/Nodes/RCTColorAnimatedNode.m b/Libraries/NativeAnimation/Nodes/RCTColorAnimatedNode.m new file mode 100644 index 00000000000000..6c8d2a881116ba --- /dev/null +++ b/Libraries/NativeAnimation/Nodes/RCTColorAnimatedNode.m @@ -0,0 +1,30 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import +#import + +@implementation RCTColorAnimatedNode + +- (void)performUpdate +{ + [super performUpdate]; + + RCTValueAnimatedNode *rNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:self.config[@"r"]]; + RCTValueAnimatedNode *gNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:self.config[@"g"]]; + RCTValueAnimatedNode *bNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:self.config[@"b"]]; + RCTValueAnimatedNode *aNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:self.config[@"a"]]; + + _color = ((int)round(aNode.value * 255) & 0xff) << 24 | + ((int)round(rNode.value) & 0xff) << 16 | + ((int)round(gNode.value) & 0xff) << 8 | + ((int)round(bNode.value) & 0xff); + + // TODO (T111179606): Support platform colors for color animations +} + +@end diff --git a/Libraries/NativeAnimation/Nodes/RCTPropsAnimatedNode.m b/Libraries/NativeAnimation/Nodes/RCTPropsAnimatedNode.m index aac71b01efaf23..43e96a2eb2b6f5 100644 --- a/Libraries/NativeAnimation/Nodes/RCTPropsAnimatedNode.m +++ b/Libraries/NativeAnimation/Nodes/RCTPropsAnimatedNode.m @@ -12,6 +12,7 @@ #import #import #import +#import @implementation RCTPropsAnimatedNode { @@ -118,17 +119,21 @@ - (void)performUpdate for (NSNumber *parentTag in self.parentNodes.keyEnumerator) { RCTAnimatedNode *parentNode = [self.parentNodes objectForKey:parentTag]; if ([parentNode isKindOfClass:[RCTStyleAnimatedNode class]]) { - [self->_propsDictionary addEntriesFromDictionary:[(RCTStyleAnimatedNode *)parentNode propsDictionary]]; - + RCTStyleAnimatedNode *styleAnimatedNode = (RCTStyleAnimatedNode *)parentNode; + [_propsDictionary addEntriesFromDictionary:styleAnimatedNode.propsDictionary]; } else if ([parentNode isKindOfClass:[RCTValueAnimatedNode class]]) { + RCTValueAnimatedNode *valueAnimatedNode = (RCTValueAnimatedNode *)parentNode; NSString *property = [self propertyNameForParentTag:parentTag]; - id animatedObject = [(RCTValueAnimatedNode *)parentNode animatedObject]; + id animatedObject = valueAnimatedNode.animatedObject; if (animatedObject) { - self->_propsDictionary[property] = animatedObject; + _propsDictionary[property] = animatedObject; } else { - CGFloat value = [(RCTValueAnimatedNode *)parentNode value]; - self->_propsDictionary[property] = @(value); + _propsDictionary[property] = @(valueAnimatedNode.value); } + } else if ([parentNode isKindOfClass:[RCTColorAnimatedNode class]]) { + RCTColorAnimatedNode *colorAnimatedNode = (RCTColorAnimatedNode *)parentNode; + NSString *property = [self propertyNameForParentTag:parentTag]; + _propsDictionary[property] = @(colorAnimatedNode.color); } } diff --git a/Libraries/NativeAnimation/Nodes/RCTStyleAnimatedNode.m b/Libraries/NativeAnimation/Nodes/RCTStyleAnimatedNode.m index c6710d0582ea43..8dc81c9efbd3b1 100644 --- a/Libraries/NativeAnimation/Nodes/RCTStyleAnimatedNode.m +++ b/Libraries/NativeAnimation/Nodes/RCTStyleAnimatedNode.m @@ -9,6 +9,7 @@ #import #import #import +#import @implementation RCTStyleAnimatedNode { @@ -38,11 +39,14 @@ - (void)performUpdate RCTAnimatedNode *node = [self.parentNodes objectForKey:nodeTag]; if (node) { if ([node isKindOfClass:[RCTValueAnimatedNode class]]) { - RCTValueAnimatedNode *parentNode = (RCTValueAnimatedNode *)node; - [self->_propsDictionary setObject:@(parentNode.value) forKey:property]; + RCTValueAnimatedNode *valueAnimatedNode = (RCTValueAnimatedNode *)node; + _propsDictionary[property] = @(valueAnimatedNode.value); } else if ([node isKindOfClass:[RCTTransformAnimatedNode class]]) { - RCTTransformAnimatedNode *parentNode = (RCTTransformAnimatedNode *)node; - [self->_propsDictionary addEntriesFromDictionary:parentNode.propsDictionary]; + RCTTransformAnimatedNode *transformAnimatedNode = (RCTTransformAnimatedNode *)node; + [_propsDictionary addEntriesFromDictionary:transformAnimatedNode.propsDictionary]; + } else if ([node isKindOfClass:[RCTColorAnimatedNode class]]) { + RCTColorAnimatedNode *colorAnimatedNode = (RCTColorAnimatedNode *)node; + _propsDictionary[property] = @(colorAnimatedNode.color); } } }]; diff --git a/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m b/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m index 74db1636fd6647..9a7eebb4155b8c 100644 --- a/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m +++ b/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m @@ -12,6 +12,7 @@ #import #import #import +#import #import #import #import @@ -86,6 +87,7 @@ - (void)createAnimatedNode:(NSNumber *)tag dispatch_once(&mapToken, ^{ map = @{@"style" : [RCTStyleAnimatedNode class], @"value" : [RCTValueAnimatedNode class], + @"color" : [RCTColorAnimatedNode class], @"props" : [RCTPropsAnimatedNode class], @"interpolation" : [RCTInterpolationAnimatedNode class], @"addition" : [RCTAdditionAnimatedNode class], diff --git a/Libraries/NativeAnimation/React-RCTAnimation.podspec b/Libraries/NativeAnimation/React-RCTAnimation.podspec index 0535d984a27a0a..31fb9f925f36e5 100644 --- a/Libraries/NativeAnimation/React-RCTAnimation.podspec +++ b/Libraries/NativeAnimation/React-RCTAnimation.podspec @@ -29,7 +29,7 @@ Pod::Spec.new do |s| s.platforms = { :ios => "11.0", :osx => "10.15" } # TODO(macOS GH#214) s.compiler_flags = folly_compiler_flags + ' -Wno-nullability-completeness' s.source = source - s.source_files = "{Drivers/*,Nodes/*,*}.{m,mm}" + s.source_files = "**/*.{h,m,mm}" s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs" s.header_dir = "RCTAnimation" s.pod_target_xcconfig = { diff --git a/React/Fabric/Mounting/RCTMountingManager.mm b/React/Fabric/Mounting/RCTMountingManager.mm index ae7ce093cc18cb..66ff0d50fdf2c9 100644 --- a/React/Fabric/Mounting/RCTMountingManager.mm +++ b/React/Fabric/Mounting/RCTMountingManager.mm @@ -15,6 +15,7 @@ #import #import #import +#import #import #import #import @@ -318,6 +319,11 @@ - (void)synchronouslyUpdateViewOnUIThread:(ReactTag)reactTag if (props[@"opacity"] && componentView.layer.opacity != (float)newViewProps.opacity) { componentView.layer.opacity = newViewProps.opacity; } + + auto reactNativeConfig = _contextContainer->at>("ReactNativeConfig"); + if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:finalize_updates_on_synchronous_update_view_ios")) { + [componentView finalizeUpdates:RNComponentViewUpdateMaskProps]; + } } - (void)synchronouslyDispatchCommandOnUIThread:(ReactTag)reactTag diff --git a/ReactCommon/react/renderer/graphics/platform/ios/Color.h b/ReactCommon/react/renderer/graphics/platform/ios/Color.h index 549403a699d4a8..0a50fa455ad54f 100644 --- a/ReactCommon/react/renderer/graphics/platform/ios/Color.h +++ b/ReactCommon/react/renderer/graphics/platform/ios/Color.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include