ptmt / react-native-macos

[deprecated in favor of https://microsoft.github.io/react-native-windows/] React Native for macOS is an experimental fork for writing desktop apps using Cocoa
MIT License
11.25k stars 429 forks source link

on mouse right click, show up context menu #237

Closed jacoolee closed 5 years ago

jacoolee commented 5 years ago

🚀 Feature Proposal

on mouse right click

Motivation

it's obvious right click is a critical feature for desktop-oriented apps, so I wonder if it's supported already or can it be supported.

Example

on mouse right click, a context menu would show up.

aleclarson commented 5 years ago

Every <View> has a contextMenu prop for this.

const contextMenu = [
  { key: 'foo', title: 'Foo' },
  { isSeparator: true },
  { key: 'bar', title: 'Bar' },
]

<View
  contextMenu={contextMenu}
  onContextMenuItemClick={event => {
    console.log(event.nativeEvent)
  }} />

Here is the source code: https://github.com/ptmt/react-native-macos/blob/77580c1707ff5d31889a3f719ef3bbc13afa5e05/React/Views/RCTViewManager.m#L233-L259 https://github.com/ptmt/react-native-macos/blob/77580c1707ff5d31889a3f719ef3bbc13afa5e05/React/Views/RCTView.m#L730-L738

aleclarson commented 5 years ago

Also, #228 adds an onContextMenu prop, in case you want to implement a custom right-click menu.

aleclarson commented 5 years ago

If you have any ideas on how to improve this API, please open a new issue. Thanks!