Created
October 13, 2019 10:49
-
-
Save Dimillian/8dfd0a19922f62bca9d0b1aa63d42e2e to your computer and use it in GitHub Desktop.
Revisions
-
Dimillian created this gist
Oct 13, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ 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() } }