Comments (5)
@AdrianFahrbach there's another option you could use for a native NSmenu: ActionSheetIOS. We actually ported that to fire an NSMenu. I found an old internal component that gives you an idea of how it could work:
'use strict';
import * as React from 'react';
import { findNodeHandle, ActionSheetIOSOptions, ActionSheetIOS } from 'react-native';
import { IContextualMenuStatic } from '../../common/ContextualMenu/ContextualMenu.types';
import { IContextualMenuProps } from '../../common/ContextualMenu/ContextualMenu.Props';
declare module 'react-native' {
// The TypeScript type definition at
// https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-native
// is missing anchor on ActionSheetIOSOptions.
// Use declaration merging to add it here.
interface ActionSheetIOSOptions {
anchor?: number;
}
}
class ContextualMenuImpl extends React.Component<IContextualMenuProps, {}> {
public static showContextualMenu(menu: IContextualMenuProps, target: React.ReactNode) {
const buttonTitles: Array<string> = [];
for (const button of menu.items) {
buttonTitles.push(button.name);
}
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
const reactTag = findNodeHandle(target as any);
const options: ActionSheetIOSOptions = {
options: buttonTitles,
cancelButtonIndex: menu.cancelButtonIndex,
destructiveButtonIndex: menu.destructiveButtonIndex,
anchor: reactTag
};
ActionSheetIOS.showActionSheetWithOptions(options, buttonIndex => {
menu.items[buttonIndex].onClick({ key: menu.items[buttonIndex].key });
});
}
}
export const ContextualMenu: IContextualMenuStatic = ContextualMenuImpl;
Note that while findNodeHandle
works in Fabric, it's not recommended, and we're still looking for a good alternative.
from react-native-macos.
I've been meaning to add support for macOS to https://github.com/react-native-menu/menu but haven't gotten around to it.
Meanwhile, I ended up writing a fully custom replacement for NSMenu with FluentUI React Native Menu. That one had to be fully custom (A custom NSWindow holding RN Views instead of just rendering a native NSMenu) because we wanted more customizable menu items (I.E, you can put any view in there instead of just text). That might be worth checking out. The spec page I linked doesn't have macOS screenshots but I encourage you to try the test app out
from react-native-macos.
I think when I've thought about this before, I've resisted the approach of just adding props to <View>
because menus can get secretly complex when you add in images, checkboxes, multi-select, submenus, etc. Ultimately I think a "wrapper "component (like @react-native-menu/menu) or a component that lets you write up the menu in JSX (like FluentUI React Native's Menu) is the better extensible approach.
from react-native-macos.
I tried the FluentUI React Native Menu and can't get it to work. I also tested this on windows and force opening the menu with <Menu open>
but it just doesn't show up. Maybe the theme provider is mandatory?
screenshot00.11.40.mp4
Ultimately I think a "wrapper "component (like @react-native-menu/menu) or a component that lets you write up the menu in JSX (like FluentUI React Native's Menu) is the better extensible approach.
My initial thought was a separate library as well, so I was actually looking for something like your FluentUI menu.
What I really like about the View prop approach though is its simplicity. I didn't test it, but it sounds like that way I also don't have to worry about making it feel 100% native and/or placing the popup in the right location. I also don't need to handle the open/close state or nest multiple components, I can just throw an object into that prop.
I'm going for a very native look & feel though, so in my case I don't want to place any custom views inside my menu.
from react-native-macos.
Related Issues (20)
- [RCTConvert] Deprecate UIBarStyle
- [RCTConvert] Remove UIBarStyle
- [SocketRocket] Upstream visionOS Support
- Is __apply_Xcode_12_5_M1_post_install_workaround now obsolete? HOT 4
- The transform style does not work in version 0.73.* HOT 7
- Unable to resolve module
- Input focus area doesn't move when parent view is transformed HOT 7
- [Fabric] TextInput UI is not updated when changing prop `value` or calling `inputRef.current.clear()` / `inputRef.current.setNativeProps({text: ''})` HOT 2
- Web inspector flashing on production/release build when starting the app HOT 6
- Keyboard shortcuts (copy, paste, select) not working in TextInput HOT 6
- "Fatal error: 'ExpoModulesCore/ExpoModulesCore.h' file not found" in run-macos HOT 3
- I want to request a feature like in-app Purchases support, and Firebase support. HOT 3
- useWindowDimensions causes infinite re-rendering HOT 3
- Wrong image pixel density version on initial launch HOT 6
- No version of react-native-macos@^0.70.0-0 found! HOT 1
- <Text onBlur={() => {}}> throws -[RCTTextView setOnBlur:]: unrecognized selector sent HOT 1
- How can i get the microphone or camera permission in react-native-macOS, i am using react-native-permissions HOT 3
- ERROR: No bundle URL present. HOT 10
- `Text` elements' `backgroundColor` style prop extends to the entire background
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-macos.