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

Make predictiveBackParams a function instead of just a value #761

Merged
merged 1 commit into from
Aug 18, 2024

Conversation

arkivanov
Copy link
Owner

@arkivanov arkivanov commented Aug 18, 2024

Closes #759.

Summary by CodeRabbit

  • New Features

    • Enhanced flexibility in animation handling by allowing dynamic computation of predictive back parameters based on the current stack state.
  • Improvements

    • Simplified method signatures for the PredictiveBackParams class, reducing complexity in handling back gestures and animations.
  • Refactor

    • Refined the structure of several classes and methods to improve maintainability and readability, particularly in the handling of event parameters.

Copy link

coderabbitai bot commented Aug 18, 2024

Walkthrough

The recent changes to the extensions-compose-experimental package simplify the handling of predictive back gestures by refactoring the PredictiveBackParams and StackAnimationKt classes. The updates shift from using complex multi-parameter functions to streamlined single-parameter functions, improving usability and clarity. Additionally, the DefaultStackAnimation class is enhanced to dynamically compute predictive back parameters based on the current state of the ChildStack, allowing for more flexible animation behaviors.

Changes

Files Change Summary
extensions-compose-experimental/api/android/extensions-compose-experimental.api, .../api/extensions-compose-experimental.klib.api, .../api/jvm/extensions-compose-experimental.api Constructor and method signatures in PredictiveBackParams and related classes updated to replace Function3 with Function1, simplifying the API.
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/DefaultStackAnimation.kt, .../PredictiveBackParams.kt, .../StackAnimation.kt Refactored predictiveBackParams to a function returning PredictiveBackParams, enhancing dynamism in back gesture handling.
extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt, .../PredictiveBackGestureTest.kt, .../StackAnimationDirectionsTest.kt, .../SharedTransitionsContent.kt Updates in test files to reflect changes in how predictiveBackParams are passed, improving clarity and consistency in test implementations.

Assessment against linked issues

