-
Notifications
You must be signed in to change notification settings - Fork 82
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
Support animating an overlay out after returning a result #1066
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1fa8b00
Support animating an overlay out after returning a result
bryanstern 0d98a87
Formatting
bryanstern e83feec
Simplify using AnimatedContent
bryanstern 6f769e0
Example
bryanstern ad547f9
Clean up
bryanstern 3ac5217
Fix size transform
bryanstern 9bc5622
Remove example
bryanstern ba028ff
clean up
bryanstern d926c1d
Formatting
bryanstern 32b2eb6
Merge branch 'main' into animated_overlays
bryanstern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
// SPDX-License-Identifier: Apache-2.0 | ||
package com.slack.circuit.overlay | ||
|
||
import androidx.compose.animation.AnimatedContent | ||
import androidx.compose.animation.AnimatedVisibilityScope | ||
import androidx.compose.animation.EnterTransition | ||
import androidx.compose.animation.ExitTransition | ||
import androidx.compose.animation.togetherWith | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.ProvidableCompositionLocal | ||
import androidx.compose.runtime.Stable | ||
|
@@ -166,6 +171,30 @@ public interface Overlay<Result : Any> { | |
@Composable public fun Content(navigator: OverlayNavigator<Result>) | ||
} | ||
|
||
/** | ||
* An [Overlay] that can be animated in and more interestingly out _after_ it has returned a | ||
* [Result]. The [Overlay] is animated in and out by its [enterTransition] and [exitTransition], | ||
* [AnimatedContent] is executed with with [AnimatedVisibilityScope] so that child animations can be | ||
* coordinated with the overlay's animations. | ||
*/ | ||
public abstract class AnimatedOverlay<Result : Any>( | ||
public val enterTransition: EnterTransition, | ||
public val exitTransition: ExitTransition, | ||
) : Overlay<Result> { | ||
@Composable | ||
final override fun Content(navigator: OverlayNavigator<Result>) { | ||
AnimatedContent( | ||
targetState = Unit, | ||
transitionSpec = { EnterTransition.None togetherWith ExitTransition.None }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we should be using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh good catch #1090 |
||
) { | ||
AnimatedContent(navigator) | ||
} | ||
} | ||
|
||
@Composable | ||
public abstract fun AnimatedVisibilityScope.AnimatedContent(navigator: OverlayNavigator<Result>) | ||
} | ||
|
||
/** A [ProvidableCompositionLocal] to expose the current [OverlayHost] in the composition tree. */ | ||
public val LocalOverlayHost: ProvidableCompositionLocal<OverlayHost> = compositionLocalOf { | ||
error("No OverlayHost provided") | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should mark this as an experimental API. I can see this API evolving.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though the library itself isn't stable yet anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to you here. I still think we can add signal to what APIs are more stable than others?
I don't mind either way though. If you'd rather keep experimental annotations out of here (understandably), all good with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think we're fine without it for now, most of the library would probably fall under that annotation's umbrella if we introduced it heh