Skip to content

Commit

Permalink
[iOS] Fabric: make built-in components recycle optional
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwuzw committed Feb 1, 2024
1 parent ebc2831 commit 843b93e
Show file tree
Hide file tree
Showing 20 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
[super updateProps:props oldProps:oldProps];
}

RCTComponentViewShouldBeRecycled(true);

@end

Class<RCTComponentViewProtocol> RCTActivityIndicatorViewCls(void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ + (ComponentDescriptorProvider)componentDescriptorProvider
return concreteComponentDescriptorProvider<DebuggingOverlayComponentDescriptor>();
}

RCTComponentViewShouldBeRecycled(true);

#pragma mark - Native commands

- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ - (void)prepareForRecycle
_imageView.image = nil;
}

RCTComponentViewShouldBeRecycled(true);

#pragma mark - RCTImageResponseDelegate

- (void)didReceiveImage:(UIImage *)image metadata:(id)metadata fromObserver:(const void *)observer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ - (void)prepareForRecycle
_textInput = nil;
}

RCTComponentViewShouldBeRecycled(true);

@end

Class<RCTComponentViewProtocol> RCTInputAccessoryCls(void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ - (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
updatePropsIfNeeded(updateMask);
}

RCTComponentViewShouldBeRecycled(true);

- (void)_setPropsWithUpdateMask:(RNComponentViewUpdateMask)updateMask
{
if (updateMask & RNComponentViewUpdateMaskProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
[childComponentView removeFromSuperview];
}

RCTComponentViewShouldBeRecycled(true);

@end

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ + (ComponentDescriptorProvider)componentDescriptorProvider
return concreteComponentDescriptorProvider<RootComponentDescriptor>();
}

RCTComponentViewShouldBeRecycled(true);

@end
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ - (void)prepareForRecycle
_state.reset();
}

RCTComponentViewShouldBeRecycled(true);

@end

Class<RCTComponentViewProtocol> RCTSafeAreaViewCls(void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
[super updateProps:props oldProps:oldProps];
}

RCTComponentViewShouldBeRecycled(true);

#pragma mark -

- (void)handleUIControlEventValueChanged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,8 @@ - (void)prepareForRecycle
[super prepareForRecycle];
}

RCTComponentViewShouldBeRecycled(true);

#pragma mark - UIScrollViewDelegate

- (BOOL)touchesShouldCancelInContentView:(__unused UIView *)view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ - (void)onChange:(UISwitch *)sender
.onChange(SwitchEventEmitter::OnChange{.value = static_cast<bool>(sender.on)});
}

RCTComponentViewShouldBeRecycled(true);

#pragma mark - Native Commands

- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ - (void)prepareForRecycle
_accessibilityProvider = nil;
}

RCTComponentViewShouldBeRecycled(true);

- (void)drawRect:(CGRect)rect
{
if (!_state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ - (void)prepareForRecycle
[_backedTextInputView resignFirstResponder];
}

RCTComponentViewShouldBeRecycled(true);

#pragma mark - RCTBackedTextInputDelegate

- (BOOL)textInputShouldBeginEditing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
[super updateProps:props oldProps:oldProps];
}

RCTComponentViewShouldBeRecycled(true);

@end
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
[super updateProps:props oldProps:oldProps];
}

RCTComponentViewShouldBeRecycled(true);

@end

Class<RCTComponentViewProtocol> RCTUnimplementedNativeViewCls(void)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@

NS_ASSUME_NONNULL_BEGIN

#define RCTComponentViewShouldBeRecycled(recycled) \
static bool _shouldBeRecycled = recycled; \
+(bool)shouldBeRecycled \
{ \
return _shouldBeRecycled; \
} \
\
+(void)setShouldBeRecycled : (bool)shouldBeRecycled \
{ \
_shouldBeRecycled = shouldBeRecycled; \
}

/**
* UIView class for <View> component.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
}
}

RCTComponentViewShouldBeRecycled(true);

#pragma mark - RCTComponentViewProtocol

+ (ComponentDescriptorProvider)componentDescriptorProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ typedef NS_OPTIONS(NSInteger, RNComponentViewUpdateMask) {
- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(nullable NSSet<NSString *> *)props;
- (nullable NSSet<NSString *> *)propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;

/*
* Mark component view should be recycled.
*/
+ (void)setShouldBeRecycled:(bool)shouldBeRecycled;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ NS_ASSUME_NONNULL_BEGIN

- (void)updateClippedSubviewsWithClipRect:(CGRect)clipRect relativeToView:(UIView *)clipView;

+ (void)setShouldBeRecycled:(bool)shouldBeRecycled;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,9 @@ - (void)updateClippedSubviewsWithClipRect:(CGRect)clipRect relativeToView:(UIVie
}
}

+ (void)setShouldBeRecycled:(bool)shouldBeRecycled
{
// Default implementation does nothing.
}

@end

0 comments on commit 843b93e

Please sign in to comment.