1

I'm trying to override the functionality of edgesIgnoringSafeArea(_:) since I have custom handling for the vertical safe area in my view. However, there's no super to call so I'm not sure how to proceed other then handling every safe area edge. Any advice would be appreciated.

// Will use later for custom handling of vertical safe area
@State private var edgesThatIgnoreSafeArea: Edge.Set = []

func edgesIgnoringSafeArea(_ edges: Edge.Set) -> some View {
    edgesThatIgnoreSafeArea = edges

    // There is no super here to call, and calling self would just call this function again
    return AnyView(edgesIgnoringSafeArea(edges.subtracting(.vertical)))  
}
robhasacamera
  • 2,197
  • 1
  • 22
  • 36

2 Answers2

1

We cannot override modifiers, but we can add our own which use standard, like

extension View {
    func edgesIgnoringHorizontal(_ edges: Edge.Set) -> some View {
         self.edgesIgnoringSafeArea(edges.subtracting(.vertical))
    }
}

Note: although I don't see much sense in such overriding, because just using of .edgesIgnoringSafeArea(.horizontal) is simpler and more obvious and readable... but anyway.

Asperi
  • 123,447
  • 8
  • 131
  • 245
0

Figured out how to do this. I wrapped my view with AnyView and applied the selective safe area to it.

@State private var edgesThatIgnoreSafeArea: Edge.Set = []

func edgesIgnoringSafeArea(_ edges: Edge.Set) -> some View {
    edgesThatIgnoreSafeArea = edges

    return AnyView(self).edgesIgnoringSafeArea(edges.subtracting(.vertical))
}
robhasacamera
  • 2,197
  • 1
  • 22
  • 36