Objective Addressed Explanation
Disable iOS swipe-back gesture on a specific page in a child stack navigation ( #759)
Simplify predictive back parameters handling in the stack animation context
Maintain compatibility with existing usage of PredictiveBackParams and related functions Impact on legacy code usage is unclear due to significant API changes.

Poem

In the warren where changes bloom,
Code now dances, shedding gloom.
Functions simpler, clearer paths,
Predictive back, a joyful math!
Hops of logic, smooth and bright,
A rabbit's cheer for code's delight! 🐰✨


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

Outside diff range, codebase verification and nitpick comments (1)
extensions-compose-experimental/src/commonMain/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/animation/PredictiveBackParams.kt (1)

27-27: Compatibility Issues with animatableSelector Usage

The current usages of animatableSelector in the test files do not align with the simplified signature. Specifically:

  • materialPredictiveBackAnimatable includes an additional parameter that is not compatible with the new single-parameter signature.
  • TestAnimatable is a class, not a function, which is incompatible with the expected function signature.

These issues need to be addressed to ensure consistency with the intended use of animatableSelector.

Analysis chain

Simplified animatableSelector parameter.

The change to simplify animatableSelector by focusing on initialBackEvent enhances clarity and reduces complexity. Ensure that this change aligns with the intended use cases across the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `animatableSelector` to ensure compatibility with the new signature.

# Test: Search for `animatableSelector` usage. Expect: Only occurrences with the new single parameter signature.
rg --type kotlin 'animatableSelector\s*=\s*'

Length of output: 465


Script:

#!/bin/bash
# Locate and display the definition of `materialPredictiveBackAnimatable`
rg --type kotlin 'fun materialPredictiveBackAnimatable' -A 5

# Locate and display the definition of `TestAnimatable`
rg --type kotlin 'fun TestAnimatable' -A 5

Length of output: 1269


Script:

#!/bin/bash
# Search for `TestAnimatable` definition without assuming it's a function
rg --type kotlin 'TestAnimatable'

Length of output: 430

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1391225 and bcf9394.

Files selected for processing (10)
  • extensions-compose-experimental/api/android/extensions-compose-experimental.api (2 hunks)
  • extensions-compose-experimental/api/extensions-compose-experimental.klib.api (2 hunks)
  • extensions-compose-experimental/api/jvm/extensions-compose-experimental.api (2 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/PredictiveBackParams.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 (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)
  • sample/shared/compose/src/commonMain/kotlin/com/arkivanov/sample/shared/sharedtransitions/SharedTransitionsContent.kt (1 hunks)
Files skipped from review due to trivial changes (1)
  • extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt
Additional comments not posted (12)
sample/shared/compose/src/commonMain/kotlin/com/arkivanov/sample/shared/sharedtransitions/SharedTransitionsContent.kt (1)

34-38: Dynamic predictiveBackParams implementation.

Wrapping predictiveBackParams in a lambda allows dynamic evaluation, enhancing flexibility. Verify that this change maintains the expected behavior in animations.

Verification successful

Dynamic predictiveBackParams implementation is verified.

The usage of predictiveBackParams in various test scenarios involving different animations (e.g., scale, fade, slide) confirms that its dynamic evaluation is being adequately tested. This ensures that the expected behavior in animations is maintained.

  • Test files demonstrate dynamic evaluation with different animation types.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the behavior of `predictiveBackParams` in animations.

# Test: Search for `predictiveBackParams` usage in animation contexts. Expect: Consistent behavior with dynamic evaluation.
rg --type kotlin 'predictiveBackParams\s*=\s*'

Length of output: 4076

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

29-31: Enhanced stackAnimation with dynamic predictiveBackParams.

The change to use a function type for predictiveBackParams allows dynamic evaluation, improving flexibility in handling back gestures. Verify that this aligns with the intended animation behaviors.

Also applies to: 37-37

Verification successful

Dynamic predictiveBackParams behavior is verified.

The test cases in ChildStackTest.kt demonstrate that the dynamic evaluation of predictiveBackParams is effectively tested, confirming its alignment with the intended animation behaviors. The function is tested with various configurations, ensuring flexibility and correctness in handling back gestures.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `stackAnimation` with the new `predictiveBackParams` function type.

# Test: Search for `stackAnimation` usage. Expect: Consistent behavior with dynamic evaluation of predictive back parameters.
rg --type kotlin 'stackAnimation\s*\('

Length of output: 4223


Script:

#!/bin/bash
# Search for the implementation details of `stackAnimation` in ChildStackTest.kt
rg --type kotlin 'stackAnimation' -A 5 extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt

Length of output: 2016


51-53: Dynamic evaluation in stackAnimation with StackAnimator.

The update to stackAnimation with a dynamic predictiveBackParams function type and StackAnimator enhances control over animations. Ensure that this change aligns with expected animation logic.

Also applies to: 59-59

Verification successful

Dynamic evaluation in stackAnimation with StackAnimator is verified.

The test cases in ChildStackTest.kt confirm that the dynamic evaluation of predictiveBackParams is consistent with expected animation logic, covering various scenarios. This ensures the correctness of the implementation.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of `stackAnimation` with `StackAnimator` and dynamic `predictiveBackParams`.

# Test: Search for `stackAnimation` usage with `StackAnimator`. Expect: Consistent animation logic with dynamic evaluation.
rg --type kotlin 'stackAnimation\s*\('

Length of output: 4223


Script:

#!/bin/bash
# Extract detailed context of `stackAnimation` usage in test files to verify dynamic evaluation logic.
rg --type kotlin -A 5 'stackAnimation\s*\(' extensions-compose-experimental/src/jvmTest/kotlin/com/arkivanov/decompose/extensions/compose/experimental/stack/ChildStackTest.kt

Length of output: 1367

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

38-38: LGTM! Verify the usage of predictiveBackParams.

The change from null to a lambda function returning null is approved. This modification allows for future flexibility in handling predictive back parameters.

However, ensure that this change aligns with the intended behavior and does not introduce unintended side effects in the DefaultStackAnimation class.

Verification successful

Change aligns with intended behavior and does not introduce side effects. The usage of predictiveBackParams as a lambda function in DefaultStackAnimation is consistent with its intended flexible behavior. The lambda is used to control the enabling of predictive back gestures, and no unintended side effects are observed in the current implementation.

  • DefaultStackAnimation properly handles the lambda to determine predictive back gesture behavior.
  • Test files demonstrate flexible usage without issues.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `predictiveBackParams` in `DefaultStackAnimation`.

# Test: Search for `predictiveBackParams` usage. Expect: Proper handling of the lambda function.
rg --type kotlin 'predictiveBackParams' -A 5

Length of output: 25253

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

13-15: Approved: Simplification of functional interfaces.

The changes to replace Function3 with Function1 in PredictiveBackParams and StackAnimationKt simplify the functional interfaces. This should improve usability and readability.

Ensure that these changes do not adversely affect existing functionality and that all dependent code is updated accordingly.

Also applies to: 35-38

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

13-15: Approved: Consistent simplification of function signatures.

The changes to replace Function3 with Function1 in PredictiveBackParams and StackAnimationKt are consistent with the previous file. This streamlines the API, enhancing clarity.

Verify that these changes are consistently applied and do not disrupt existing functionality.

Also applies to: 35-38

Verification successful

Verification Complete: Consistent Application of Simplified Function Signatures

The transition from Function3 to Function1 in PredictiveBackParams and StackAnimationKt has been consistently applied across the codebase. No instances of the old signature were found, indicating no disruption to existing functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify consistency and impact of changing `Function3` to `Function1` in `PredictiveBackParams` and `StackAnimationKt`.

# Test: Search for usages of affected constructors and methods. Expect: Consistent updates and no disruptions.
rg --type kotlin 'PredictiveBackParams|stackAnimation' -A 5

Length of output: 39102


Script:

#!/bin/bash
# Description: Check for any remaining instances of `stackAnimation` using `Function3` signature.

# Search for `stackAnimation` usages that still use a three-parameter function.
rg --type kotlin 'stackAnimation\s*\(\s*\w+\s*,\s*\w+\s*,\s*\w+' -A 5

Length of output: 71

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

288-294: Refactor improves clarity and flexibility.

The refactoring of predictiveBackParams into a function enhances readability and maintainability. The use of method reference ::TestAnimatable is a clean and efficient approach.

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

40-40: Dynamic computation of predictive back parameters enhances flexibility.

Changing predictiveBackParams to a function type allows for dynamic computation based on the current ChildStack state, significantly improving flexibility and adaptability.


95-104: Optimized computation of predictive back parameters.

The logic ensures that predictiveBackParams are computed only when the backStack is not empty, optimizing performance and maintaining clarity in the control flow.

extensions-compose-experimental/api/extensions-compose-experimental.klib.api (3)

22-22: Simplified constructor enhances clarity.

Changing the constructor to use a Function1 type parameter simplifies the callback mechanism, reducing complexity and improving clarity.


25-25: Getter method simplification aligns with constructor changes.

The getter method for animatableSelector now returns a Function1, aligning with the constructor change and simplifying back event handling.


39-40: Refactored method signatures improve usability.

The stackAnimation functions now use Function1, reducing the number of parameters and focusing functionality on single event handlers, enhancing usability and clarity.

@arkivanov arkivanov merged commit d0c0865 into master Aug 18, 2024
2 checks passed
@arkivanov arkivanov deleted the predictive-params-function branch August 18, 2024 15:32
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.

How to Disable iOS Swipe-Back Gesture on a Specific Page in a Child Stack Navigation Using Decompose
1 participant