Skip to content

Commit

Permalink
SwiftUI: example for bottom sheet.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-lyn committed Dec 11, 2021
1 parent 65388ab commit 8c5e7c1
Showing 1 changed file with 59 additions and 22 deletions.
81 changes: 59 additions & 22 deletions STPopupSwiftUIExample/STPopupSwiftUIExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,74 @@ import SwiftUI
import STPopup

struct ContentView: View {
@State private var isPresentingPopup = false
@State private var isPresentingFormSheetPopup = false
@State private var isPresentingBottomSheetPopup = false
@State private var showsAdditionalMessage = false

var body: some View {
Button("Show Popup") {
isPresentingPopup = true
}
.padding()
.popup(isPresented: $isPresentingPopup) {
VStack(spacing: 10) {
Image(systemName: "location")
.font(.system(.largeTitle))
Text("Location Service")
if showsAdditionalMessage {
Text("Tap to dismiss")
NavigationView {
List {
Button("Show Popup(style = .formSheet)") {
isPresentingFormSheetPopup = true
}
Button("Show Popup(style = .bottomSheet)") {
isPresentingBottomSheetPopup = true
}
}
.listStyle(.plain)
.popup(isPresented: $isPresentingFormSheetPopup) {
popupContent {
isPresentingFormSheetPopup = false
}
.padding(.leading)
.padding(.trailing)
.background(Color.white)
.cornerRadius(10)
}
.popup(isPresented: $isPresentingBottomSheetPopup, style: .bottomSheet) {
VStack {
HStack {
Spacer()
}
popupContent {
isPresentingBottomSheetPopup = false
}
}
Button("Enable") {
isPresentingPopup = false
.background(
VStack {
HStack {
Spacer()
}
Spacer()
}
.background(Color.white)
.cornerRadius(10)
.padding(.leading)
.padding(.trailing)
)
}
.navigationTitle("STPopup+SwiftUI")
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
showsAdditionalMessage = true
}
}
.padding()
.padding(.leading)
.padding(.trailing)
.background(Color(.white))
.cornerRadius(10)
}
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
showsAdditionalMessage = true
}

private func popupContent(action: @escaping () -> Void) -> some View {
VStack(spacing: 10) {
Image(systemName: "location")
.font(.system(.largeTitle))
Text("Location Service")
if showsAdditionalMessage {
Text("Tap to dismiss")
}
Button("Enable") {
action()
}
}
.padding()
}
}

Expand Down

0 comments on commit 8c5e7c1

Please sign in to comment.