Skip to content

Commit

Permalink
Prevent UILabel from becoming active child
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Luke De Feo authored and facebook-github-bot committed May 7, 2024
1 parent 958638c commit 345a4df
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSObject>)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<NSObject>)[subview nextResponder];
}

return subview;
}
}
return activeChild;
}
return nil;
}
Expand Down

0 comments on commit 345a4df

Please sign in to comment.