Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithAnimation Compilation Error #1387

Closed
2 tasks done
barksten opened this issue Sep 15, 2022 · 1 comment
Closed
2 tasks done

WithAnimation Compilation Error #1387

barksten opened this issue Sep 15, 2022 · 1 comment
Labels
apple bug Something isn't working due to a bug on Apple's platforms.

Comments

@barksten
Copy link

Description

Compiler error Conflicting arguments to generic parameter 'Result' ('Void' vs. 'ViewStoreTask') when using withAnimation block.

Checklist

  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue.

Expected behavior

The code should compile

Actual behavior

Compiler error Conflicting arguments to generic parameter 'Result' ('Void' vs. 'ViewStoreTask') when using withAnimation block.

Workaround is to get result from send as:

_ = viewStore.send(.buttonTapped)

Steps to reproduce

import ComposableArchitecture
import SwiftUI

struct AppState: Equatable {}
enum AppAction {
    case buttonTapped
}
struct AppEnvironment {}

let reducer = Reducer<AppState, AppAction, AppEnvironment> { _, _, _ in return .none }

struct SwiftUIView: View {
    let store: Store<AppState, AppAction> = Store(initialState: .init(), reducer: reducer, environment: .init())
    var body: some View {
        WithViewStore(self.store, observe: { $0 }) { viewStore in
            Button("Test") {
                withAnimation {
                    viewStore.send(.buttonTapped)
                }
            }
        }
    }
}

struct SwiftUIView_Previews: PreviewProvider {
    static var previews: some View {
        SwiftUIView()
    }
}

The Composable Architecture version information

works with versions up to 0.38. Errors from 0.39 and up to main

Destination operating system

verified with iOS 15 and above

Xcode version information

Version 14.0 (14A309)

Swift Compiler version information

swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
Target: arm64-apple-macosx12.0
@barksten barksten added the bug Something isn't working due to a bug in the library. label Sep 15, 2022
@stephencelis stephencelis added apple bug Something isn't working due to a bug on Apple's platforms. and removed bug Something isn't working due to a bug in the library. labels Sep 15, 2022
@stephencelis
Copy link
Member

@barksten This API change was for Swift concurrency, but is related to Swift's inability to ignore unused variables through continuations:

swiftlang/swift#57477

So this is a general error you will come across with using continuation-style functions like withAnimation.

The fix is to explicitly ignore the result:

-withAnimation {
+_ = withAnimation {
   viewStore.send(.buttonTapped)
 }

Or:

 withAnimation {
-  viewStore.send(.buttonTapped)
+  _ = viewStore.send(.buttonTapped)
 }

Or better yet, use the animation parameter of ViewStore.send, to flatten things:

-withAnimation {
-  viewStore.send(.buttonTapped)
-}
+viewStore.send(.buttonTapped, animation: .default)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apple bug Something isn't working due to a bug on Apple's platforms.
Projects
None yet
Development

No branches or pull requests

2 participants