From 345a4dfdec44d16f88228d0aee697a2944640c4d Mon Sep 17 00:00:00 2001 From: Luke De Feo Date: Tue, 7 May 2024 11:39:33 -0700 Subject: [PATCH] Prevent UILabel from becoming active child Summary: context S415547 On ig there is a random UILabel that can beceome the last child of the ui window. This can become active and therefore we dont traverse the correct view. This attempts to mitigate this by making sure we only consider a view for becoming an active child if it itself has subviews Reviewed By: dinhvh, lblasa Differential Revision: D57058208 fbshipit-source-id: 57fcbc3cc6ed2ba02811d73bd5effb8db0b88bd7 --- .../Descriptors/UIView+UIDDescriptor.m | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIView+UIDDescriptor.m b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIView+UIDDescriptor.m index 189f6ec1116..0095a7d088a 100644 --- a/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIView+UIDDescriptor.m +++ b/iOS/Plugins/FlipperKitUIDebuggerPlugin/FlipperKitUIDebuggerPlugin/Descriptors/UIView+UIDDescriptor.m @@ -615,27 +615,33 @@ - (void)UID_aggregateAttributes:(nonnull UIDMutableAttributes*)attributes { /** In the context of UIView, the active child is defined as the last view in - the subviews collection. If said item's next responder is a UIViewController, - then return this instead. + the subviews collection that itself has children. This is to avoid random + labels or non container views becoming active child + + We need to account for the fact we inject view controllers into the heierachy, + so if said item's next responder is a different view controller to the current + UIViewController then return the new controller so the active child is + actually one of the children returned to the desktop */ + - (id)UID_activeChild { if (self.isHidden) { return nil; } - if (self.subviews && self.subviews.count > 0) { - UIView* activeChild = [self.subviews lastObject]; - BOOL isController = - [activeChild.nextResponder isKindOfClass:[UIViewController class]]; - - if (isController && activeChild.nextResponder != self.nextResponder) { -/* @cwt-override FIXME[T168581563]: -Wnullable-to-nonnull-conversion */ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnullable-to-nonnull-conversion" - return activeChild.nextResponder; -#pragma clang diagnostic pop + for (UIView* subview in [self.subviews reverseObjectEnumerator]) { + if (subview.subviews && subview.subviews.count > 0) { + BOOL isRootViewOfController = + [subview.nextResponder isKindOfClass:[UIViewController class]]; + + if (isRootViewOfController && + subview.nextResponder != self.nextResponder) { + return (id)[subview nextResponder]; + } + + return subview; + } } - return activeChild; } return nil; }