Last active
February 20, 2020 17:33
-
-
Save angelinaFri/550b39dda76ebd12263612da5b02e74b to your computer and use it in GitHub Desktop.
SwiftUI navigation
This file contains 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 | |
struct MainView: View { | |
@State var isPresent = true | |
@State var showFullScreen = false | |
@State var showModal = false | |
var body: some View { | |
ZStack { | |
if !showFullScreen { | |
BlueScreen(showFullScreen: self.$showFullScreen, showModal: self.$showModal) | |
} else { | |
FullScreen(showFullScreen: self.$showFullScreen) | |
} | |
} | |
} | |
} | |
struct SoundSheet : View { | |
@Binding var showCallSreen: Bool | |
@Environment(\.presentationMode) var presentationMode | |
let dg = DragGesture() | |
var body: some View { | |
ZStack { | |
Rectangle() | |
.fill(Color.yellow) | |
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height) | |
.highPriorityGesture(dg) | |
VStack { | |
Button("Dismiss YellowScreen") { | |
self.presentationMode.wrappedValue.dismiss() | |
} | |
Button("Show FullScreenView") { | |
self.showCallSreen.toggle() | |
} | |
} | |
} | |
} | |
} | |
struct FullScreen: View { | |
@Binding var showFullScreen: Bool | |
var body: some View { | |
VStack { | |
Rectangle() | |
.fill(Color.red) | |
.frame(width: 400, height: 400) | |
VStack { | |
Button(action: { | |
withAnimation(.linear) { | |
self.showFullScreen.toggle() | |
} | |
}) { | |
Text("Back to Blue Screen") | |
} | |
} | |
} | |
} | |
} | |
struct BlueScreen: View { | |
@Binding var showFullScreen: Bool | |
@Binding var showModal: Bool | |
var body: some View { | |
VStack { | |
Button(action: { | |
self.showModal.toggle() | |
}) { | |
Text("Show Yellow screen") | |
} | |
Rectangle() | |
.fill(Color.blue) | |
.frame(width: 400, height: 400) | |
.sheet(isPresented: self.$showModal) { | |
SoundSheet(showCallSreen: self.$showFullScreen) | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment