|
// |
|
// ContentView.swift |
|
// navigation |
|
// |
|
// Created by Thomas Ricouard on 13/10/2019. |
|
// Copyright © 2019 Thomas Ricouard. All rights reserved. |
|
// |
|
|
|
import SwiftUI |
|
|
|
struct RootView: View { |
|
@State private var isHomeShown = true |
|
@State private var isSettingShown = false |
|
@State private var selectedContent = "content1" |
|
|
|
var body: some View { |
|
ZStack { |
|
ContentView(content: $selectedContent, |
|
isHomeShown: $isHomeShown, |
|
isSettingShown: $isSettingShown) |
|
.blur(radius: isHomeShown ? 10 : 0) |
|
.scaleEffect(isHomeShown ? 0.8 : 1) |
|
.animation(.spring()) |
|
if isHomeShown { |
|
HomeView(selectedContent: $selectedContent, |
|
isHomeShown: $isHomeShown) |
|
.transition(.scale) |
|
.animation(.spring()) |
|
} |
|
if isSettingShown { |
|
SettingsView(isShown: $isSettingShown) |
|
.transition(.slide) |
|
.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 |
|
@Binding var isSettingShown: Bool |
|
|
|
var body: some View { |
|
GeometryReader { _ in |
|
VStack { |
|
Text(self.content) |
|
Button(action: { |
|
self.isHomeShown = true |
|
}, label: { |
|
Text("Back").foregroundColor(.blue) |
|
}) |
|
Spacer() |
|
Button(action: { |
|
self.isSettingShown = true |
|
}, label: { |
|
Text("Settings").foregroundColor(.blue) |
|
}) |
|
.padding() |
|
} |
|
} |
|
.background(Color.yellow) |
|
.frame(width: 300, height: 300) |
|
} |
|
} |
|
|
|
struct SettingsView: View { |
|
@Binding var isShown: Bool |
|
|
|
var body: some View { |
|
ZStack { |
|
RoundedRectangle(cornerRadius: 20) |
|
.fill(Color.white) |
|
.shadow(radius: 10) |
|
VStack { |
|
Text("Setting 1") |
|
Text("Setting 2") |
|
Button(action: { |
|
self.isShown = false |
|
}, label: { |
|
Text("Close").foregroundColor(.blue) |
|
}) |
|
} |
|
.padding() |
|
} |
|
.frame(width: 250, height: 250) |
|
} |
|
} |
|
|
|
struct RootView_Previews: PreviewProvider { |
|
static var previews: some View { |
|
RootView() |
|
} |
|
} |