diff --git a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm index 215d780b1..a055fc0e9 100644 --- a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm +++ b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutComponentKitSupport/SKComponentLayoutWrapper.mm @@ -45,12 +45,21 @@ static CKFlexboxComponentChild findFlexboxLayoutParams(CKComponent *parent, CKCo + (instancetype)newFromRoot:(id)root { const CKComponentLayout layout = [root mountedLayout]; + // Check if there is a cached wrapper. + if (layout.component) { + SKComponentLayoutWrapper *cachedWrapper = objc_getAssociatedObject(layout.component, &kLayoutWrapperKey); + if (cachedWrapper) { + return cachedWrapper; + } + } CKComponentReuseWrapper *reuseWrapper = CKAnalyticsListenerHelpers::GetReusedNodes(layout.component); + // Create a new layout wrapper. SKComponentLayoutWrapper *const wrapper = [[SKComponentLayoutWrapper alloc] initWithLayout:layout position:CGPointMake(0, 0) parentKey:[NSString stringWithFormat: @"%p.", layout.component] reuseWrapper:reuseWrapper]; + // Cache the result. if (layout.component) { objc_setAssociatedObject(layout.component, &kLayoutWrapperKey, wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC); }