wip
This commit is contained in:
parent
c87bb0e45f
commit
8a7af525a9
|
@ -35,12 +35,12 @@ extension View {
|
||||||
selector: { (view: PlatformView) in
|
selector: { (view: PlatformView) in
|
||||||
switch scope ?? defaultScope {
|
switch scope ?? defaultScope {
|
||||||
case .receiver:
|
case .receiver:
|
||||||
return view.findReceiver(ofType: PlatformSpecificView.self)
|
return view.receiver(ofType: PlatformSpecificView.self)
|
||||||
case .ancestor:
|
case .ancestor:
|
||||||
return view.findAncestor(ofType: PlatformSpecificView.self)
|
return view.ancestor(ofType: PlatformSpecificView.self)
|
||||||
case .receiverOrAncestor:
|
case .receiverOrAncestor:
|
||||||
return view.findReceiver(ofType: PlatformSpecificView.self)
|
return view.receiver(ofType: PlatformSpecificView.self)
|
||||||
?? view.findAncestor(ofType: PlatformSpecificView.self)
|
?? view.ancestor(ofType: PlatformSpecificView.self)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
customize: customize
|
customize: customize
|
||||||
|
@ -65,7 +65,7 @@ extension PlatformView {
|
||||||
AnySequence(sequence(first: self, next: \.superview).dropFirst())
|
AnySequence(sequence(first: self, next: \.superview).dropFirst())
|
||||||
}
|
}
|
||||||
|
|
||||||
func findReceiver<PlatformSpecificView: PlatformView>(
|
func receiver<PlatformSpecificView: PlatformView>(
|
||||||
ofType type: PlatformSpecificView.Type
|
ofType type: PlatformSpecificView.Type
|
||||||
) -> PlatformSpecificView? {
|
) -> PlatformSpecificView? {
|
||||||
guard let hostingView = self.hostingView else {
|
guard let hostingView = self.hostingView else {
|
||||||
|
@ -73,7 +73,7 @@ extension PlatformView {
|
||||||
}
|
}
|
||||||
|
|
||||||
// for container in superviews {
|
// for container in superviews {
|
||||||
let children = hostingView.recursivelyFindSubviews(ofType: PlatformSpecificView.self)
|
let children = hostingView.allSubviews(ofType: PlatformSpecificView.self)
|
||||||
|
|
||||||
for child in children {
|
for child in children {
|
||||||
guard
|
guard
|
||||||
|
@ -93,17 +93,17 @@ extension PlatformView {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recursivelyFindSubviews<PlatformSpecificView: PlatformView>(
|
func allSubviews<PlatformSpecificView: PlatformView>(
|
||||||
ofType type: PlatformSpecificView.Type
|
ofType type: PlatformSpecificView.Type
|
||||||
) -> [PlatformSpecificView] {
|
) -> [PlatformSpecificView] {
|
||||||
var result = self.subviews.compactMap { $0 as? PlatformSpecificView }
|
var result = self.subviews.compactMap { $0 as? PlatformSpecificView }
|
||||||
for subview in self.subviews {
|
for subview in self.subviews {
|
||||||
result.append(contentsOf: subview.recursivelyFindSubviews(ofType: type))
|
result.append(contentsOf: subview.allSubviews(ofType: type))
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func findAncestor<PlatformSpecificView: PlatformView>(
|
func ancestor<PlatformSpecificView: PlatformView>(
|
||||||
ofType type: PlatformSpecificView.Type
|
ofType type: PlatformSpecificView.Type
|
||||||
) -> PlatformSpecificView? {
|
) -> PlatformSpecificView? {
|
||||||
self.superviews.lazy.compactMap { $0 as? PlatformSpecificView }.first
|
self.superviews.lazy.compactMap { $0 as? PlatformSpecificView }.first
|
||||||
|
|
Loading…
Reference in New Issue