Skip to content

feat(android): add androidDisplayMode prop for tooltip/dialog menu style#9

Merged
sbaiahmed1 merged 2 commits intomainfrom
feat/add-tooltip-support
Dec 6, 2025
Merged

feat(android): add androidDisplayMode prop for tooltip/dialog menu style#9
sbaiahmed1 merged 2 commits intomainfrom
feat/add-tooltip-support

Conversation

@sbaiahmed1
Copy link
Copy Markdown
Owner

@sbaiahmed1 sbaiahmed1 commented Dec 6, 2025

Add support for tooltip-style menus on Android through new androidDisplayMode prop. This provides more native-like menu behavior on Android, matching platform conventions where appropriate.

The prop accepts either 'dialog' (default) or 'tooltip' mode. When set to 'tooltip', the menu appears as a native PopupMenu anchored to the trigger view, with proper theme support and destructive item styling.

Summary by Sourcery

Add configurable Android menu display modes and expand the documented MenuView API and examples.

New Features:

  • Introduce an androidDisplayMode prop to switch between dialog and tooltip-style menus on Android, backed by a native PopupMenu implementation.
  • Support destructive menu items with red text and subtitle fields in menu items, and theme variant control for Android menus.

Enhancements:

  • Refine and condense README documentation, including updated props tables and contributing link, and remove low-level implementation details.
  • Extend the example app with theme-variant typing improvements and a new Android tooltip menu showcase.

Documentation:

  • Document new MenuView props, including themeVariant, subtitles, destructive items, and Android-specific behavior in the README.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Dec 6, 2025

Reviewer's Guide

Adds a new androidDisplayMode prop to allow Android menus to render as native tooltip-style PopupMenu instead of the existing dialog implementation, updates the Android native view/manager wiring, and extends the example app and README to document the new behavior and related props/features.

Sequence diagram for Android menu display mode selection

sequenceDiagram
  actor User
  participant ReactNativeApp
  participant MenuViewJS
  participant MenuViewNativeComponent
  participant MenuViewNative
  participant AndroidPopupMenu
  participant AndroidDialog

  User->>ReactNativeApp: Tap menu trigger
  ReactNativeApp->>MenuViewJS: onPress handler
  MenuViewJS->>MenuViewNativeComponent: render with androidDisplayMode=tooltip
  MenuViewNativeComponent->>MenuViewNative: setAndroidDisplayMode(tooltip)

  User->>MenuViewNative: touch intercepted on trigger view
  MenuViewNative->>MenuViewNative: showMenu()
  alt androidDisplayMode == tooltip
    MenuViewNative->>MenuViewNative: showTooltipMenu()
    MenuViewNative->>AndroidPopupMenu: create PopupMenu and populate items
    AndroidPopupMenu-->>User: show anchored tooltip menu
  else androidDisplayMode == dialog
    MenuViewNative->>MenuViewNative: showDialogMenu()
    MenuViewNative->>AndroidDialog: create and show dialog
    AndroidDialog-->>User: show bottom dialog menu
  end

  User->>AndroidPopupMenu: select item
  AndroidPopupMenu->>MenuViewNative: onMenuItemClick
  MenuViewNative->>MenuViewNativeComponent: dispatch onMenuSelect
  MenuViewNativeComponent->>MenuViewJS: onMenuSelect event
  MenuViewJS->>ReactNativeApp: handleMenuSelect and update state
Loading

Updated class diagram for MenuView Android display modes and props

classDiagram
  class MenuView {
    - String androidDisplayMode
    - List~ReadableMap~ menuItems
    - String themeVariant
    - String selectedItemIdentifier
    + setAndroidDisplayMode(mode String)
    + setMenuItems(items List~ReadableMap~)
    + setThemeVariant(themeVariant String)
    + setSelectedIdentifier(identifier String)
    - void showMenu()
    - void showTooltipMenu()
    - void showDialogMenu()
  }

  class MenuViewManager {
    + createViewInstance(context ThemedReactContext) MenuView
    + setMenuItems(view MenuView, menuItems ReadableArray)
    + setSelectedIdentifier(view MenuView, selectedIdentifier String)
    + setDisabled(view MenuView, disabled Boolean)
    + setAndroidDisplayMode(view MenuView, androidDisplayMode String)
  }

  class NativeProps {
    + menuItems MenuItem[]
    + selectedIdentifier String
    + disabled Boolean
    + androidDisplayMode androidDisplayModeType
    + onMenuSelect BubblingEventHandler
  }

  class MenuItem {
    + identifier String
    + title String
    + subtitle String
    + destructive Boolean
    + iosSymbol String
  }

  class androidDisplayModeType {
    <<enumeration>>
    dialog
    tooltip
  }

  MenuViewManager --> MenuView : manages
  NativeProps --> MenuItem : uses
  NativeProps --> androidDisplayModeType : uses
