Skip to content

Instantly share code, notes, and snippets.

@Dev1an
Created March 7, 2020 00:35
Show Gist options
  • Select an option

  • Save Dev1an/b5a17a0c87e069e95abd7c3fdf7f9033 to your computer and use it in GitHub Desktop.

Select an option

Save Dev1an/b5a17a0c87e069e95abd7c3fdf7f9033 to your computer and use it in GitHub Desktop.
Show a SwiftUI View floating above another View without altering its layout.
import SwiftUI
extension View {
func float<Content: View>(above: Content) -> ModifiedContent<Self, Above<Content>> {
self.modifier(Above(aboveContent: above))
}
}
struct Above<AboveContent: View>: ViewModifier {
let aboveContent: AboveContent
func body(content: Content) -> some View {
content.overlay(
GeometryReader { proxy in
Rectangle().fill(Color.clear).overlay(
self.aboveContent.offset(x: 0, y: -proxy.size.height),
alignment: .bottom
)
},
alignment: .bottom
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment