From 9d9e250d28a6a4d1698ac02a1f905e20c5a66074 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 18 Sep 2017 15:32:51 -0700 Subject: [PATCH] Using `indexOfObjectIdenticalTo` instead of `indexOfObject` in RCTUIManager Summary: This should be much more performant (and it better illustrates the intension of the code). The fix was suggested by Adlai-Holler. Reviewed By: mmmulani Differential Revision: D5851595 fbshipit-source-id: 45d172a5fa796549c6dcea8f35c5cbb2a4c2d2e0 --- React/Modules/RCTUIManager.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index f64f8b7d3..aae34be74 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -768,7 +768,7 @@ RCT_EXPORT_METHOD(removeSubviewsFromContainerWithID:(nonnull NSNumber *)containe // So, let's temporary restore the view back after removing. // To do so, we have to memorize original `superview` (which can differ from `container`) and an index of removed view. UIView *originalSuperview = removedChild.superview; - NSUInteger originalIndex = [originalSuperview.subviews indexOfObject:removedChild]; + NSUInteger originalIndex = [originalSuperview.subviews indexOfObjectIdenticalTo:removedChild]; [container removeReactSubview:removedChild]; [originalSuperview insertSubview:removedChild atIndex:originalIndex]; @@ -821,7 +821,7 @@ RCT_EXPORT_METHOD(replaceExistingNonRootView:(nonnull NSNumber *)reactTag return; } - NSUInteger indexOfView = [superShadowView.reactSubviews indexOfObject:shadowView]; + NSUInteger indexOfView = [superShadowView.reactSubviews indexOfObjectIdenticalTo:shadowView]; RCTAssert(indexOfView != NSNotFound, @"View's superview doesn't claim it as subview (id %@)", reactTag); NSArray *removeAtIndices = @[@(indexOfView)]; NSArray *addTags = @[newReactTag];