Loading

File-Level Changes

Change Details Files
Introduce androidDisplayMode prop for Android MenuView and wire it through native/JS interfaces.
  • Add androidDisplayMode field with default 'dialog' to MenuView native view state.
  • Expose setAndroidDisplayMode on MenuView to store the chosen display mode.
  • Export androidDisplayMode React prop via MenuViewManager with @ReactProp.
  • Declare androidDisplayMode in NativeProps with union type 'dialog'
'tooltip' and default 'dialog'.
Add tooltip-style PopupMenu rendering path on Android using androidDisplayMode='tooltip'.
  • Update showMenu to branch between tooltip and dialog rendering based on androidDisplayMode.
  • Implement showTooltipMenu using ContextThemeWrapper and PopupMenu with light/dark themeVariant support.
  • Support destructive items by rendering red text via SpannableString and ForegroundColorSpan.
  • Mirror selection behavior by marking the selected item as checked and invoking selectMenuItem on click.
  • Extract existing dialog-based menu logic into showDialogMenu for clarity.
android/src/main/java/com/menu/MenuView.kt
Extend example app to demonstrate themeVariant typing and Android tooltip usage.
  • Tighten TypeScript typing for selectedTheme to 'light'
'dark'
Refresh README API docs and feature list to reflect new props and capabilities.
  • Update feature checklist with subtitle support, destructive action styling, theme variant support, and improved accessibility.
  • Replace older, verbose API/architecture sections with a concise MenuView props table and MenuItem object description including subtitle, destructive, and iosSymbol.
  • Simplify contributing section link format.
README.md

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

@sbaiahmed1 sbaiahmed1 self-assigned this Dec 6, 2025
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 - here's some feedback:

  • The new androidDisplayMode prop isn’t documented in the README props table; consider adding it (including allowed values and default) so consumers know how to opt into the tooltip-style menu.
  • In MenuView.setAndroidDisplayMode and showMenu, the comments still refer to text color / items requesting tooltip mode, which no longer matches the implementation; updating these comments will make the behavior clearer to future readers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `androidDisplayMode` prop isn’t documented in the README props table; consider adding it (including allowed values and default) so consumers know how to opt into the tooltip-style menu.
- In `MenuView.setAndroidDisplayMode` and `showMenu`, the comments still refer to text color / items requesting tooltip mode, which no longer matches the implementation; updating these comments will make the behavior clearer to future readers.

## Individual Comments

### Comment 1
<location> `android/src/main/java/com/menu/MenuView.kt:184` </location>
<code_context>

     private fun showMenu() {
+        // Check if any item requests tooltip mode
+        val useTooltip =  androidDisplayMode == "tooltip"
+        
+        if (useTooltip) {
</code_context>

<issue_to_address>
**suggestion (bug_risk):** Consider normalizing/validating `androidDisplayMode` and fixing the minor formatting issue.

Any value other than the exact string "tooltip" (including typos) now silently falls back to dialog mode. To avoid subtle bugs, consider normalizing this value (e.g., trim/lowercase) and constraining it to known options (constants or an enum). Also, there’s a double space before `androidDisplayMode` that should be removed.

Suggested implementation:

```
        androidDisplayMode = mode
            ?.trim()
            ?.lowercase()
            ?.takeIf { it == "tooltip" || it == "dialog" }
            ?: "dialog"
    }


```

```
        // Check if any item requests tooltip mode
        val useTooltip = androidDisplayMode == "tooltip"


```
</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.

refactor(android): clean up androidDisplayMode related code
@sbaiahmed1 sbaiahmed1 merged commit 6c3c7aa into main Dec 6, 2025
6 checks passed
@sbaiahmed1 sbaiahmed1 deleted the feat/add-tooltip-support branch December 6, 2025 17:57
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