Skip to content

Commit

Permalink
Merge branch 'develop' into blocking-task
Browse files Browse the repository at this point in the history
  • Loading branch information
piercifani authored Jan 16, 2025
2 parents 60b2ac1 + 921d17b commit fd465c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 64 deletions.
4 changes: 0 additions & 4 deletions Sources/BSWInterfaceKit/SwiftUI/LibraryContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@ struct BSWInterfaceKit_SwiftUILibrary: LibraryContentProvider {
}
}

#if swift(>=6.0)
extension LibraryItem: @unchecked @retroactive Sendable {}
#else
extension LibraryItem: @unchecked Sendable {}
#endif
59 changes: 26 additions & 33 deletions Sources/BSWInterfaceKit/SwiftUI/Previews/AsyncView+Preview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,10 @@ import SwiftUI
/// when the ID of the operation changes.
@available(iOS 17, macOS 14, watchOS 9, *)
#Preview {
AsyncContentView()
}

@available(iOS 17, macOS 14, watchOS 9, *)
@MainActor
private struct AsyncContentView: View {

@State var asyncViewID: String = "default-value"

var body: some View {

VStack {
HStack {
Button("Swap1") {
asyncViewID = "swap-1"
}
Button("Swap2") {
asyncViewID = "swap-2"
}
}
Spacer()
AsyncView(
id: $asyncViewID,
dataGenerator: {
try await generateData(forQuery: asyncViewID)
},
hostedViewGenerator: {
ContentView(data: $0)
}
)
.border(Color.red)
}
}
@Previewable
@State
var asyncViewID: String = "default-value"

func generateData(forQuery query: String) async throws -> String {
/// On a real app, this method will call a Web Server to fetch
Expand All @@ -53,7 +24,7 @@ private struct AsyncContentView: View {
case "swap-2":
return "Nam vel nunc ipsum. Nunc in magna sed nisi dapibus feugiat in vel elit"
default:
return AsyncContentView.ContentView.generatePlaceholderData()
return ContentView.generatePlaceholderData()
}
}

Expand All @@ -70,4 +41,26 @@ private struct AsyncContentView: View {
"Morbi ullamcorper interdum ex, non feugiat neque hendrerit eu."
}
}

return VStack {
HStack {
Button("Swap1") {
asyncViewID = "swap-1"
}
Button("Swap2") {
asyncViewID = "swap-2"
}
}
Spacer()
AsyncView(
id: $asyncViewID,
dataGenerator: {
try await generateData(forQuery: asyncViewID)
},
hostedViewGenerator: {
ContentView(data: $0)
}
)
.border(Color.red)
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@

import SwiftUI

@available(iOS 17.0, macOS 13, watchOS 9, *)
struct DemoView: View {
@available(iOS 18.0, macOS 14, watchOS 10, *)
#Preview {

@State var presentSheet = false
@Previewable
@State
var presentSheet = false

var body: some View {
Button("Present Sheet") {
presentSheet = true
}
.intrinsicHeightSheet(isPresented: $presentSheet) {
ContentView()
}
.task {
presentSheet = true
}

Button("Present Sheet") {
presentSheet = true
}

struct ContentView: View {
var body: some View {
VStack {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ac bibendum est. Donec tincidunt ligula sit amet ipsum vehicula vehicula. Vestibulum ultrices arcu sit amet aliquam dictum.")
}
.padding()
}
.intrinsicHeightSheet(isPresented: $presentSheet) {
Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ac bibendum est. Donec tincidunt ligula sit amet ipsum vehicula vehicula. Vestibulum ultrices arcu sit amet aliquam dictum.")
.padding()
}
.task {
presentSheet = true
}
}

@available(iOS 17.0, macOS 13, watchOS 9, *)
#Preview {
DemoView()
}

@available(iOS 16.0, macOS 13, watchOS 9, *)
Expand Down

0 comments on commit fd465c1

Please sign in to comment.