first commit

This commit is contained in:
2026-03-10 16:18:05 +00:00
commit 11f9c069b5
31635 changed files with 3187747 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
/*
* 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 "RCTValueAnimatedNode.h"
@interface RCTAdditionAnimatedNode : RCTValueAnimatedNode
@end

View File

@@ -0,0 +1,25 @@
/*
* 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 <React/RCTAdditionAnimatedNode.h>
@implementation RCTAdditionAnimatedNode
- (void)performUpdate
{
[super performUpdate];
NSArray<NSNumber *> *inputNodes = self.config[@"input"];
if (inputNodes.count > 1) {
RCTValueAnimatedNode *parent1 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[0]];
RCTValueAnimatedNode *parent2 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[1]];
if ([parent1 isKindOfClass:[RCTValueAnimatedNode class]] && [parent2 isKindOfClass:[RCTValueAnimatedNode class]]) {
self.value = parent1.value + parent2.value;
}
}
}
@end

View File

@@ -0,0 +1,50 @@
/*
* 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 <Foundation/Foundation.h>
@class RCTNativeAnimatedNodesManager;
@interface RCTAnimatedNode : NSObject
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config NS_DESIGNATED_INITIALIZER;
@property (nonatomic, readonly) NSNumber *nodeTag;
@property (nonatomic, weak) RCTNativeAnimatedNodesManager *manager;
@property (nonatomic, copy, readonly) NSDictionary<NSString *, id> *config;
@property (nonatomic, copy, readonly) NSMapTable<NSNumber *, RCTAnimatedNode *> *childNodes;
@property (nonatomic, copy, readonly) NSMapTable<NSNumber *, RCTAnimatedNode *> *parentNodes;
@property (nonatomic, readonly) BOOL needsUpdate;
- (BOOL)isManagedByFabric;
/**
* Marks a node and its children as needing update.
*/
- (void)setNeedsUpdate NS_REQUIRES_SUPER;
/**
* The node will update its value if necessary and only after its parents have updated.
*/
- (void)updateNodeIfNecessary NS_REQUIRES_SUPER;
/**
* Where the actual update code lives. Called internally from updateNodeIfNecessary
*/
- (void)performUpdate NS_REQUIRES_SUPER;
- (void)addChild:(RCTAnimatedNode *)child NS_REQUIRES_SUPER;
- (void)removeChild:(RCTAnimatedNode *)child NS_REQUIRES_SUPER;
- (void)onAttachedToNode:(RCTAnimatedNode *)parent NS_REQUIRES_SUPER;
- (void)onDetachedFromNode:(RCTAnimatedNode *)parent NS_REQUIRES_SUPER;
- (void)detachNode NS_REQUIRES_SUPER;
@end

View File

@@ -0,0 +1,126 @@
/*
* 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 <React/RCTAnimatedNode.h>
#import <React/RCTDefines.h>
@implementation RCTAnimatedNode {
NSMapTable<NSNumber *, RCTAnimatedNode *> *_childNodes;
NSMapTable<NSNumber *, RCTAnimatedNode *> *_parentNodes;
}
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config
{
if ((self = [super init]) != nullptr) {
_nodeTag = tag;
_config = [config copy];
}
return self;
}
RCT_NOT_IMPLEMENTED(-(instancetype)init)
- (NSMapTable<NSNumber *, RCTAnimatedNode *> *)childNodes
{
return _childNodes;
}
- (NSMapTable<NSNumber *, RCTAnimatedNode *> *)parentNodes
{
return _parentNodes;
}
- (void)addChild:(RCTAnimatedNode *)child
{
if (_childNodes == nullptr) {
_childNodes = [NSMapTable strongToWeakObjectsMapTable];
}
if (child != nullptr) {
[_childNodes setObject:child forKey:child.nodeTag];
[child onAttachedToNode:self];
}
}
- (void)removeChild:(RCTAnimatedNode *)child
{
if (_childNodes == nullptr) {
return;
}
if (child != nullptr) {
[_childNodes removeObjectForKey:child.nodeTag];
[child onDetachedFromNode:self];
}
}
- (void)onAttachedToNode:(RCTAnimatedNode *)parent
{
if (_parentNodes == nullptr) {
_parentNodes = [NSMapTable strongToWeakObjectsMapTable];
}
if (parent != nullptr) {
[_parentNodes setObject:parent forKey:parent.nodeTag];
}
}
- (void)onDetachedFromNode:(RCTAnimatedNode *)parent
{
if (_parentNodes == nullptr) {
return;
}
if (parent != nullptr) {
[_parentNodes removeObjectForKey:parent.nodeTag];
}
}
- (void)detachNode
{
for (RCTAnimatedNode *parent in _parentNodes.objectEnumerator) {
[parent removeChild:self];
}
for (RCTAnimatedNode *child in _childNodes.objectEnumerator) {
[self removeChild:child];
}
}
- (void)setNeedsUpdate
{
_needsUpdate = YES;
for (RCTAnimatedNode *child in _childNodes.objectEnumerator) {
[child setNeedsUpdate];
}
}
- (void)updateNodeIfNecessary
{
if (_needsUpdate) {
for (RCTAnimatedNode *parent in _parentNodes.objectEnumerator) {
[parent updateNodeIfNecessary];
}
[self performUpdate];
}
}
- (void)performUpdate
{
_needsUpdate = NO;
// To be overridden by subclasses
// This method is called on a node only if it has been marked for update
// during the current update loop
}
- (BOOL)isManagedByFabric
{
for (RCTAnimatedNode *child in _childNodes.objectEnumerator) {
if ([child isManagedByFabric]) {
return YES;
}
}
return NO;
}
@end

View File

@@ -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 <React/RCTAnimatedNode.h>
@interface RCTColorAnimatedNode : RCTAnimatedNode
@property (nonatomic, assign) int32_t color;
@end

View File

@@ -0,0 +1,29 @@
/*
* 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 <React/RCTColorAnimatedNode.h>
#import <React/RCTValueAnimatedNode.h>
#import <React/RCTAnimationUtils.h>
@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 = RCTColorFromComponents(rNode.value, gNode.value, bNode.value, aNode.value);
// TODO (T111179606): Support platform colors for color animations
}
@end

View File

@@ -0,0 +1,12 @@
/*
* 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 "RCTValueAnimatedNode.h"
@interface RCTDiffClampAnimatedNode : RCTValueAnimatedNode
@end

View File

@@ -0,0 +1,64 @@
/*
* 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 <React/RCTDiffClampAnimatedNode.h>
#import <React/RCTLog.h>
@implementation RCTDiffClampAnimatedNode {
NSNumber *_inputNodeTag;
CGFloat _min;
CGFloat _max;
CGFloat _lastValue;
}
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config
{
if (self = [super initWithTag:tag config:config]) {
_inputNodeTag = config[@"input"];
_min = [config[@"min"] floatValue];
_max = [config[@"max"] floatValue];
}
return self;
}
- (void)onAttachedToNode:(RCTAnimatedNode *)parent
{
[super onAttachedToNode:parent];
self.value = _lastValue = [self inputNodeValue];
}
- (void)performUpdate
{
[super performUpdate];
CGFloat value = [self inputNodeValue];
CGFloat diff = value - _lastValue;
_lastValue = value;
self.value = MIN(MAX(self.value + diff, _min), _max);
}
- (CGFloat)inputNodeValue
{
if (self.parentNodes == nil) {
RCTLogWarn(@"Animated.DiffClamp node has not been fully initialised.");
return 0;
}
RCTValueAnimatedNode *inputNode = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:_inputNodeTag];
if (![inputNode isKindOfClass:[RCTValueAnimatedNode class]]) {
RCTLogError(@"Illegal node ID set as an input for Animated.DiffClamp node");
return 0;
}
return inputNode.value;
}
@end

View File

@@ -0,0 +1,12 @@
/*
* 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 "RCTValueAnimatedNode.h"
@interface RCTDivisionAnimatedNode : RCTValueAnimatedNode
@end

View File

@@ -0,0 +1,32 @@
/*
* 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 <React/RCTDivisionAnimatedNode.h>
#import <React/RCTLog.h>
@implementation RCTDivisionAnimatedNode
- (void)performUpdate
{
[super performUpdate];
NSArray<NSNumber *> *inputNodes = self.config[@"input"];
if (inputNodes.count > 1) {
RCTValueAnimatedNode *parent1 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[0]];
RCTValueAnimatedNode *parent2 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[1]];
if ([parent1 isKindOfClass:[RCTValueAnimatedNode class]] && [parent2 isKindOfClass:[RCTValueAnimatedNode class]]) {
if (parent2.value == 0) {
RCTLogError(@"Detected a division by zero in Animated.divide node");
return;
}
self.value = parent1.value / parent2.value;
}
}
}
@end

View File

@@ -0,0 +1,26 @@
/*
* 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 "RCTValueAnimatedNode.h"
#import <React/RCTDefines.h>
NS_ASSUME_NONNULL_BEGIN
RCT_EXTERN NSString *RCTInterpolateString(
NSString *pattern,
CGFloat inputValue,
NSArray<NSNumber *> *inputRange,
NSArray<NSArray<NSNumber *> *> *outputRange,
NSString *extrapolateLeft,
NSString *extrapolateRight);
@interface RCTInterpolationAnimatedNode : RCTValueAnimatedNode
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,169 @@
/*
* 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 "RCTInterpolationAnimatedNode.h"
#import <React/RCTAnimationUtils.h>
#import <React/RCTConvert.h>
typedef NS_ENUM(NSInteger, RCTInterpolationOutputType) {
RCTInterpolationOutputNumber,
RCTInterpolationOutputColor,
RCTInterpolationOutputString,
};
static NSRegularExpression *getNumericComponentRegex(void)
{
static NSRegularExpression *regex;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *fpRegex = @"[+-]?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?";
regex = [NSRegularExpression regularExpressionWithPattern:fpRegex
options:NSRegularExpressionCaseInsensitive
error:nil];
});
return regex;
}
static NSArray<NSArray<NSNumber *> *> *outputFromStringPattern(NSString *input)
{
NSMutableArray *output = [NSMutableArray array];
[getNumericComponentRegex()
enumerateMatchesInString:input
options:0
range:NSMakeRange(0, input.length)
usingBlock:^(NSTextCheckingResult *_Nullable result, NSMatchingFlags flags, BOOL *_Nonnull stop) {
[output addObject:@([[input substringWithRange:result.range] doubleValue])];
}];
return output;
}
NSString *RCTInterpolateString(
NSString *pattern,
CGFloat inputValue,
NSArray<NSNumber *> *inputRange,
NSArray<NSArray<NSNumber *> *> *outputRange,
NSString *extrapolateLeft,
NSString *extrapolateRight)
{
NSUInteger rangeIndex = RCTFindIndexOfNearestValue(inputValue, inputRange);
NSMutableString *output = [NSMutableString stringWithString:pattern];
NSArray<NSTextCheckingResult *> *matches =
[getNumericComponentRegex() matchesInString:pattern options:0 range:NSMakeRange(0, pattern.length)];
NSInteger matchIndex = matches.count - 1;
for (NSTextCheckingResult *match in [matches reverseObjectEnumerator]) {
CGFloat val = RCTInterpolateValue(
inputValue,
[inputRange[rangeIndex] doubleValue],
[inputRange[rangeIndex + 1] doubleValue],
[outputRange[rangeIndex][matchIndex] doubleValue],
[outputRange[rangeIndex + 1][matchIndex] doubleValue],
extrapolateLeft,
extrapolateRight);
[output replaceCharactersInRange:match.range withString:[@(val) stringValue]];
matchIndex--;
}
return output;
}
@implementation RCTInterpolationAnimatedNode {
__weak RCTValueAnimatedNode *_parentNode;
NSArray<NSNumber *> *_inputRange;
NSArray *_outputRange;
NSString *_extrapolateLeft;
NSString *_extrapolateRight;
RCTInterpolationOutputType _outputType;
id _Nullable _outputvalue;
NSString *_Nullable _outputPattern;
NSArray<NSTextCheckingResult *> *_matches;
}
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config
{
if ((self = [super initWithTag:tag config:config]) != nullptr) {
_inputRange = config[@"inputRange"];
NSArray *outputRangeConfig = config[@"outputRange"];
if ([config[@"outputType"] isEqual:@"color"]) {
_outputType = RCTInterpolationOutputColor;
} else if ([outputRangeConfig[0] isKindOfClass:[NSString class]]) {
_outputType = RCTInterpolationOutputString;
_outputPattern = outputRangeConfig[0];
} else {
_outputType = RCTInterpolationOutputNumber;
}
NSMutableArray *outputRange = [NSMutableArray arrayWithCapacity:outputRangeConfig.count];
for (id value in outputRangeConfig) {
switch (_outputType) {
case RCTInterpolationOutputColor: {
UIColor *color = [RCTConvert UIColor:value];
[outputRange addObject:(color != nullptr) ? color : [UIColor whiteColor]];
break;
}
case RCTInterpolationOutputString:
[outputRange addObject:outputFromStringPattern(value)];
break;
case RCTInterpolationOutputNumber:
[outputRange addObject:value];
break;
}
}
_outputRange = outputRange;
_extrapolateLeft = config[@"extrapolateLeft"];
_extrapolateRight = config[@"extrapolateRight"];
}
return self;
}
- (void)onAttachedToNode:(RCTAnimatedNode *)parent
{
[super onAttachedToNode:parent];
if ([parent isKindOfClass:[RCTValueAnimatedNode class]]) {
_parentNode = (RCTValueAnimatedNode *)parent;
}
}
- (void)onDetachedFromNode:(RCTAnimatedNode *)parent
{
[super onDetachedFromNode:parent];
if (_parentNode == parent) {
_parentNode = nil;
}
}
- (void)performUpdate
{
[super performUpdate];
if (_parentNode == nullptr) {
return;
}
CGFloat inputValue = _parentNode.value;
switch (_outputType) {
case RCTInterpolationOutputColor:
_outputvalue = @(RCTInterpolateColorInRange(inputValue, _inputRange, _outputRange));
break;
case RCTInterpolationOutputString:
_outputvalue = RCTInterpolateString(
_outputPattern, inputValue, _inputRange, _outputRange, _extrapolateLeft, _extrapolateRight);
break;
case RCTInterpolationOutputNumber:
self.value =
RCTInterpolateValueInRange(inputValue, _inputRange, _outputRange, _extrapolateLeft, _extrapolateRight);
break;
}
}
- (id)animatedObject
{
return _outputvalue;
}
@end

View File

@@ -0,0 +1,12 @@
/*
* 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 "RCTValueAnimatedNode.h"
@interface RCTModuloAnimatedNode : RCTValueAnimatedNode
@end

View File

@@ -0,0 +1,22 @@
/*
* 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 <React/RCTModuloAnimatedNode.h>
@implementation RCTModuloAnimatedNode
- (void)performUpdate
{
[super performUpdate];
NSNumber *inputNode = self.config[@"input"];
NSNumber *modulus = self.config[@"modulus"];
RCTValueAnimatedNode *parent = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNode];
const float m = modulus.floatValue;
self.value = fmodf(fmodf(parent.value, m) + m, m);
}
@end

View File

@@ -0,0 +1,12 @@
/*
* 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 "RCTValueAnimatedNode.h"
@interface RCTMultiplicationAnimatedNode : RCTValueAnimatedNode
@end

View File

@@ -0,0 +1,26 @@
/*
* 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 <React/RCTMultiplicationAnimatedNode.h>
@implementation RCTMultiplicationAnimatedNode
- (void)performUpdate
{
[super performUpdate];
NSArray<NSNumber *> *inputNodes = self.config[@"input"];
if (inputNodes.count > 1) {
RCTValueAnimatedNode *parent1 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[0]];
RCTValueAnimatedNode *parent2 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[1]];
if ([parent1 isKindOfClass:[RCTValueAnimatedNode class]] && [parent2 isKindOfClass:[RCTValueAnimatedNode class]]) {
self.value = parent1.value * parent2.value;
}
}
}
@end

View File

@@ -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

View File

@@ -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 != nullptr) && [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

View File

@@ -0,0 +1,26 @@
/*
* 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"
#import <React/RCTSurfacePresenterStub.h>
@class RCTBridge;
@class RCTViewPropertyMapper;
@interface RCTPropsAnimatedNode : RCTAnimatedNode
- (void)connectToView:(NSNumber *)viewTag
viewName:(NSString *)viewName
bridge:(RCTBridge *)bridge
surfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter;
- (void)disconnectFromView:(NSNumber *)viewTag;
- (void)restoreDefaultValues;
@end

View File

@@ -0,0 +1,146 @@
/*
* 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 <React/RCTPropsAnimatedNode.h>
#import <React/RCTAnimationUtils.h>
#import <React/RCTColorAnimatedNode.h>
#import <React/RCTObjectAnimatedNode.h>
#import <React/RCTStyleAnimatedNode.h>
#import <React/RCTUIManager.h>
#import <React/RCTValueAnimatedNode.h>
@implementation RCTPropsAnimatedNode {
NSNumber *_connectedViewTag;
NSString *_connectedViewName;
__weak RCTBridge *_bridge;
__weak id<RCTSurfacePresenterStub> _surfacePresenter;
NSMutableDictionary<NSString *, NSObject *> *_propsDictionary; // TODO: use RawProps or folly::dynamic directly
BOOL _managedByFabric;
}
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config
{
if (self = [super initWithTag:tag config:config]) {
_propsDictionary = [NSMutableDictionary new];
}
return self;
}
- (BOOL)isManagedByFabric
{
return _managedByFabric;
}
- (void)connectToView:(NSNumber *)viewTag
viewName:(NSString *)viewName
bridge:(RCTBridge *)bridge
surfacePresenter:(id<RCTSurfacePresenterStub>)surfacePresenter
{
_bridge = bridge;
_surfacePresenter = surfacePresenter;
_connectedViewTag = viewTag;
_connectedViewName = viewName;
_managedByFabric = RCTUIManagerTypeForTagIsFabric(viewTag);
}
- (void)disconnectFromView:(NSNumber *)viewTag
{
_bridge = nil;
_surfacePresenter = nil;
_connectedViewTag = nil;
_connectedViewName = nil;
_managedByFabric = NO;
}
- (void)updateView
{
if (_managedByFabric) {
if (_bridge.surfacePresenter) {
[_bridge.surfacePresenter synchronouslyUpdateViewOnUIThread:_connectedViewTag props:_propsDictionary];
} else {
[_surfacePresenter synchronouslyUpdateViewOnUIThread:_connectedViewTag props:_propsDictionary];
}
} else {
[_bridge.uiManager synchronouslyUpdateViewOnUIThread:_connectedViewTag
viewName:_connectedViewName
props:_propsDictionary];
}
}
- (void)restoreDefaultValues
{
if (_managedByFabric) {
// Restoring to default values causes render of inconsistent state
// to the user because it isn't synchronised with Fabric's UIManager.
return;
}
// Restore the default value for all props that were modified by this node.
for (NSString *key in _propsDictionary.allKeys) {
_propsDictionary[key] = [NSNull null];
}
if (_propsDictionary.count) {
[self updateView];
}
}
- (NSString *)propertyNameForParentTag:(NSNumber *)parentTag
{
__block NSString *propertyName;
[self.config[@"props"]
enumerateKeysAndObjectsUsingBlock:^(NSString *_Nonnull property, NSNumber *_Nonnull tag, BOOL *_Nonnull stop) {
if ([tag isEqualToNumber:parentTag]) {
propertyName = property;
*stop = YES;
}
}];
return propertyName;
}
- (void)performUpdate
{
[super performUpdate];
// Since we are updating nodes after detaching them from views there is a time where it's
// possible that the view was disconnected and still receive an update, this is normal and we can
// simply skip that update.
if (!_connectedViewTag) {
return;
}
for (NSNumber *parentTag in self.parentNodes.keyEnumerator) {
RCTAnimatedNode *parentNode = [self.parentNodes objectForKey:parentTag];
if ([parentNode isKindOfClass:[RCTStyleAnimatedNode class]]) {
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 = valueAnimatedNode.animatedObject;
if (animatedObject) {
_propsDictionary[property] = animatedObject;
} else {
_propsDictionary[property] = @(valueAnimatedNode.value);
}
} else if ([parentNode isKindOfClass:[RCTColorAnimatedNode class]]) {
RCTColorAnimatedNode *colorAnimatedNode = (RCTColorAnimatedNode *)parentNode;
NSString *property = [self propertyNameForParentTag:parentTag];
_propsDictionary[property] = @(colorAnimatedNode.color);
} else if ([parentNode isKindOfClass:[RCTObjectAnimatedNode class]]) {
RCTObjectAnimatedNode *objectAnimatedNode = (RCTObjectAnimatedNode *)parentNode;
NSString *property = [self propertyNameForParentTag:parentTag];
_propsDictionary[property] = objectAnimatedNode.value;
}
}
if (_propsDictionary.count) {
[self updateView];
}
}
@end

View File

@@ -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 RCTStyleAnimatedNode : RCTAnimatedNode
- (NSDictionary<NSString *, NSObject *> *)propsDictionary;
@end

View File

@@ -0,0 +1,62 @@
/*
* 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 <React/RCTAnimationUtils.h>
#import <React/RCTColorAnimatedNode.h>
#import <React/RCTObjectAnimatedNode.h>
#import <React/RCTStyleAnimatedNode.h>
#import <React/RCTTransformAnimatedNode.h>
#import <React/RCTValueAnimatedNode.h>
@implementation RCTStyleAnimatedNode {
NSMutableDictionary<NSString *, NSObject *> *_propsDictionary;
}
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config
{
if ((self = [super initWithTag:tag config:config]) != nullptr) {
_propsDictionary = [NSMutableDictionary new];
}
return self;
}
- (NSDictionary *)propsDictionary
{
return _propsDictionary;
}
- (void)performUpdate
{
[super performUpdate];
NSDictionary<NSString *, NSNumber *> *style = self.config[@"style"];
[style enumerateKeysAndObjectsUsingBlock:^(NSString *property, NSNumber *nodeTag, __unused BOOL *stop) {
RCTAnimatedNode *node = [self.parentNodes objectForKey:nodeTag];
if (node != nullptr) {
if ([node isKindOfClass:[RCTValueAnimatedNode class]]) {
RCTValueAnimatedNode *valueAnimatedNode = (RCTValueAnimatedNode *)node;
id animatedObject = valueAnimatedNode.animatedObject;
if (animatedObject != nullptr) {
_propsDictionary[property] = animatedObject;
} else {
_propsDictionary[property] = @(valueAnimatedNode.value);
}
} else if ([node isKindOfClass:[RCTTransformAnimatedNode class]]) {
RCTTransformAnimatedNode *transformAnimatedNode = (RCTTransformAnimatedNode *)node;
[_propsDictionary addEntriesFromDictionary:transformAnimatedNode.propsDictionary];
} else if ([node isKindOfClass:[RCTColorAnimatedNode class]]) {
RCTColorAnimatedNode *colorAnimatedNode = (RCTColorAnimatedNode *)node;
_propsDictionary[property] = @(colorAnimatedNode.color);
} else if ([node isKindOfClass:[RCTObjectAnimatedNode class]]) {
RCTObjectAnimatedNode *objectAnimatedNode = (RCTObjectAnimatedNode *)node;
_propsDictionary[property] = objectAnimatedNode.value;
}
}
}];
}
@end

View File

@@ -0,0 +1,12 @@
/*
* 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 "RCTValueAnimatedNode.h"
@interface RCTSubtractionAnimatedNode : RCTValueAnimatedNode
@end

View File

@@ -0,0 +1,25 @@
/*
* 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 <React/RCTSubtractionAnimatedNode.h>
@implementation RCTSubtractionAnimatedNode
- (void)performUpdate
{
[super performUpdate];
NSArray<NSNumber *> *inputNodes = self.config[@"input"];
if (inputNodes.count > 1) {
RCTValueAnimatedNode *parent1 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[0]];
RCTValueAnimatedNode *parent2 = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:inputNodes[1]];
if ([parent1 isKindOfClass:[RCTValueAnimatedNode class]] && [parent2 isKindOfClass:[RCTValueAnimatedNode class]]) {
self.value = parent1.value - parent2.value;
}
}
}
@end

View File

@@ -0,0 +1,12 @@
/*
* 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 RCTTrackingAnimatedNode : RCTAnimatedNode
@end

View File

@@ -0,0 +1,47 @@
/*
* 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 <React/RCTNativeAnimatedNodesManager.h>
#import <React/RCTTrackingAnimatedNode.h>
#import <React/RCTValueAnimatedNode.h>
@implementation RCTTrackingAnimatedNode {
NSNumber *_animationId;
NSNumber *_toValueNodeTag;
NSNumber *_valueNodeTag;
NSMutableDictionary *_animationConfig;
}
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config
{
if ((self = [super initWithTag:tag config:config]) != nullptr) {
_animationId = config[@"animationId"];
_toValueNodeTag = config[@"toValue"];
_valueNodeTag = config[@"value"];
_animationConfig = [NSMutableDictionary dictionaryWithDictionary:config[@"animationConfig"]];
}
return self;
}
- (void)onDetachedFromNode:(RCTAnimatedNode *)parent
{
[self.manager stopAnimation:_animationId];
[super onDetachedFromNode:parent];
}
- (void)performUpdate
{
[super performUpdate];
// change animation config's "toValue" to reflect updated value of the parent node
RCTValueAnimatedNode *node = (RCTValueAnimatedNode *)[self.parentNodes objectForKey:_toValueNodeTag];
_animationConfig[@"toValue"] = @(node.value);
[self.manager startAnimatingNode:_animationId nodeTag:_valueNodeTag config:_animationConfig endCallback:nil];
}
@end

View File

@@ -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 RCTTransformAnimatedNode : RCTAnimatedNode
- (NSDictionary<NSString *, NSObject *> *)propsDictionary;
@end

View File

@@ -0,0 +1,55 @@
/*
* 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 <React/RCTTransformAnimatedNode.h>
#import <React/RCTValueAnimatedNode.h>
@implementation RCTTransformAnimatedNode {
NSMutableDictionary<NSString *, NSObject *> *_propsDictionary;
}
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config
{
if ((self = [super initWithTag:tag config:config]) != nullptr) {
_propsDictionary = [NSMutableDictionary new];
}
return self;
}
- (NSDictionary *)propsDictionary
{
return _propsDictionary;
}
- (void)performUpdate
{
[super performUpdate];
NSArray<NSDictionary *> *transformConfigs = self.config[@"transforms"];
NSMutableArray<NSDictionary *> *transform = [NSMutableArray arrayWithCapacity:transformConfigs.count];
for (NSDictionary *transformConfig in transformConfigs) {
NSString *type = transformConfig[@"type"];
NSString *property = transformConfig[@"property"];
NSNumber *value;
if ([type isEqualToString:@"animated"]) {
NSNumber *nodeTag = transformConfig[@"nodeTag"];
RCTAnimatedNode *node = [self.parentNodes objectForKey:nodeTag];
if (![node isKindOfClass:[RCTValueAnimatedNode class]]) {
continue;
}
RCTValueAnimatedNode *parentNode = (RCTValueAnimatedNode *)node;
value = @(parentNode.value);
} else {
value = transformConfig[@"value"];
}
[transform addObject:@{property : value}];
}
_propsDictionary[@"transform"] = transform;
}
@end

View File

@@ -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 <UIKit/UIKit.h>
#import "RCTAnimatedNode.h"
@class RCTValueAnimatedNode;
@protocol RCTValueAnimatedNodeObserver <NSObject>
- (void)animatedNode:(RCTValueAnimatedNode *)node didUpdateValue:(CGFloat)value;
@end
@interface RCTValueAnimatedNode : RCTAnimatedNode
- (void)setOffset:(CGFloat)offset;
- (void)flattenOffset;
- (void)extractOffset;
@property (nonatomic, assign) CGFloat value;
@property (nonatomic, strong, readonly) id animatedObject;
@property (nonatomic, weak) id<RCTValueAnimatedNodeObserver> valueObserver;
@end

View File

@@ -0,0 +1,60 @@
/*
* 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 <React/RCTValueAnimatedNode.h>
@interface RCTValueAnimatedNode ()
@property (nonatomic, assign) CGFloat offset;
@end
@implementation RCTValueAnimatedNode
@synthesize value = _value;
- (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary<NSString *, id> *)config
{
if (self = [super initWithTag:tag config:config]) {
_offset = [self.config[@"offset"] floatValue];
_value = [self.config[@"value"] floatValue];
}
return self;
}
- (void)flattenOffset
{
_value += _offset;
_offset = 0;
}
- (void)extractOffset
{
_offset += _value;
_value = 0;
}
- (CGFloat)value
{
return _value + _offset;
}
- (id)animatedObject
{
return nil;
}
- (void)setValue:(CGFloat)value
{
_value = value;
if (_valueObserver) {
[_valueObserver animatedNode:self didUpdateValue:_value];
}
}
@end