Skip to content

Commit 49f3f47

Browse files
genkikondofacebook-github-bot
authored andcommitted
Support color animation with native driver for iOS
Summary: Adds support for Animated.Color with native driver for iOS. Reads the native config for the rbga channel AnimatedNodes, and on update(), converts the values into a SharedColor. Followup changes will include support for platform colors. Ran update_pods: https://www.internalfb.com/intern/wiki/React_Native/Preparing_to_Ship/Open_Source_Pods/ Changelog: [iOS][Added] - Support running animations with AnimatedColor with native driver Reviewed By: sammy-SC Differential Revision: D33860583 fbshipit-source-id: 990ad0f754a21e3939f2cb233bcfa793ef12eb14
1 parent 6b61995 commit 49f3f47

File tree

9 files changed

+76
-16
lines changed

9 files changed

+76
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTAnimatedNode.h>
9+
10+
@interface RCTColorAnimatedNode : RCTAnimatedNode
11+
12+
@property (nonatomic, assign) int32_t color;
13+
14+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTColorAnimatedNode.h>
9+
#import <React/RCTValueAnimatedNode.h>
10+
11+
@implementation RCTColorAnimatedNode
12+
13+
- (void)performUpdate
14+
{
15+
[super performUpdate];
16+
17+
RCTValueAnimatedNode *rNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:self.config[@"r"]];
18+
RCTValueAnimatedNode *gNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:self.config[@"g"]];
19+
RCTValueAnimatedNode *bNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:self.config[@"b"]];
20+
RCTValueAnimatedNode *aNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:self.config[@"a"]];
21+
22+
_color = ((int)round(aNode.value * 255) & 0xff) << 24 |
23+
((int)round(rNode.value) & 0xff) << 16 |
24+
((int)round(gNode.value) & 0xff) << 8 |
25+
((int)round(bNode.value) & 0xff);
26+
27+
// TODO (T111179606): Support platform colors for color animations
28+
}
29+
30+
@end

Libraries/NativeAnimation/Nodes/RCTPropsAnimatedNode.m

+11-6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <React/RCTStyleAnimatedNode.h>
1313
#import <React/RCTUIManager.h>
1414
#import <React/RCTValueAnimatedNode.h>
15+
#import <React/RCTColorAnimatedNode.h>
1516

