-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce RCTObjectAnimatedNode (#36804)
Summary: Pull Request resolved: #36804 AnimatedObject is a more generic version of AnimatedTransform, able to handle animated values within arrays and objects. This is useful for props of native components that may need to be animated per field. This diff adds the native (iOS) counterpart to AnimatedObject node in JS. The node handles array and map value types. Changelog: [Internal][Added] - Introduce ObjectAnimatedNode iOS-side node for handling array and object prop values Reviewed By: philIip Differential Revision: D44678162 fbshipit-source-id: 7cdc075229a55fcb450f23ba5667b3ddd48c24df
- Loading branch information
1 parent
54a6922
commit 0858853
Showing
5 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
packages/react-native/Libraries/NativeAnimation/Nodes/RCTObjectAnimatedNode.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "RCTAnimatedNode.h" | ||
|
||
@interface RCTObjectAnimatedNode : RCTAnimatedNode | ||
|
||
@property (nonatomic, strong, readonly) id value; | ||
|
||
@end |
66 changes: 66 additions & 0 deletions
66
packages/react-native/Libraries/NativeAnimation/Nodes/RCTObjectAnimatedNode.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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 "RCTObjectAnimatedNode.h" | ||
#import "RCTValueAnimatedNode.h" | ||
|
||
NSString *const VALUE_KEY = @"value"; | ||
NSString *const NODE_TAG_KEY = @"nodeTag"; | ||
|
||
@implementation RCTObjectAnimatedNode | ||
|
||
- (void)performUpdate | ||
{ | ||
[super performUpdate]; | ||
|
||
id value = self.config[VALUE_KEY]; | ||
if ([value isKindOfClass:[NSDictionary class]]) { | ||
_value = [self _performUpdateHelperDictionary:(NSDictionary *)value]; | ||
} else if ([value isKindOfClass:[NSArray class]]) { | ||
_value = [self _performUpdateHelperArray:(NSArray *)value]; | ||
} | ||
} | ||
|
||
- (NSDictionary<NSString *, id> *)_performUpdateHelperDictionary:(NSDictionary<NSString *, id> *)source | ||
{ | ||
NSMutableDictionary<NSString *, id> *result = [NSMutableDictionary new]; | ||
for (NSString *key in source) { | ||
result[key] = [self _convertValue:source[key]]; | ||
} | ||
return result; | ||
} | ||
|
||
- (NSArray *)_performUpdateHelperArray:(NSArray *)source | ||
{ | ||
NSMutableArray *result = [NSMutableArray array]; | ||
for (id value in source) { | ||
[result addObject:[self _convertValue:value]]; | ||
} | ||
return result; | ||
} | ||
|
||
- (id)_convertValue:(id)value | ||
{ | ||
if ([value isKindOfClass:[NSDictionary class]]) { | ||
NSDictionary<NSString *, id> *dict = (NSDictionary *)value; | ||
id nodeTag = [dict objectForKey:NODE_TAG_KEY]; | ||
if (nodeTag && [nodeTag isKindOfClass:[NSNumber class]]) { | ||
RCTAnimatedNode *node = [self.parentNodes objectForKey:(NSNumber *)nodeTag]; | ||
if ([node isKindOfClass:[RCTValueAnimatedNode class]]) { | ||
RCTValueAnimatedNode *valueNode = (RCTValueAnimatedNode *)node; | ||
return @(valueNode.value); | ||
} | ||
} | ||
return [self _performUpdateHelperDictionary:dict]; | ||
} else if ([value isKindOfClass:[NSArray class]]) { | ||
return [self _performUpdateHelperArray:(NSArray *)value]; | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters