-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[iOS] Fabric: make built-in components recycle optional #42780
[iOS] Fabric: make built-in components recycle optional #42780
Conversation
#define RCTComponentViewShouldBeRecycled(recycled) \ | ||
static bool _shouldBeRecycled = recycled; \ | ||
+(bool)shouldBeRecycled \ | ||
{ \ | ||
return _shouldBeRecycled; \ | ||
} \ | ||
\ | ||
+(void)setShouldBeRecycled : (bool)shouldBeRecycled \ | ||
{ \ | ||
_shouldBeRecycled = shouldBeRecycled; \ | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
react-native/packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm
Line 99 in ebb55a7
.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?
Let's not use macros and static variables here. Recycling should be configured as part of a class's implementation, by overriding I think we should consider changing the default to false to make sure components are aware of the need to reset props in between changes, but that's also why you should compare |
I don't think disabling recycling on core components is a good idea. We depend on this to achieve better performance characteristics and have plans around perf that depend on it. Regarding #42732, manually sizing a RCTViewComponentView will cause bugs. If you size component manually, bypassing the shadow tree, React Native will not have visibility into size of the view and hit testing won't work. |
@sammy-SC Yes, recycling is very critical for performance. But seems we don't have an easy way to add some custom recycle cleanup codes of built-in core components for users, if users add some custom logic on core components, they can do some cleanup when recycled. cc. @j-piasecki Any thoughts about the fix of your issue? :) |
I don't think that disabling the recycling for a particular view type is the solution, especially when the view in question is
That's the way it should be done, I've opened the issue mainly to raise the point that it's not always done directly - like in the linked
At the moment we patched |
I would be more inclined to reset autoresizingMask to none, rather than disabling view recycling.
This is interesting. So Calling setViewControllers (which takes an array of view controllers I suppose) will cause the UIPageViewController to change autoresizingMask on a view? Does it call it always on the top most view? |
It looks this way from the stack trace we got from overriding the setter for the |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
We can close it. The problem was surfaced because of a flaw in the original library and we don't want to provide this functionality to components as it is implemented here. |
Summary:
Fixes #42732. We already support custom component view recycle optional, but seems we have no interface to disable built-in components recycling.
Changelog:
[IOS] [ADDED] - Fabric: make built-in components recycle optional
Test Plan:
To disable built-in components recycle, we can call like
[*ComponentView setShouldBeRecycled:false]
.