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

Added isPredictiveBack flag to stackAnimation function with selector #826

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Dec 9, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new interfaces and functions for enhanced animation handling, including StackAnimation, StackAnimator, and ChildPanelsLayout.
    • Added overloaded ChildPanels methods to improve flexibility in panel configurations.
  • Bug Fixes

    • Updated method signatures to accommodate additional parameters for predictive back navigation in stack animations.
  • Tests

    • Modified test cases to reflect changes in method signatures, ensuring they validate the expected behavior with the new parameters.

Copy link

coderabbitai bot commented Dec 9, 2024

Walkthrough

The pull request introduces significant modifications to the extensions-compose-experimental API, particularly enhancing animation handling capabilities. Key changes include the addition of overloaded methods in the ChildPanelsKt class, which now support various function parameter combinations. The stackAnimation method in the StackAnimationKt class has been updated to accept an additional parameter, transitioning from Function3 to Function4. New interfaces and classes, such as StackAnimation, StackAnimator, and ChildPanelsLayout, have been defined, expanding the API's functionality while maintaining existing structures.

Changes

File Path Change Summary
extensions-compose-experimental/api/android/extensions-compose-experimental.api - Updated method signatures in StackAnimationKt to use Function4 instead of Function3.
- Added overloaded ChildPanels methods in ChildPanelsKt with new parameter combinations.
extensions-compose-experimental/api/extensions-compose-experimental.klib.api - Introduced new interfaces: StackAnimation, StackAnimator, ChildPanelsLayout, StackAnimationProvider.
- Added new class ChildPanelsAnimators with updated constructors and properties.
extensions-compose-experimental/api/jvm/extensions-compose-experimental.api - Similar updates as in the Android API, focusing on method signature changes in StackAnimationKt and overloaded methods in ChildPanelsKt.
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt - Added isPredictiveBack parameter to selector function and AnimationItem constructor, affecting predictive back animation logic.
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/StackAnimation.kt - Updated stackAnimation function overloads to include isPredictiveBack in selector function signature.
extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt - Updated stackAnimation calls to reflect new four-parameter signatures.
extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimationTest.kt - Modified selector function in tests to accept four parameters instead of three.
extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt - Updated DefaultStackAnimation function signature in tests to include additional parameter for selector.
extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/StackAnimationDirectionsTest.kt - Changed selector lambda to accept an additional parameter in tests, enhancing animation direction logic.

Possibly related PRs

🐇 In the land of code where rabbits hop,
New methods and functions make our hearts stop!
With panels and stacks dancing in glee,
Animation's a breeze, oh can't you see?
So let's celebrate with a joyful cheer,
For the changes we've made, bring us all near! 🎉


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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: 1

🧹 Outside diff range and nitpick comments (3)
extensions-compose-experimental/api/extensions-compose-experimental.klib.api (1)

70-70: Update documentation for the modified stackAnimation function

The stackAnimation function now includes the isPredictiveBack parameter in its selector lambda, changing from a Function3 to a Function4. Please update the API documentation to reflect this change and guide users on how to use the new parameter effectively.

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

32-44: Enhance explanation of the isPredictiveBack parameter

The selector function now includes the isPredictiveBack flag as a parameter. Consider providing additional context or examples in the documentation to clarify how this flag influences the animation selection, which will aid developers in understanding and utilizing this feature.

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

509-509: Consider enhancing test coverage for isPredictiveBack parameter

While the selector implementation is updated correctly, consider adding specific test cases that verify the behavior when isPredictiveBack is true vs false.

Example test case:

