Created
March 7, 2020 00:35
-
-
Save Dev1an/b5a17a0c87e069e95abd7c3fdf7f9033 to your computer and use it in GitHub Desktop.
Show a SwiftUI View floating above another View without altering its layout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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