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

Implement Container.ignore_interactions property #3639

Merged
merged 5 commits into from
Aug 20, 2024

Conversation

ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Jul 13, 2024

Summary by Sourcery

This pull request adds a new ignore_interactions property to the Container class, enabling the option to ignore user interactions. The ContainerControl class has been updated to handle this property by using an IgnorePointer widget.

  • New Features:
    • Introduced the ignore_interactions property to the Container class, allowing users to specify whether interactions with the container should be ignored.
  • Enhancements:
    • Updated the ContainerControl class to respect the ignore_interactions property by wrapping the container in an IgnorePointer widget when the property is set to true.

Copy link
Contributor

sourcery-ai bot commented Jul 13, 2024

Reviewer's Guide by Sourcery

This pull request introduces a new ignore_interactions property to the Container class. The property is added to the __init__ method and is managed via getter and setter methods in container.py. In container.dart, the ignoreInteractions attribute is added to the ContainerControl class, and the container is wrapped with IgnorePointer if ignoreInteractions is true, effectively ignoring any user interactions.

File-Level Changes

Files Changes
sdk/python/packages/flet-core/src/flet_core/container.py
packages/flet/lib/src/controls/container.dart
Introduced the ignore_interactions property to the Container class and implemented the logic to ignore interactions when this property is set to true.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • Continue your discussion with Sourcery by replying directly to review comments.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ndonkoHenri - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

Comment on lines +365 to +366
def ignore_interactions(self) -> Optional[bool]:
return self._get_attr("ignoreInteractions", data_type="bool", def_value=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): Mismatch in data type for ignore_interactions setter.

The setter for ignore_interactions should accept a value of type Optional[bool] instead of Optional[str] to match the property type.

packages/flet/lib/src/controls/container.dart Show resolved Hide resolved
Comment on lines +321 to +322
if (ignoreInteractions) {
result = IgnorePointer(child: result);
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider using AbsorbPointer instead of IgnorePointer.

AbsorbPointer can be used if you want to block interactions but still allow the widget to be visible to hit testing. This might be more appropriate depending on the use case.

Suggested change
if (ignoreInteractions) {
result = IgnorePointer(child: result);
if (ignoreInteractions) {
result = AbsorbPointer(child: result);

@@ -197,6 +198,7 @@ def __init__(
self.theme = theme
self.theme_mode = theme_mode
self.color_filter = color_filter
self.ignore_interactions = ignore_interactions
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (complexity): Consider simplifying the ignore_interactions attribute implementation.

The new code introduces unnecessary complexity and redundancy. The ignore_interactions attribute has inconsistent data types between the getter and setter, which can lead to confusion and potential bugs. Additionally, the added boilerplate code increases the cognitive load. Here's a more concise and consistent approach:

class Container:
    def __init__(self, ..., ignore_interactions: Optional[bool] = None, ...):
        ...
        self.ignore_interactions = ignore_interactions
        ...

    @property
    def ignore_interactions(self) -> Optional[bool]:
        return self._get_attr("ignoreInteractions", data_type="bool", def_value=False)

    @ignore_interactions.setter
    def ignore_interactions(self, value: Optional[bool]):
        self._set_attr("ignoreInteractions", value)

This version ensures consistent data types, reduces boilerplate, and improves code clarity.

@FeodorFitsner
Copy link
Contributor

Could you resolve conflict here please?

@FeodorFitsner
Copy link
Contributor

# Conflicts:
#	sdk/python/packages/flet-core/src/flet_core/container.py
…nto container-ignore-interactions

# Conflicts:
#	sdk/python/packages/flet-core/src/flet_core/container.py
@FeodorFitsner FeodorFitsner merged commit d041bb2 into main Aug 20, 2024
1 of 2 checks passed
@FeodorFitsner FeodorFitsner deleted the container-ignore-interactions branch August 20, 2024 18:36
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.

2 participants