Skip to content

Fix/ios menu mount#4

Merged
sbaiahmed1 merged 3 commits intomainfrom
fix/ios-menu-mount
Oct 23, 2025
Merged

Fix/ios menu mount#4
sbaiahmed1 merged 3 commits intomainfrom
fix/ios-menu-mount

Conversation

@sbaiahmed1
Copy link
Copy Markdown
Owner

@sbaiahmed1 sbaiahmed1 commented Oct 23, 2025

Summary by Sourcery

Fix iOS menu mounting by relying on React’s view hierarchy, removing conflicting constraints, and ensuring the menu’s selection state is correctly refreshed after remounts; introduce platform-specific rendering for MenuView and bump package version.

New Features:

  • Add updateMenuSelection method to rebuild the native menu with the current selection without full props update

Enhancements:

  • Remove manual addSubview in iOS MenuView and clear existing constraints before applying layout
  • Always refresh menu items or selection state when selectedIdentifier changes or after remount
  • Render MenuView directly on iOS, and wrap it with a relative container and zIndex on other platforms to correctly layer child content

Build:

  • Bump package version to 0.2.1

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Oct 23, 2025

Reviewer's Guide

This PR refactors the iOS MenuView to rely on React for mounting and constraint management, ensures menu selection state persists across remounts by adding a dedicated updateMenuSelection method, introduces platform-specific rendering logic in the React wrapper, tidies example imports, and bumps the package version.

Sequence diagram for menu selection state update on iOS remount

sequenceDiagram
participant React
participant MenuView (iOS)
participant _menuButton

React->>MenuView (iOS): Remounts component
MenuView (iOS)->>MenuView (iOS): updateProps called
alt selectedIdentifier changed
    MenuView (iOS)->>MenuView (iOS): updateMenuItems
else _menuButton and _menuButton.menu exist
    MenuView (iOS)->>MenuView (iOS): updateMenuSelection
    MenuView (iOS)->>_menuButton: Recreate menu with correct selection
end
Loading

Class diagram for updated MenuView (iOS) methods

classDiagram
class MenuView {
  - _menuItems: NSArray<NSDictionary *>
  - _menuButton: UIButton
  + updateProps(props, oldProps)
  + updateMenuItems(menuItems, selectedIdentifier)
  + updateMenuSelection(selectedIdentifier)
  + selectMenuItem(identifier, title)
}
MenuView : updateMenuSelection(selectedIdentifier)
Loading

File-Level Changes

Change Details Files
Refactor iOS child view setup to use React-mounted views with proper constraints
  • Removed manual addSubview and rely on mountChildComponentView
  • Disabled translatesAutoresizingMaskIntoConstraints and removed existing constraints
  • Activated top, leading, trailing, and bottom anchors to fill container
ios/MenuView.mm
Ensure menu selection state updates and persists across remounts
  • Always call updateMenuItems when selectedIdentifier changes
  • Added else-if branch to handle remounted components by calling updateMenuSelection
  • Introduced updateMenuSelection method to rebuild UIAction list with correct state
ios/MenuView.mm
Implement platform-specific rendering in React wrapper
  • Render NativeMenuView directly on iOS using Platform.OS check
  • Wrap Android (and others) version in a relative View with absoluteFill and zIndex
  • Added StyleSheet definition for relative positioning
src/index.tsx
Clean up example app imports
  • Reordered imports (useState, Alert, ScrollView) for clarity
  • Removed duplicated import statements
example/src/App.tsx
Bump package version
  • Increment version from 0.2.0 to 0.2.1
package.json

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:248-249` </location>
<code_context>
+    // Recreate the menu with updated selection states
+    NSMutableArray<UIAction *> *actions = [[NSMutableArray alloc] init];
+    
+    for (UIMenuElement *element in _menuButton.menu.children) {
+        if ([element isKindOfClass:[UIAction class]]) {
+            UIAction *oldAction = (UIAction *)element;
+            
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Recreating UIActions may lose other properties or behaviors set on the original actions.

Ensure all relevant properties from oldAction are copied to newAction to maintain expected behavior.

Suggested implementation:

```
    for (UIMenuElement *element in _menuButton.menu.children) {
        if ([element isKindOfClass:[UIAction class]]) {
            UIAction *oldAction = (UIAction *)element;

            // Copy all relevant properties from oldAction
            NSString *title = oldAction.title;
            UIImage *image = oldAction.image;
            NSString *identifier = oldAction.identifier;
            UIActionAttributes attributes = oldAction.attributes;
            UIActionState state = [oldAction.identifier isEqualToString:selectedIdentifier] ? UIActionStateOn : UIActionStateOff;
            NSString *discoverabilityTitle = oldAction.discoverabilityTitle;
            UIActionHandler handler = oldAction.handler;

            UIAction *newAction = [UIAction actionWithTitle:title
                                                      image:image
                                                 identifier:identifier
                                                    handler:handler];
            newAction.attributes = attributes;
            newAction.state = state;
            newAction.discoverabilityTitle = discoverabilityTitle;

            [actions addObject:newAction];

```

If your UIAction objects have other custom properties or behaviors, ensure those are also copied to the newAction. If you use custom subclasses of UIAction, you may need to copy those properties as well.
</issue_to_address>

### Comment 2
<location> `src/index.tsx:29-30` </location>
<code_context>
-    <NativeMenuView ref={ref} {...nativeProps}>
-      {children}
-    </NativeMenuView>
+    <View style={styles.relative}>
+      <NativeMenuView
+        style={[
+          StyleSheet.absoluteFill,
</code_context>

<issue_to_address>
**issue (bug_risk):** Absolute positioning and zIndex may cause stacking or touch issues with children.

Please verify that NativeMenuView's absolute positioning and zIndex do not block or intercept touch events intended for its children, particularly in nested or complex layouts.
</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.

@sbaiahmed1 sbaiahmed1 merged commit 5b7ab17 into main Oct 23, 2025
6 checks passed
@sbaiahmed1 sbaiahmed1 deleted the fix/ios-menu-mount branch November 30, 2025 22:04
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