From 794d2f282f007f580fdc1ef0d6687cf4b8cb345c Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Mon, 4 May 2020 09:50:11 -0700 Subject: [PATCH] Solved the bug related to the toggle inspector of iOS Summary: Before this diff the nodes were not invalidated properly when the new view got added in the hierarchy, due to this there was following bug. https://our.intern.facebook.com/intern/px/p/15RSP Reviewed By: Andrey-Mishanin Differential Revision: D21285438 fbshipit-source-id: b72aa93856688b31296ae1df4f15e128037aa1ca --- .../FlipperKitLayoutPlugin.mm | 4 ++++ .../FlipperKitLayoutPlugin/SKInvalidation.h | 2 +- .../UIView+SKInvalidation.mm | 19 +++++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.mm b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.mm index 34c3b8f0e..2ef733b97 100644 --- a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.mm +++ b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.mm @@ -371,6 +371,10 @@ }); } +- (void)invalidateRootNode { + [self invalidateNode:_rootNode]; +} + - (void)_reportInvalidatedObjects { NSMutableArray* nodes = [NSMutableArray new]; { // scope mutex acquisition diff --git a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/SKInvalidation.h b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/SKInvalidation.h index 9b26d599e..f2eee5819 100644 --- a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/SKInvalidation.h +++ b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/SKInvalidation.h @@ -10,7 +10,7 @@ @protocol SKInvalidationDelegate - (void)invalidateNode:(id)node; - +- (void)invalidateRootNode; - (void)updateNodeReference:(id)node; @end diff --git a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/UIView+SKInvalidation.mm b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/UIView+SKInvalidation.mm index 3da4f961b..10058261c 100644 --- a/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/UIView+SKInvalidation.mm +++ b/iOS/Plugins/FlipperKitLayoutPlugin/FlipperKitLayoutPlugin/UIView+SKInvalidation.mm @@ -9,7 +9,6 @@ #import #import - #import "SKInvalidation.h" #import "SKSwizzle.h" #import "UIView+SKInvalidation.h" @@ -31,6 +30,14 @@ FB_LINKABLE(UIView_SKInvalidation) }); } +/** +This function takes in a view and returns true if the view is a UIWindow and its +windowLevel is an alert one otherwise it returns false. +*/ +static auto shouldInvalidateRootNode(UIView* view) -> bool { + return [view isKindOfClass:[UIWindow class]]; +} + - (void)swizzle_setHidden:(BOOL)hidden { [self swizzle_setHidden:hidden]; @@ -47,7 +54,11 @@ FB_LINKABLE(UIView_SKInvalidation) id delegate = [SKInvalidation sharedInstance].delegate; if (delegate != nil) { - [delegate invalidateNode:view]; + if (shouldInvalidateRootNode(view.superview)) { + [delegate invalidateRootNode]; + return; + } + [delegate invalidateNode:view.superview]; } } @@ -55,6 +66,10 @@ FB_LINKABLE(UIView_SKInvalidation) id delegate = [SKInvalidation sharedInstance].delegate; if (delegate != nil && self.superview != nil) { + if (shouldInvalidateRootNode(self.superview)) { + [delegate invalidateRootNode]; + return; + } [delegate invalidateNode:self.superview]; }