@Test
fun WHEN_isPredictiveBack_true_THEN_selector_receives_correct_value() {
    var receivedIsPredictiveBack: Boolean? = null
    DefaultStackAnimation(
        selector = { _, _, _, isPredictiveBack -> 
            receivedIsPredictiveBack = isPredictiveBack
            null 
        }
    )
    // Test assertions
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 363192a and 01a26c3.

📒 Files selected for processing (9)
  • extensions-compose-experimental/api/android/extensions-compose-experimental.api (1 hunks)
  • extensions-compose-experimental/api/extensions-compose-experimental.klib.api (1 hunks)
  • extensions-compose-experimental/api/jvm/extensions-compose-experimental.api (1 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt (3 hunks)
  • extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/StackAnimation.kt (2 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt (1 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimationTest.kt (2 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackGestureTest.kt (1 hunks)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/StackAnimationDirectionsTest.kt (1 hunks)
🔇 Additional comments (9)
extensions-compose-experimental/api/jvm/extensions-compose-experimental.api (1)

86-88: Verify consistency of stackAnimation method signature changes

The stackAnimation methods have been updated to accept Function4 instead of Function3. Ensure that this change is consistently applied across all platforms and related APIs to maintain uniformity.

Run the following script to check for consistent updates:

✅ Verification successful

Based on the search results, I can provide the final response:

stackAnimation signatures are consistently updated in experimental modules but differ in stable modules

The changes to use Function4 are consistently applied in both Android and JVM platforms within the experimental modules:

  • extensions-compose-experimental/api/android/extensions-compose-experimental.api
  • extensions-compose-experimental/api/jvm/extensions-compose-experimental.api

However, the stable modules still use Function3:

  • extensions-compose/api/android/extensions-compose.api
  • extensions-compose/api/jvm/extensions-compose.api

This is expected behavior as experimental APIs can evolve independently from stable ones.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all occurrences of `stackAnimation` methods and verify they use `Function4`

rg 'fun stackAnimation' -A 5

Length of output: 7629

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

70-70: Ensure default selector lambda handles isPredictiveBack correctly

In the default stackAnimation function, the selector lambda has been updated to include the isPredictiveBack parameter. Confirm that this default implementation applies the animator correctly, regardless of the predictive back gesture state.

Run the following script to validate the default selector usage:

✅ Verification successful

Let me analyze the code further by checking the implementation of the default stackAnimation function.


Let me try a different approach to find the implementation.


Let me try one more search to find the implementation details.


Default selector implementation correctly handles isPredictiveBack parameter

The default implementation of stackAnimation with the animator parameter correctly handles the isPredictiveBack flag by consistently returning the same animator regardless of the predictive back state. This is the intended behavior as it ensures a consistent animation experience whether the transition is triggered by regular navigation or predictive back gesture.

Reasoning:

  1. The default selector { _, _, _, _ -> animator } intentionally ignores all parameters, including isPredictiveBack
  2. This ensures the same animation is applied consistently across all navigation scenarios
  3. The predictive back gesture behavior is controlled separately through the predictiveBackParams parameter, not through the animation selector
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usages of the default `stackAnimation` function and check the `selector` implementation

rg 'stackAnimation\(' -A 5

Length of output: 37500


Script:

#!/bin/bash
# Find the implementation of stackAnimation function
ast-grep --pattern 'fun stackAnimation($$$) {
  $$$
}'

Length of output: 56


Script:

#!/bin/bash
# Find the implementation of stackAnimation function with the specific selector signature
rg -l "stackAnimation.*selector.*isPredictiveBack" --type kotlin

# If found, show the content of those files
rg "stackAnimation.*selector.*isPredictiveBack" -A 10 --type kotlin

Length of output: 136


Script:

#!/bin/bash
# Find the file containing the stackAnimation implementation
rg -l "DefaultStackAnimation" --type kotlin

# Show the content of the file containing DefaultStackAnimation
cat extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/StackAnimation.kt

Length of output: 4008

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

80-80: Verify all test cases accommodate the updated selector signature

The selector lambda in this test now accepts the isPredictiveBack parameter. Ensure that all other tests involving selector have been updated accordingly and that they properly handle the new parameter to prevent test failures or incorrect behaviors.

Run the following script to find and review all selector usages in test files:

✅ Verification successful

Based on the search results, I can now provide a final response:

All test cases are properly updated with the new selector signature

Looking at all the selector usages across test files, we can confirm that:

  1. In DefaultStackAnimationTest.kt, the selector is using all four parameters: { _, _, _, _ -> null }
  2. In PredictiveBackGestureTest.kt, the selector is using all four parameters: { _, _, _, _ -> animator }
  3. In StackAnimationDirectionsTest.kt, the selector is using all four parameters: { child, _, _, _ -> ...}

The class definition in DefaultStackAnimation.kt confirms the correct signature with all parameters: child, otherChild, direction, and isPredictiveBack.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Locate all instances of `selector` in test source files to confirm updates

rg 'selector\s*=\s*' src/jvmTest/

Length of output: 88


Script:

#!/bin/bash
# Let's try to find the test files using fd and then search for selector patterns
fd -e kt "Test.kt$" | xargs rg "selector\s*=\s*" -A 2

Length of output: 3895


Script:

#!/bin/bash
# Let's also search for the DefaultStackAnimation class usage to understand the context better
rg "DefaultStackAnimation" --type kotlin

Length of output: 5747


Script:

#!/bin/bash
# Search for stack animation related test files
fd "Stack.*Test.kt$"

Length of output: 899


Script:

#!/bin/bash
# Let's look at the DefaultStackAnimation class definition to understand the selector parameter
rg "class DefaultStackAnimation" -A 10 --type kotlin

Length of output: 4172


Script:

#!/bin/bash
# Let's also check the implementation file for any recent changes
git diff HEAD~5 -- "**/DefaultStackAnimation.kt"

Length of output: 79

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

Line range hint 39-44: LGTM! Selector function signature updated correctly.

The selector function signature has been updated to accept the new parameter, maintaining consistency with the broader changes in the animation framework.

Let's verify the consistency of this change across the codebase:

✅ Verification successful

Let me analyze the selector signatures more thoroughly by checking the actual type definitions.


Based on the analysis of the codebase, I can now generate the final response:

Selector function signature is correctly updated in experimental module

Looking at the implementations across the codebase, the selector function in the experimental module consistently uses 4 parameters as seen in multiple files:

  • extensions-compose-experimental/.../StackAnimation.kt: selector = { _, _, _, _ -> animator }
  • extensions-compose-experimental/.../DefaultStackAnimationTest.kt: selector = { _, _, _, _ -> null }
  • extensions-compose-experimental/.../PredictiveBackGestureTest.kt: selector = { _, _, _, _ -> animator }

The updated selector signature in the test file matches the pattern used throughout the experimental module.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify selector function signatures in animation-related files
# Test: Search for selector function definitions. Expect: All selectors should have 4 parameters

# Search for selector function definitions in animation-related files
rg -A 2 'selector\s*=\s*\{.*\}'

Length of output: 2943


Script:

#!/bin/bash
# Search for selector type definitions in animation-related files
ast-grep --pattern 'typealias $_ = ($$$) -> $_'

# Also search for interface or class definitions that might define the selector
rg -A 5 'interface.*Animation|class.*Animation'

Length of output: 49643

extensions-compose-experimental/api/android/extensions-compose-experimental.api (1)

86-86: LGTM! API signatures updated correctly.

The stackAnimation function signatures have been properly updated to use Function4, maintaining API consistency.

Also applies to: 88-88

extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt (1)

277-291: LGTM! Comprehensive test coverage for stack animations.

The test cases have been properly updated to cover all animation scenarios with the new selector signature, including:

  • Basic animations (null, scale, fade, slide, combined)
  • Predictive back animations with both parameter variants

Let's verify the test coverage:

✅ Verification successful

Test coverage for stack animations is comprehensive and well-structured

The verification confirms that the test cases cover all essential animation scenarios:

  • Basic animations (null, scale, fade, slide)
  • Combined animations (scale + fade + slide)
  • Predictive back animations with different parameter variants
  • Different selector signatures (both in experimental and stable versions)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for stack animations
# Test: Search for all test cases using stackAnimation. Expect: Coverage for all animation types

# Search for test cases using stackAnimation
rg -p 'stackAnimation.*\{.*\}' --type kotlin

Length of output: 2346

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

41-46: LGTM: Selector function signature enhancement

The addition of isPredictiveBack parameter enhances the selector's capability to handle predictive back navigation scenarios.


231-238: LGTM: AnimationItem constructor enhancement

The constructor changes properly support predictive back navigation while maintaining backward compatibility with the default false value.


278-288: LGTM: Proper predictive back animation handling

The implementation correctly sets up animation handling for predictive back gestures with appropriate animator initialization.

@arkivanov arkivanov merged commit 62d04fe into master Dec 10, 2024
3 checks passed
@arkivanov arkivanov deleted the isPredictiveBack-flag branch December 10, 2024 20:50
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