Skip to content

Instantly share code, notes, and snippets.

@shaundon
Created June 20, 2020 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaundon/47b818b1c7c7f78cba1aa9b877b1f958 to your computer and use it in GitHub Desktop.
Save shaundon/47b818b1c7c7f78cba1aa9b877b1f958 to your computer and use it in GitHub Desktop.
//
// PageSlide.swift
// personal-best
//
// Created by Shaun Donnelly on 20/06/2020.
// Copyright © 2020 Shaun Donnelly. All rights reserved.
//
import SwiftUI
struct PageSlideControl: View {
struct PageSlideButtonStyle: ViewModifier {
func body(content: Content) -> some View {
return content
.padding()
.foregroundColor(.white)
.background(Color.blue)
}
}
@Binding var selectedPageIndex: Int
let titleOne: String
let titleTwo: String
var body: some View {
HStack(spacing: 0) {
Button(action: {
withAnimation {
self.selectedPageIndex = 0
}
}) {
Text(titleOne).bold()
}.modifier(PageSlideButtonStyle())
Button(action: {
withAnimation {
self.selectedPageIndex = 1
}
}) {
Text(titleTwo).bold()
}.modifier(PageSlideButtonStyle())
}
.cornerRadius(25.0)
.shadow(radius: 5.0)
}
}
struct PageSlide<FirstPage: View, SecondPage: View>: View {
let firstPage: FirstPage
let firstPageTitle: String
let secondPage: SecondPage
let secondPageTitle: String
@State var selectedPageIndex = 0
init(
@ViewBuilder firstPage: () -> FirstPage,
firstPageTitle: String,
@ViewBuilder secondPage: () -> SecondPage,
secondPageTitle: String
) {
self.firstPage = firstPage()
self.firstPageTitle = firstPageTitle
self.secondPage = secondPage()
self.secondPageTitle = secondPageTitle
}
var body: some View {
ZStack(alignment: .bottom) {
if selectedPageIndex == 0 {
firstPage.transition(AnyTransition.slide.animation(.easeInOut))
} else {
secondPage.transition(AnyTransition.slide.animation(.easeInOut))
}
PageSlideControl(
selectedPageIndex: $selectedPageIndex,
titleOne: firstPageTitle,
titleTwo: secondPageTitle
)
}
}
}
struct PageSlide_Previews: PreviewProvider {
static var previews: some View {
PageSlide(
firstPage: {
List {
Text("One")
Text("Two")
Text("Three")
}
},
firstPageTitle: "Workouts",
secondPage: {
List {
Text("Four")
Text("Five")
Text("Six")
}
},
secondPageTitle: "Stats"
)
}
}
@shaundon
Copy link
Author

This is unfinished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment