From 8a7af525a9f1e94f2b51ceb58e45b3a28a6dc2f7 Mon Sep 17 00:00:00 2001 From: David Roman <2538074+davdroman@users.noreply.github.com> Date: Mon, 22 May 2023 19:36:44 +0100 Subject: [PATCH] wip --- Sources/Introspect.swift | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Sources/Introspect.swift b/Sources/Introspect.swift index 57543cb..e01b165 100644 --- a/Sources/Introspect.swift +++ b/Sources/Introspect.swift @@ -35,12 +35,12 @@ extension View { selector: { (view: PlatformView) in switch scope ?? defaultScope { case .receiver: - return view.findReceiver(ofType: PlatformSpecificView.self) + return view.receiver(ofType: PlatformSpecificView.self) case .ancestor: - return view.findAncestor(ofType: PlatformSpecificView.self) + return view.ancestor(ofType: PlatformSpecificView.self) case .receiverOrAncestor: - return view.findReceiver(ofType: PlatformSpecificView.self) - ?? view.findAncestor(ofType: PlatformSpecificView.self) + return view.receiver(ofType: PlatformSpecificView.self) + ?? view.ancestor(ofType: PlatformSpecificView.self) } }, customize: customize @@ -65,7 +65,7 @@ extension PlatformView { AnySequence(sequence(first: self, next: \.superview).dropFirst()) } - func findReceiver( + func receiver( ofType type: PlatformSpecificView.Type ) -> PlatformSpecificView? { guard let hostingView = self.hostingView else { @@ -73,7 +73,7 @@ extension PlatformView { } // for container in superviews { - let children = hostingView.recursivelyFindSubviews(ofType: PlatformSpecificView.self) + let children = hostingView.allSubviews(ofType: PlatformSpecificView.self) for child in children { guard @@ -93,17 +93,17 @@ extension PlatformView { return nil } - func recursivelyFindSubviews( + func allSubviews( ofType type: PlatformSpecificView.Type ) -> [PlatformSpecificView] { var result = self.subviews.compactMap { $0 as? PlatformSpecificView } for subview in self.subviews { - result.append(contentsOf: subview.recursivelyFindSubviews(ofType: type)) + result.append(contentsOf: subview.allSubviews(ofType: type)) } return result } - func findAncestor( + func ancestor( ofType type: PlatformSpecificView.Type ) -> PlatformSpecificView? { self.superviews.lazy.compactMap { $0 as? PlatformSpecificView }.first