Skip to content

Instantly share code, notes, and snippets.

@SwiftyAlex
Created August 30, 2020 11:29
Show Gist options
  • Save SwiftyAlex/39c121310ba82baa550b9f520ea4ed93 to your computer and use it in GitHub Desktop.
Save SwiftyAlex/39c121310ba82baa550b9f520ea4ed93 to your computer and use it in GitHub Desktop.
SwiftUI Welcome View
//
// WelcomeView.swift
// iOS
//
// Created by Alex Logan on 30/08/2020.
//
import SwiftUI
struct WelcomeView: View {
@Binding var isPresented: Bool
var welcomeItems: [WelcomeItemContent] = [.about, .watch, .health]
@State var showingAlert: Bool = false
var body: some View {
VStack(alignment: .leading, spacing: 12) {
VStack(alignment: .leading, spacing: 0){
Text("Welcome to")
.bold()
.font(.largeTitle)
.fontWeight(.black)
Text("App")
.font(.largeTitle)
.fontWeight(.black)
.foregroundColor(Color.accentColor)
.minimumScaleFactor(0.5)
.lineLimit(1)
}
Text("This app is a cool app to help you do something cool.")
.font(.body)
.fontWeight(.semibold)
.opacity(0.4)
.minimumScaleFactor(0.5)
VStack(alignment: .leading, spacing: 20) {
ForEach(self.welcomeItems, id: \.self) { welcomeItem in
WelcomeItemView(content: welcomeItem)
}
}.padding(.top, 20)
Spacer()
HStack {
Spacer()
Button(action: { closeViaAlert() }, label: {
Text("Continue")
.font(Font.system(size: 16.0, design: .rounded))
.bold()
.foregroundColor(.white)
.minimumScaleFactor(0.8)
.padding()
.frame(minWidth: 0, maxWidth: /*@START_MENU_TOKEN@*/.infinity/*@END_MENU_TOKEN@*/)
.background(RoundedRectangle(cornerRadius: 7.5, style: .circular).foregroundColor(Color.accent))
})
Spacer()
}
}
.onAppear(perform: { } )
.padding(40)
.background(Color("background"))
.edgesIgnoringSafeArea(.bottom)
}
private func authoriseHealthKit() { }
private func closeViaAlert() {
self.showingAlert.toggle()
}
}
struct WelcomeView_Previews: PreviewProvider {
@State static var isPresented: Bool = true
static var previews: some View {
WelcomeView(isPresented: $isPresented)
}
}
struct WelcomeItemContent: Hashable {
var title: String
var subTitle: String
var systemImageName: String? = nil
static var about = WelcomeItemContent(title: "Send", subTitle: "Send a thing to a person who wants a thing.", systemImageName: "paperplane.circle.fill")
static var watch = WelcomeItemContent(title: "Heart stuff", subTitle: "This is just a heart. I like things.", systemImageName: "heart.circle.fill")
static var health = WelcomeItemContent(title: "Another Thing", subTitle: "I guess this would be something to do with bookmarks",systemImageName: "bookmark.circle.fill")
}
struct WelcomeItemView: View {
@State var content: WelcomeItemContent
var body: some View {
HStack(alignment: .top) {
if let imageName = content.systemImageName {
Image(systemName: imageName)
.resizable()
.frame(width: 64, height: 64, alignment: .center)
.foregroundColor(.accent)
}
VStack(alignment: .leading) {
Text(content.title)
.font(.headline)
Text(content.subTitle)
.font(.body)
.minimumScaleFactor(0.8)
.lineLimit(2)
}
}
.frame(height: 66)
.clipped()
}
}
struct WelcomeItemView_Previews: PreviewProvider {
static var previews: some View {
WelcomeItemView(
content: WelcomeItemContent.about
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment