Skip to content

fix(ios): improve menu view child component handling#7

Merged
sbaiahmed1 merged 2 commits intomainfrom
fix/button-layout-issue-ios
Oct 30, 2025
Merged

fix(ios): improve menu view child component handling#7
sbaiahmed1 merged 2 commits intomainfrom
fix/button-layout-issue-ios

Conversation

@sbaiahmed1
Copy link
Copy Markdown
Owner

@sbaiahmed1 sbaiahmed1 commented Oct 30, 2025

properly clean up menu button and restore disabled views when unmounting track disabled views in a set to avoid duplicate state changes

Summary by Sourcery

Improve MenuView’s child component handling by centralizing cleanup logic for menu buttons and disabled subviews, ensuring consistent state restoration and preventing duplicate updates.

Enhancements:

  • Introduce a mutable set to track and restore disabled subviews’ user interaction state
  • Extract menu button cleanup into cleanupMenuButton and distinguish overlay vs. child buttons via _isChildViewButton flag
  • Invoke cleanupMenuButton and restoreUserInteractionForDisabledViews in mount, unmount, and dealloc to avoid duplicate or lingering state changes

properly clean up menu button and restore disabled views when unmounting
track disabled views in a set to avoid duplicate state changes
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Oct 30, 2025

Reviewer's Guide

This PR enhances MenuView by introducing explicit state tracking for child button overlays, automating the disabling and restoration of user interaction on nested views, centralizing menu button cleanup logic, and integrating these processes into mount, unmount, and deallocation phases.

Sequence diagram for mounting and unmounting child component views in MenuView

sequenceDiagram
participant MenuView
participant ChildView
participant MenuButton
participant DisabledViews
MenuView->>ChildView: mountChildComponentView()
alt If replacing old child view
  MenuView->>MenuView: cleanupMenuButton()
  MenuView->>MenuView: restoreUserInteractionForDisabledViews()
end
MenuView->>ChildView: setupChildViewAsMenuTrigger()
MenuView->>DisabledViews: disableUserInteractionRecursively()

MenuView->>ChildView: unmountChildComponentView()
MenuView->>MenuView: cleanupMenuButton()
MenuView->>MenuView: restoreUserInteractionForDisabledViews()
Loading

Sequence diagram for MenuView deallocation cleanup

sequenceDiagram
participant MenuView
participant MenuButton
participant DisabledViews
MenuView->>MenuView: dealloc()
MenuView->>MenuView: cleanupMenuButton()
MenuView->>MenuView: restoreUserInteractionForDisabledViews()
Loading

Class diagram for updated MenuView child component handling

classDiagram
class MenuView {
  UIColor *_textColor
  UIColor *_checkedColor
  UIColor *_uncheckedColor
  BOOL _isChildViewButton
  NSMutableSet<UIView *> *_disabledViews
  UIView *_childView
  UIButton *_menuButton
  NSArray *_menuItems
  +mountChildComponentView(UIView<RCTComponentViewProtocol> *childComponentView, NSInteger index)
  +unmountChildComponentView(UIView<RCTComponentViewProtocol> *childComponentView, NSInteger index)
  +setupChildViewAsMenuTrigger(UIView *childView)
  +disableUserInteractionRecursively(UIView *view)
  +restoreUserInteractionForDisabledViews()
  +cleanupMenuButton()
  +dealloc()
  +updateProps(Props::Shared const &props, Props::Shared const &oldProps)
}
MenuView --> UIButton
MenuView --> UIView
MenuView --> "*" UIView : disabledViews
Loading

File-Level Changes

Change Details Files
Introduce state tracking for overlay vs native button and disabled views
  • Add _disabledViews set and _isChildViewButton flag as ivars
  • Initialize these fields in initWithFrame
  • Update setupChildViewAsMenuTrigger to set the flag based on child type
ios/MenuView.mm
Automate disabling and restoration of user interaction
  • Refactor disableUserInteractionRecursively to record views only once
  • Add restoreUserInteractionForDisabledViews to re-enable and clear tracked views
ios/MenuView.mm
Centralize menu button cleanup logic
  • Implement cleanupMenuButton to remove overlay buttons and clear menus
  • Reset the _isChildViewButton flag within cleanup
ios/MenuView.mm
Integrate cleanup and restoration into lifecycle methods
  • Call cleanupMenuButton and restoreUserInteractionForDisabledViews in mountChildComponentView and unmountChildComponentView
  • Add dealloc to perform final cleanup on deallocation
ios/MenuView.mm

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `ios/MenuView.mm:23` </location>
<code_context>
     UIColor *_checkedColor;
     UIColor *_uncheckedColor;
+    BOOL _isChildViewButton;
+    NSMutableSet<UIView *> *_disabledViews;
 }

</code_context>

<issue_to_address>
**suggestion (bug_risk):** Consider using NSHashTable for weak references to views.

NSMutableSet keeps strong references, which may cause memory leaks if views are not properly removed. NSHashTable with weak objects prevents this by allowing views to be deallocated automatically.

Suggested implementation:

```
    NSHashTable<UIView *> *_disabledViews;

```

```
        _disabledViews = [NSHashTable weakObjectsHashTable];

```
</issue_to_address>

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 and I'll use the feedback to improve your reviews.

Comment thread ios/MenuView.mm Outdated
…d views

Use NSHashTable with weak references to prevent memory leaks when views are deallocated.

Add safety checks during iteration to handle weak references properly.
@sbaiahmed1 sbaiahmed1 merged commit 190c4e7 into main Oct 30, 2025
6 checks passed
@sbaiahmed1 sbaiahmed1 deleted the fix/button-layout-issue-ios branch October 30, 2025 22:35
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