1617
@implementation RCTPropsAnimatedNode
1718
{
@@ -118,17 +119,21 @@ - (void)performUpdate
118119
for (NSNumber *parentTag in self.parentNodes.keyEnumerator) {
119120
RCTAnimatedNode *parentNode = [self.parentNodes objectForKey:parentTag];
120121
if ([parentNode isKindOfClass:[RCTStyleAnimatedNode class]]) {
121-
[self->_propsDictionary addEntriesFromDictionary:[(RCTStyleAnimatedNode *)parentNode propsDictionary]];
122-
122+
RCTStyleAnimatedNode *styleAnimatedNode = (RCTStyleAnimatedNode *)parentNode;
123+
[_propsDictionary addEntriesFromDictionary:styleAnimatedNode.propsDictionary];
123124
} else if ([parentNode isKindOfClass:[RCTValueAnimatedNode class]]) {
125+
RCTValueAnimatedNode *valueAnimatedNode = (RCTValueAnimatedNode *)parentNode;
124126
NSString *property = [self propertyNameForParentTag:parentTag];
125-
id animatedObject = [(RCTValueAnimatedNode *)parentNode animatedObject];
127+
id animatedObject = valueAnimatedNode.animatedObject;
126128
if (animatedObject) {
127-
self->_propsDictionary[property] = animatedObject;
129+
_propsDictionary[property] = animatedObject;
128130
} else {
129-
CGFloat value = [(RCTValueAnimatedNode *)parentNode value];
130-
self->_propsDictionary[property] = @(value);
131+
_propsDictionary[property] = @(valueAnimatedNode.value);
131132
}
133+
} else if ([parentNode isKindOfClass:[RCTColorAnimatedNode class]]) {
134+
RCTColorAnimatedNode *colorAnimatedNode = (RCTColorAnimatedNode *)parentNode;
135+
NSString *property = [self propertyNameForParentTag:parentTag];
136+
_propsDictionary[property] = @(colorAnimatedNode.color);
132137
}
133138
}
134139

Libraries/NativeAnimation/Nodes/RCTStyleAnimatedNode.m

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import <React/RCTAnimationUtils.h>
1010
#import <React/RCTValueAnimatedNode.h>
1111
#import <React/RCTTransformAnimatedNode.h>
12+
#import <React/RCTColorAnimatedNode.h>
1213

1314
@implementation RCTStyleAnimatedNode
1415
{
@@ -38,11 +39,14 @@ - (void)performUpdate
3839
RCTAnimatedNode *node = [self.parentNodes objectForKey:nodeTag];
3940
if (node) {
4041
if ([node isKindOfClass:[RCTValueAnimatedNode class]]) {
41-
RCTValueAnimatedNode *parentNode = (RCTValueAnimatedNode *)node;
42-
[self->_propsDictionary setObject:@(parentNode.value) forKey:property];
42+
RCTValueAnimatedNode *valueAnimatedNode = (RCTValueAnimatedNode *)node;
43+
_propsDictionary[property] = @(valueAnimatedNode.value);
4344
} else if ([node isKindOfClass:[RCTTransformAnimatedNode class]]) {
44-
RCTTransformAnimatedNode *parentNode = (RCTTransformAnimatedNode *)node;
45-
[self->_propsDictionary addEntriesFromDictionary:parentNode.propsDictionary];
45+
RCTTransformAnimatedNode *transformAnimatedNode = (RCTTransformAnimatedNode *)node;
46+
[_propsDictionary addEntriesFromDictionary:transformAnimatedNode.propsDictionary];
47+
} else if ([node isKindOfClass:[RCTColorAnimatedNode class]]) {
48+
RCTColorAnimatedNode *colorAnimatedNode = (RCTColorAnimatedNode *)node;
49+
_propsDictionary[property] = @(colorAnimatedNode.color);
4650
}
4751
}
4852
}];

Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <React/RCTAdditionAnimatedNode.h>
1313
#import <React/RCTAnimatedNode.h>
1414
#import <React/RCTAnimationDriver.h>
15+
#import <React/RCTColorAnimatedNode.h>
1516
#import <React/RCTDiffClampAnimatedNode.h>
1617
#import <React/RCTDivisionAnimatedNode.h>
1718
#import <React/RCTEventAnimation.h>
@@ -86,6 +87,7 @@ - (void)createAnimatedNode:(NSNumber *)tag
8687
dispatch_once(&mapToken, ^{
8788
map = @{@"style" : [RCTStyleAnimatedNode class],
8889
@"value" : [RCTValueAnimatedNode class],
90+
@"color" : [RCTColorAnimatedNode class],
8991
@"props" : [RCTPropsAnimatedNode class],
9092
@"interpolation" : [RCTInterpolationAnimatedNode class],
9193
@"addition" : [RCTAdditionAnimatedNode class],

Libraries/NativeAnimation/React-RCTAnimation.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Pod::Spec.new do |s|
2929
s.platforms = { :ios => "11.0" }
3030
s.compiler_flags = folly_compiler_flags + ' -Wno-nullability-completeness'
3131
s.source = source
32-
s.source_files = "{Drivers/*,Nodes/*,*}.{m,mm}"
32+
s.source_files = "**/*.{h,m,mm}"
3333
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
3434
s.header_dir = "RCTAnimation"
3535
s.pod_target_xcconfig = {

React/Fabric/Mounting/RCTMountingManager.mm

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import <React/RCTFollyConvert.h>
1515
#import <React/RCTLog.h>
1616
#import <React/RCTUtils.h>
17+
#import <react/config/ReactNativeConfig.h>
1718
#import <react/renderer/components/root/RootShadowNode.h>
1819
#import <react/renderer/core/LayoutableShadowNode.h>
1920
#import <react/renderer/core/RawProps.h>
@@ -316,6 +317,11 @@ - (void)synchronouslyUpdateViewOnUIThread:(ReactTag)reactTag
316317
if (props[@"opacity"] && componentView.layer.opacity != (float)newViewProps.opacity) {
317318
componentView.layer.opacity = newViewProps.opacity;
318319
}
320+
321+
auto reactNativeConfig = _contextContainer->at<std::shared_ptr<ReactNativeConfig const>>("ReactNativeConfig");
322+
if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:finalize_updates_on_synchronous_update_view_ios")) {
323+
[componentView finalizeUpdates:RNComponentViewUpdateMaskProps];
324+
}
319325
}
320326

321327
- (void)synchronouslyDispatchCommandOnUIThread:(ReactTag)reactTag

ReactCommon/react/renderer/graphics/platform/ios/Color.h

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#pragma once
99

10-
#include <butter/optional.h>
1110
#include <cmath>
1211

1312
#include <folly/Hash.h>

packages/rn-tester/Podfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ SPEC CHECKSUMS:
884884
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
885885
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
886886
FBLazyVector: b81a2b70c72d8b0aefb652cea22c11e9ffd02949
887-
FBReactNativeSpec: 8e730e8017b1ba644ba3c14f0c33a4cc96cce9f4
887+
FBReactNativeSpec: 277e2460e8a1a20883306c886d5d57a361e32a71
888888
Flipper: 26fc4b7382499f1281eb8cb921e5c3ad6de91fe0
889889
Flipper-Boost-iOSX: fd1e2b8cbef7e662a122412d7ac5f5bea715403c
890890
Flipper-DoubleConversion: 57ffbe81ef95306cc9e69c4aa3aeeeeb58a6a28c
@@ -915,7 +915,7 @@ SPEC CHECKSUMS:
915915
React-logger: 2009c0280c286a76200d6b7c5fe242fad51ddd7a
916916
React-perflogger: fe66bd6d8b17ebcfdf0159bf41fe28d8035ac20c
917917
React-RCTActionSheet: 3131a0b9280aa0e51bdf54b3d79aecd8503db62c
918-
React-RCTAnimation: 70f2b9daaa1b45dea608be865cc5f2e1789dbc39
918+
React-RCTAnimation: 0c0a35cd27c5005cfddcda59b612994f4ebdaa43
919919
React-RCTBlob: 48cae62d905ef96ab10c84ab16163643a3c872a7
920920
React-RCTFabric: c126a269f6279896e19e133d6b1e019fa2f0f028
921921
React-RCTImage: 2ce3f1f72de91798eb31c9001b30cab8d1c71c4e
@@ -926,10 +926,10 @@ SPEC CHECKSUMS:
926926
React-RCTTest: 12bbd7fc2e72bd9920dc7286c5b8ef96639582b6
927927
React-RCTText: e9146b2c0550a83d1335bfe2553760070a2d75c7
928928
React-RCTVibration: 50be9c390f2da76045ef0dfdefa18b9cf9f35cfa
929-
React-rncore: 7db29a115e312e9f0f280294d78fe8501f740d8d
929+
React-rncore: 252dd9c510174ba718e358d332a43ad7056e9cb0
930930
React-runtimeexecutor: 4b0c6eb341c7d3ceb5e2385cb0fdb9bf701024f3
931931
ReactCommon: 7a2714d1128f965392b6f99a8b390e3aa38c9569
932-
ScreenshotManager: 1a419252584923755f7e7fd96ededcac2cf95521
932+
ScreenshotManager: 79ae4255728f14773097f05accaa53949bdd526c
933933
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
934934
Yoga: c0d06f5380d34e939f55420669a60fe08b79bd75
935935
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

0 commit comments

Comments
 (0)