Android PopupMenu and iOS14+ UIMenu components for react-native.
Falls back to ActionSheet for versions below iOS14.
Installation
via npm:
npm install @react-native-menu/menu
via yarn:
yarn add @react-native-menu/menu
Installing on iOS with React Native 0.63
There is an issue(https://github.com/facebook/react-native/issues/29246) causing projects with this module to fail on build on React Native 0.63.
This issue may be fixed in future versions of react native.
As a work around, look for lines in [YourPrject].xcodeproj
under LIBRARY_SEARCH_PATHS
with "\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"",
and change swift-5.0
to swift-5.3
.
Linking
The package is automatically linked when building the app. All you need to do is:
npx pod-install
Usage
import { MenuView } from '@react-native-menu/menu';
const App = () => {
return (
<View style={styles.container}>
<MenuView
title="Menu Title"
onPressAction={({ nativeEvent }) => {
console.warn(JSON.stringify(nativeEvent));
}}
actions={[
{
id: 'add',
titleColor: '#2367A2',
image: Platform.select({
ios: 'plus',
android: 'ic_menu_add',
}),
imageColor: '#2367A2',
},
{
id: 'share',
title: 'Share Action',
titleColor: '#46F289',
subtitle: 'Share action on SNS',
image: Platform.select({
ios: 'square.and.arrow.up',
android: 'ic_menu_share',
}),
imageColor: '#46F289',
state: 'on',
},
{
id: 'destructive',
title: 'Destructive Action',
attributes: {
destructive: true,
},
image: Platform.select({
ios: 'trash',
android: 'ic_menu_delete',
}),
},
]}
>
<View style={styles.button}>
<Text style={styles.buttonText}>Test</Text>
</View>
</MenuView>
</View>
);
};
Reference
Props
title
(iOS only)
The title of the menu.
actions
Actions to be displayed in the menu.
Type | Required |
---|
MenuAction[] | Yes |
Object representing Menu Action.
export type MenuAction = {
id?: string;
title: string;
titleColor?: number | ColorValue;
subtitle?: string;
attributes?: MenuAttributes;
state?: MenuState;
image?: string;
imageColor?: number | ColorValue;
};
The attributes indicating the style of the action.
type MenuAttributes = {
destructive?: boolean;
disabled?: boolean;
hidden?: boolean;
};
The state of the action.
type MenuState = 'off' | 'on' | 'mixed';
onPressAction
Callback function that will be called when selecting a menu item.
It will contain id of the given action.
Type | Required |
---|
({nativeEvent}) => void | No |
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT