Fabric: Making _propKeysManagedByAnimated to preserve previous prop keys

Summary:
The previous implementation always replaced the prop set on every props update coming from Animated. Now, we merge the new set of props with the previous one.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D24370751

fbshipit-source-id: 779272d47c776cc42071d3c93d06443b6c96a877
This commit is contained in:
Valentin Shergin
2020-10-19 19:21:22 -07:00
committed by Facebook GitHub Bot
parent b05294dd99
commit c642afd97d
5 changed files with 37 additions and 17 deletions
@@ -23,7 +23,7 @@ using namespace facebook::react;
UIColor *_backgroundColor;
CALayer *_borderLayer;
BOOL _needsInvalidateLayer;
NSSet<NSString *> *_propKeysManagedByAnimated;
NSSet<NSString *> *_Nullable _propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;
}
- (instancetype)initWithFrame:(CGRect)frame
@@ -85,11 +85,6 @@ using namespace facebook::react;
return concreteComponentDescriptorProvider<ViewComponentDescriptor>();
}
- (void)setPropKeysManagedByAnimated:(nullable NSSet<NSString *> *)propKeys
{
_propKeysManagedByAnimated = propKeys;
}
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
{
#ifndef NS_BLOCK_ASSERTIONS
@@ -109,7 +104,8 @@ using namespace facebook::react;
BOOL needsInvalidateLayer = NO;
// `opacity`
if (oldViewProps.opacity != newViewProps.opacity && ![_propKeysManagedByAnimated containsObject:@"opacity"]) {
if (oldViewProps.opacity != newViewProps.opacity &&
![_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN containsObject:@"opacity"]) {
self.layer.opacity = (CGFloat)newViewProps.opacity;
needsInvalidateLayer = YES;
}
@@ -168,7 +164,8 @@ using namespace facebook::react;
}
// `transform`
if (oldViewProps.transform != newViewProps.transform && ![_propKeysManagedByAnimated containsObject:@"transform"]) {
if (oldViewProps.transform != newViewProps.transform &&
![_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN containsObject:@"transform"]) {
self.layer.transform = RCTCATransform3DFromTransformMatrix(newViewProps.transform);
self.layer.allowsEdgeAntialiasing = newViewProps.transform != Transform::Identity();
}
@@ -296,17 +293,27 @@ using namespace facebook::react;
// If view was managed by animated, its props need to align with UIView's properties.
auto const &props = *std::static_pointer_cast<ViewProps const>(_props);
if ([_propKeysManagedByAnimated containsObject:@"transform"]) {
if ([_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN containsObject:@"transform"]) {
self.layer.transform = RCTCATransform3DFromTransformMatrix(props.transform);
}
if ([_propKeysManagedByAnimated containsObject:@"opacity"]) {
if ([_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN containsObject:@"opacity"]) {
self.layer.opacity = (CGFloat)props.opacity;
}
_propKeysManagedByAnimated = nil;
_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN = nil;
_eventEmitter.reset();
}
- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(NSSet<NSString *> *_Nullable)props
{
_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN = props;
}
- (NSSet<NSString *> *_Nullable)propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN
{
return _propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;
}
- (UIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event
{
// This is a classic textbook implementation of `hitTest:` with a couple of improvements:
@@ -111,12 +111,16 @@ typedef NS_OPTIONS(NSInteger, RNComponentViewUpdateMask) {
*/
- (void)prepareForRecycle;
/**
/*
* Read the last props used to update the view.
*/
- (facebook::react::SharedProps)props;
- (void)setPropKeysManagedByAnimated:(nullable NSSet<NSString *> *)propKeys;
/*
* This is broken. Do not use.
*/
- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(nullable NSSet<NSString *> *)props;
- (nullable NSSet<NSString *> *)propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;
@end
+5 -2
View File
@@ -222,9 +222,12 @@ static void RCTPerformMountInstructions(
UIView<RCTComponentViewProtocol> *componentView = [_componentViewRegistry findComponentViewWithTag:reactTag];
SharedProps oldProps = [componentView props];
SharedProps newProps = componentDescriptor.cloneProps(oldProps, RawProps(convertIdToFollyDynamic(props)));
[componentView setPropKeysManagedByAnimated:nil];
NSSet<NSString *> *propKeys = componentView.propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN ?: [NSSet new];
propKeys = [propKeys setByAddingObjectsFromArray:props.allKeys];
componentView.propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN = nil;
[componentView updateProps:newProps oldProps:oldProps];
[componentView setPropKeysManagedByAnimated:[NSSet setWithArray:props.allKeys]];
componentView.propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN = propKeys;
}
- (void)synchronouslyDispatchCommandOnUIThread:(ReactTag)reactTag
@@ -39,7 +39,8 @@ NS_ASSUME_NONNULL_BEGIN
- (facebook::react::SharedProps)props;
- (void)setPropKeysManagedByAnimated:(nullable NSSet<NSString *> *)propKeys;
- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(nullable NSSet<NSString *> *)props;
- (nullable NSSet<NSString *> *)propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;
@end
@@ -132,9 +132,14 @@ using namespace facebook::react;
return nullptr;
}
- (void)setPropKeysManagedByAnimated:(nullable NSSet<NSString *> *)propKeys
- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(nullable NSSet<NSString *> *)propKeys
{
// Default implementation does nothing.
}
- (nullable NSSet<NSString *> *)propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN
{
return nil;
}
@end