Skip to content

Instantly share code, notes, and snippets.

@Dimillian
Created October 13, 2019 10:49
Show Gist options
  • Save Dimillian/8dfd0a19922f62bca9d0b1aa63d42e2e to your computer and use it in GitHub Desktop.
Save Dimillian/8dfd0a19922f62bca9d0b1aa63d42e2e to your computer and use it in GitHub Desktop.
struct RootView: View {
@State private var isHomeShown = true
@State private var selectedContent = "content1"
var body: some View {
ZStack {
ContentView(content: $selectedContent,
isHomeShown: $isHomeShown)
.blur(radius: isHomeShown ? 10 : 0)
.scaleEffect(isHomeShown ? 0.8 : 1)
.animation(.spring())
if isHomeShown {
HomeView(selectedContent: $selectedContent,
isHomeShown: $isHomeShown)
.transition(.scale)
.animation(.spring())
}
}
}
}
struct HomeView: View {
let contents = ["content1", "content2", "content3", "content4"]
@Binding var selectedContent: String
@Binding var isHomeShown: Bool
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 16) {
ForEach(contents, id: \.self) { content in
Rectangle()
.foregroundColor(.blue)
.frame(width: 100, height: 150)
.onTapGesture {
self.selectedContent = content
self.isHomeShown = false
}
}
}.padding()
}
}
}
struct ContentView: View {
@Binding var content: String
@Binding var isHomeShown: Bool
var body: some View {
GeometryReader { _ in
VStack {
Text(self.content)
Button(action: {
self.isHomeShown = true
}, label: {
Text("Back").foregroundColor(.blue)
})
}
}
.background(Color.yellow)
.frame(width: 300, height: 300)
}
}
struct RootView_Previews: PreviewProvider {
static var previews: some View {
RootView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment