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

Fixed the predictive back gesture interrupted with the new animation API #760

Merged
merged 1 commit into from
Aug 18, 2024

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Aug 15, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a utility function to execute multiple coroutine jobs concurrently, improving asynchronous operations.
    • Added a property to easily access the count of active items in the ChildStack.
    • New class for managing animation states during back navigation, enhancing animation handling.
    • Utility functions added for improved testing capabilities within the Compose framework.
  • Bug Fixes

    • Enhanced validation of UI components through new assertions in testing.
  • Tests

    • Comprehensive unit tests implemented for validating predictive back gestures in the composable UI context.

Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

The recent updates enhance the com.arkivanov.decompose.extensions.compose.experimental package by introducing a new coroutine utility, restructuring animation handling with the AnimationHandler class, and improving testing capabilities through enhanced assertion functions. These changes collectively elevate the framework's functionality and maintainability, providing clearer abstractions for animations, stack management, and testing utilities.

Changes

File Change Summary
.../compose/experimental/stack/Utils.kt Added awaitAll function for concurrent coroutine execution and size property in ChildStack for item count retrieval.
.../compose/experimental/stack/animation/DefaultStackAnimation.kt Introduced AnimationHandler class to encapsulate animation state management during back navigation, improving structure and readability.
.../compose/experimental/TestUtils.kt New utilities for testing: assertTestTagToRootExists and assertTestTagToRootDoesNotExist enhance UI testing capabilities in Compose.
.../compose/experimental/stack/animation/PredictiveBackGestureTest.kt Added unit tests for verifying predictive back gesture functionality, focusing on gesture states and their effects on the UI and navigation stack.
.../compose/experimental/stack/ChildStackTest.kt Enhanced testing of stack animations with new predictive back parameters to control navigation behavior and test variations effectively.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant AnimationHandler
    participant ChildStack

    User->>UI: Initiate predictive back gesture
    UI->>AnimationHandler: Start animation
    AnimationHandler->>ChildStack: Update stack state
    ChildStack-->>AnimationHandler: Get current state
    AnimationHandler->>UI: Reflect animation state
    User->>UI: Complete or cancel gesture
    AnimationHandler->>ChildStack: Finalize stack state
    UI-->>User: Update UI accordingly
Loading

🐇 In the code garden, we dance and play,
New tools and tests brighten the way!
With animations that swirl and flow,
The stack is a canvas, watch it grow.
Hoppy updates, we cheer and sing,
In this code burrow, joy is the thing! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e2659fd and 12e3696.

Files selected for processing (4)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (5 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt (1 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt (1 hunks)
Additional comments not posted (18)
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt (2)

14-18: Efficient coroutine management with awaitAll.

The awaitAll function is well-implemented, leveraging coroutineScope and joinAll for concurrent execution of coroutines. This is an efficient and idiomatic approach for coroutine management.


11-11: Convenient size property for ChildStack.

The addition of the size property is a useful enhancement, providing direct access to the number of items in the ChildStack.

extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt (5)

11-14: Correct use of runOnIdleAndWaitForIdle.

The runOnIdleAndWaitForIdle function is well-implemented, ensuring UI consistency before making assertions in tests.


16-21: Accurate assertion with assertTestTagToRootExists.

The assertTestTagToRootExists function is correctly implemented, providing a clear and informative error message when the test tag is not found.


23-28: Accurate assertion with assertTestTagToRootDoesNotExist.

The assertTestTagToRootDoesNotExist function is correctly implemented, providing a clear and informative error message when an unexpected test tag is found.


30-33: Efficient collection with collectTestTagsToRoot.

The collectTestTagsToRoot function is efficiently implemented, using mapNotNull to collect test tags from the root node.


34-43: Correct traversal with collectSemanticsFromRoot.

The collectSemanticsFromRoot function correctly traverses the node hierarchy, collecting semantics configurations. This is a robust approach for gathering UI semantics.

extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt (6)

33-47: Correct test for inactive gesture state.

The test WHEN_gesture_not_started_THEN_active_child_shown_without_progress is well-implemented, accurately verifying the UI state when a gesture is not started.


49-65: Correct test for starting predictive back gesture.

The test WHEN_startPredictiveBack_THEN_gesture_started is well-implemented, accurately verifying the UI updates when a predictive back gesture is started.


67-86: Correct test for progressing predictive back gesture.

The test GIVEN_gesture_started_WHEN_progressPredictiveBack_THEN_gesture_progressed is well-implemented, accurately verifying the UI updates when a predictive back gesture progresses.


88-111: Correct test for finishing predictive back gesture.

The test GIVEN_gesture_started_WHEN_back_THEN_gesture_finished_and_stack_popped is well-implemented, accurately verifying the stack state and UI updates when a predictive back gesture is finished.


113-136: Correct test for canceling predictive back gesture.

The test GIVEN_gesture_started_WHEN_cancelPredictiveBack_THEN_gesture_cancelled_and_stack_not_changed is well-implemented, accurately verifying the stack state and UI updates when a predictive back gesture is canceled.


138-196: Well-structured test helpers and classes.

The helper functions and classes are well-structured, promoting code reuse and clarity in tests.

extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (5)

263-304: Good encapsulation of animation logic.

The AnimationHandler class effectively encapsulates the logic for managing animation states and transitions, improving the separation of concerns and enhancing code readability.


209-235: Improved state management with AnimationHandler.

The use of AnimationHandler in onBackStarted enhances the management of animation states, providing a more structured and maintainable approach.


241-241: Simplified animation progression with AnimationHandler.

The use of AnimationHandler in onBackProgressed simplifies the logic for handling animation progression during back navigation events.


247-248: Clear cancellation logic with AnimationHandler.

The use of AnimationHandler in onBackCancelled provides a clear and maintainable approach to canceling animations and resetting states.


255-256: Streamlined completion logic with AnimationHandler.

The use of AnimationHandler in onBack streamlines the logic for completing animations and updating the stack during back navigation events.

@arkivanov arkivanov force-pushed the fix-predictive-back branch from 12e3696 to 88d9f00 Compare August 15, 2024 10:38
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 12e3696 and 88d9f00.

Files selected for processing (4)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (5 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt (1 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt

@arkivanov arkivanov force-pushed the fix-predictive-back branch from 88d9f00 to 16d994d Compare August 16, 2024 12:04
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 88d9f00 and 16d994d.

Files selected for processing (4)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (7 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt (1 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt

@arkivanov arkivanov force-pushed the fix-predictive-back branch from 16d994d to 3aa4d80 Compare August 16, 2024 13:10
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 16d994d and 3aa4d80.

Files selected for processing (4)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (7 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt (1 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt
Additional comments not posted (3)
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt (2)

12-12: LGTM: Addition of size property.

The size property in ChildStack improves code readability by providing direct access to the number of items.


14-18: LGTM: Addition of awaitAll function.

The awaitAll function effectively manages concurrent coroutine execution, enhancing asynchronous capabilities.

extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (1)

270-311: LGTM: Introduction of AnimationHandler class.

The AnimationHandler class encapsulates animation logic, improving code organization and readability.

@arkivanov arkivanov force-pushed the fix-predictive-back branch from 3aa4d80 to c788975 Compare August 18, 2024 09:40
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3aa4d80 and c788975.

Files selected for processing (5)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (7 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt (1 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt (2 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt
Additional comments not posted (2)
extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt (2)

18-27: Imports look good.

The new imports for PredictiveBackParams and materialPredictiveBackAnimatable are necessary for implementing predictive back parameters.


238-270: Enhancements to getParameters look good.

The addition of predictive back parameters enhances the flexibility of stack animations. Ensure that these new parameters are adequately tested.

Consider verifying that the predictive back parameters function as expected in real scenarios.

Verification successful

Predictive back parameters are adequately tested.

The search results confirm that the predictive back parameters are used in test cases, ensuring their functionality is verified.

  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the predictive back parameters are used in tests.

# Test: Search for test cases using predictive back parameters. Expect: Usage of predictive back parameters in test cases.
rg --type kotlin 'predictiveBackParams'

Length of output: 7071

@arkivanov arkivanov force-pushed the fix-predictive-back branch from c788975 to 945cfa2 Compare August 18, 2024 12:20
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c788975 and 945cfa2.

Files selected for processing (5)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (7 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt (1 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt (2 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/Utils.kt
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/TestUtils.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt

@arkivanov arkivanov merged commit 1391225 into master Aug 18, 2024
2 checks passed
@arkivanov arkivanov deleted the fix-predictive-back branch August 18, 2024 12:46
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.

1 participant