diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 4e976231..66d0fe12 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -13,4 +13,4 @@ jobs: with: lfs: true - name: Test BSWInterfaceKit - run: set -o pipefail && xcodebuild -scheme BSWInterfaceKit -destination "platform=iOS Simulator,name=iPhone 15,OS=17.2" -resultBundlePath TestResults.xcresult test | xcbeautify + run: set -o pipefail && xcodebuild -scheme BSWInterfaceKit -destination "platform=iOS Simulator,name=iPhone 15,OS=17.5" -resultBundlePath TestResults.xcresult test | xcbeautify diff --git a/Sources/BSWInterfaceKit/SwiftUI/Views/AsyncButton.swift b/Sources/BSWInterfaceKit/SwiftUI/Views/AsyncButton.swift index 0ea3f1d9..5b54f6cf 100644 --- a/Sources/BSWInterfaceKit/SwiftUI/Views/AsyncButton.swift +++ b/Sources/BSWInterfaceKit/SwiftUI/Views/AsyncButton.swift @@ -28,21 +28,28 @@ public struct AsyncButton: View { public var body: some View { Button( action: { - Task { - await performAction() + if #available(iOS 17.0, *) { + withAnimation { + self.state = .loading + } completion: { + Task { + await performAction() + } + } + } else { + Task { + await performAction(forIOS16: true) + } } }, label: { - if loadingConfiguration.isBlocking { - label - } else { - label - .opacity(state == .loading ? 0 : 1) - .overlay { + label + .opacity(state == .loading ? 0 : 1) + .overlay { + if loadingConfiguration.isBlocking == false, state == .loading { loadingView - .opacity(state == .loading ? 1 : 0) } - } + } } ) .disabled((state == .loading) || (error != nil)) @@ -50,14 +57,16 @@ public struct AsyncButton: View { } @MainActor - private func performAction() async { + private func performAction(forIOS16: Bool = false) async { var hudVC: UIViewController? if loadingConfiguration.isBlocking { hudVC = await presentHUDViewController() } - withAnimation { - self.state = .loading + if forIOS16 { + withAnimation { + self.state = .loading + } } let result = await Swift.Result(catching: {