Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; \
}
Comment on lines +22 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right approach because this is a static method. It means that it applies to ALL the components of a given type.
So, let's imagine that we set RCTComponentViewShouldBeRecycled(false) to RCTView, we are disabling the recyclability for ALL the RCTViews.
The possibility to be recycled or not should be a choice made instance per instance.

I should be able to say that my RCTImage x should not be recycled (perhaps it is a large image and I want to keep it i memory as a perf optimization, while my RCTImage y should not.

What do you think?

cc. @sammy-SC which knows this part of the Framework better than me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I just follow the custom user components because it's class method implemented in

.shouldBeRecycled = [viewClass respondsToSelector:@selector(shouldBeRecycled)]

Maybe we can expose some like a delegate to AppDelegate and give its instance to ask the user to decide whether to disable recycle?


/**
* 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