Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions Demo/AutoResizingSheetDemo/AutoResizingSheetDemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import AutoResizingSheet

@main
struct AutoResizingSheetDemoApp: App {
@State private var configuration = AutoResizingSheetConfiguration()

var body: some Scene {
WindowGroup {
TabView {
SwiftUIExampleView(configuration: configuration)
.tabItem {
Label("SwiftUI", systemImage: "square.stack")
}

UIKitExampleViewRepresentable(configuration: configuration)
.tabItem {
Label("UIKit", systemImage: "poweroutlet.type.a")
}

ConfigurationSettingsView(configuration: $configuration)
.tabItem {
Label("Config", systemImage: "gear")
}
}
}
@State private var configuration = AutoResizingSheetConfiguration()

var body: some Scene {
WindowGroup {
TabView {
SwiftUIExampleView(configuration: configuration)
.tabItem {
Label("SwiftUI", systemImage: "square.stack")
}

UIKitExampleViewRepresentable(configuration: configuration)
.tabItem {
Label("UIKit", systemImage: "poweroutlet.type.a")
}

ConfigurationSettingsView(configuration: $configuration)
.tabItem {
Label("Config", systemImage: "gear")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
import SwiftUI

struct AsyncSheetContentView: View {
@State private var downloadedImage: UIImage?

var body: some View {
VStack(spacing: 15) {
Text("Lorem ipsum dolor sit amet")
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)

if let downloadedImage {
Image(uiImage: downloadedImage)
.resizable()
.scaledToFit()
.frame(width: 100)
.fixedSize(horizontal: false, vertical: true)
} else {
ProgressView()
.frame(maxWidth: .infinity, alignment: .center)
}

Text("⬆️ You can resize the sheet to full size using the grabber")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("📜 By default the sheets content is scrollable")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("🛜 The sheet simulates a async sheet where the content changes it's size after data is loaded")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)

Button {
Task {
downloadedImage = nil
downloadedImage = await downloadExampleImage()
}
} label: {
Text("Reload image")
}
}
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
.onAppear {
Task {
downloadedImage = await downloadExampleImage()
}
@State private var downloadedImage: UIImage?

var body: some View {
VStack(spacing: 15) {
Text("Lorem ipsum dolor sit amet")
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)

if let downloadedImage {
Image(uiImage: downloadedImage)
.resizable()
.scaledToFit()
.frame(width: 100)
.fixedSize(horizontal: false, vertical: true)
} else {
ProgressView()
.frame(maxWidth: .infinity, alignment: .center)
}

Text("⬆️ You can resize the sheet to full size using the grabber")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("📜 By default the sheets content is scrollable")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("🛜 The sheet simulates a async sheet where the content changes it's size after data is loaded")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)

Button {
Task {
downloadedImage = nil
downloadedImage = await downloadExampleImage()
}
} label: {
Text("Reload image")
}
}

// Example function for downloading an image
private func downloadExampleImage() async -> UIImage? {
let urlString = "https://picsum.photos/1000/1200"
guard let url = URL(string: urlString),
let (data, _) = try? await URLSession.shared.data(from: url),
let image = UIImage(data: data)
else { return nil }

return image
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
.onAppear {
Task {
downloadedImage = await downloadExampleImage()
}
}
}

// Example function for downloading an image
private func downloadExampleImage() async -> UIImage? {
let urlString = "https://picsum.photos/1000/1200"
guard let url = URL(string: urlString),
let (data, _) = try? await URLSession.shared.data(from: url),
let image = UIImage(data: data)
else { return nil }

return image
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import AutoResizingSheet
import SwiftUI

struct ConfigurationSettingsView: View {
@Binding var configuration: AutoResizingSheetConfiguration

var body: some View {
VStack(spacing: 15) {
Toggle("scrollable", isOn: $configuration.scrollable)

Toggle("showGrabber", isOn: $configuration.showGrabber)

Toggle("extendableToFullSize", isOn: $configuration.extendableToFullSize)

Spacer()
}
.padding(20)
@Binding var configuration: AutoResizingSheetConfiguration

var body: some View {
VStack(spacing: 15) {
Toggle("scrollable", isOn: $configuration.scrollable)

Toggle("showGrabber", isOn: $configuration.showGrabber)

Toggle("extendableToFullSize", isOn: $configuration.extendableToFullSize)

Spacer()
}
.padding(20)
}
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
import SwiftUI

struct DynamicSheetContentView: View {
@State private var text: String
private let textToAppend = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
private let defaultText = """
@State private var text: String
private let textToAppend = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
private let defaultText = """
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam \
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, \
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. \
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam \
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
"""

init() {
_text = State(initialValue: defaultText)
}

var body: some View {
VStack(spacing: 15) {
Text("Lorem ipsum dolor sit amet")
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)

Text(text)
.font(.caption)
.fixedSize(horizontal: false, vertical: true)

Text("⬆️ You can resize the sheet to full size using the grabber")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("📜 By default the sheets content is scrollable")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("↕️ Test the resizing by appending text or resetting it back to default")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)

HStack {
Button {
text = defaultText
} label: {
Text("Reset text")
}

Spacer()

Button {
text += textToAppend
} label: {
Text("Append text")
}
}

init() {
_text = State(initialValue: defaultText)
}

var body: some View {
VStack(spacing: 15) {
Text("Lorem ipsum dolor sit amet")
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)

Text(text)
.font(.caption)
.fixedSize(horizontal: false, vertical: true)

Text("⬆️ You can resize the sheet to full size using the grabber")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("📜 By default the sheets content is scrollable")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("↕️ Test the resizing by appending text or resetting it back to default")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)

HStack {
Button {
text = defaultText
} label: {
Text("Reset text")
}

Spacer()

Button {
text += textToAppend
} label: {
Text("Append text")
}
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
}
}
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
import SwiftUI

struct StaticSheetContentView: View {
@Environment(\.dismiss) private var dismiss
var body: some View {
VStack(spacing: 15) {
Text("Lorem ipsum dolor sit amet")
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)
Text("""
@Environment(\.dismiss) private var dismiss

var body: some View {
VStack(spacing: 15) {
Text("Lorem ipsum dolor sit amet")
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)

Text("""
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam \
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, \
sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. \
Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam \
nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
""")
.font(.caption)
.fixedSize(horizontal: false, vertical: true)

Text("⬆️ You can resize the sheet to full size using the grabber")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("📜 By default the sheets content is scrollable")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("❌ The sheet can be closed via the button or by swiping it down / touching the outside area")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)

Button {
dismiss()
} label: {
Image(systemName: "xmark")
Text("Close sheet")
}
.frame(maxWidth: .infinity, alignment: .center)
}
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
.font(.caption)
.fixedSize(horizontal: false, vertical: true)

Text("⬆️ You can resize the sheet to full size using the grabber")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("📜 By default the sheets content is scrollable")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)

Text("❌ The sheet can be closed via the button or by swiping it down / touching the outside area")
.font(.caption)
.frame(maxWidth: .infinity, alignment: .leading)
.fixedSize(horizontal: false, vertical: true)

Button {
dismiss()
} label: {
Image(systemName: "xmark")
Text("Close sheet")
}
.frame(maxWidth: .infinity, alignment: .center)
}
.padding(EdgeInsets(top: 20, leading: 20, bottom: 10, trailing: 20))
}
}
Loading
Loading