Skip to content

Add support for SwiftUI withTransaction API #1824

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

Merged
merged 6 commits into from
Jan 18, 2023
Merged

Add support for SwiftUI withTransaction API #1824

merged 6 commits into from
Jan 18, 2023

Conversation

drucelweisse
Copy link
Contributor

@drucelweisse drucelweisse commented Jan 11, 2023

This adds EffectPublisher support to perform block with SwiftUI Transaction. As all animation stuff happens using Transaction, and Animation is a concrete example of Transaction it seems reasonable to support that, even if it has few use cases.

Changes: Instead of creating another function, I generalized it for transactions and in .animation(_ animation: Animation? = .default) function calls it under the hood.

Example from SwiftUI Q&A Sessions

Is there way to show .fullScreenCover without animation? I don't want to user see animated cover show from bottom to top. because it still see underline view in a short time.

You can create a Transaction value, set its disablesAnimations property to true, then set the binding that presents the fullScreenCover inside a withTransaction block. Something like:

var t = Transaction()
t.disablesAnimations = true
withTransaction(t) {
    isCoverPresented = true
}

@mbrandonw
Copy link
Member

Hey @drucelweisse, thanks for the PR!

Overall we think this is a pretty good change. We need a little more time to be able to fully look over the code, but one thing that popped out to us was that maybe even Effect's Send type should take a transaction so that you can do things like:

Effect.run { send in 
  await send(.response, transaction: disableAnimations)
}

Further, even ViewStore.send could take a transaction too. Want to experiment with adding those too and we'll come back to this soon?

@drucelweisse
Copy link
Contributor Author

drucelweisse commented Jan 12, 2023

Hi @mbrandonw! I've definitely missed out that Send also has an Animation overload. Will add that into pr.

@mbrandonw mbrandonw merged commit b4e6e83 into pointfreeco:main Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants