@react-native-menu/menu 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -158,6 +158,14 @@ Actions to be displayed in the menu.
158
158
  | ------------ | -------- |
159
159
  | MenuAction[] | Yes |
160
160
 
161
+ ### `themeVariant` (iOS only)
162
+
163
+ String to override theme of menu
164
+
165
+ | Type | Required |
166
+ | ------------ | -------- |
167
+ | enum('light', 'dark') | No |
168
+
161
169
  #### `MenuAction`
162
170
 
163
171
  Object representing Menu Action.
@@ -11,12 +11,12 @@ import UIKit
11
11
  @objc(ActionSheetView)
12
12
  class ActionSheetView: UIView {
13
13
  @objc var onPressAction: RCTDirectEventBlock?
14
- private var _title: String?;
14
+ private var _title: String?
15
15
  @objc var title: NSString? {
16
16
  didSet { self._title = title as? String }
17
17
  }
18
-
19
- private var _actions: [UIAlertAction] = [];
18
+
19
+ private var _actions: [UIAlertAction] = []
20
20
  @objc var actions: [NSDictionary]? {
21
21
  didSet {
22
22
  guard let actions = self.actions else {
@@ -34,7 +34,12 @@ class ActionSheetView: UIView {
34
34
  }
35
35
 
36
36
  @objc var shouldOpenOnLongPress: Bool = false
37
-
37
+
38
+ private var _themeVariant: String?
39
+ @objc var themeVariant: NSString? {
40
+ didSet { self._themeVariant = themeVariant as? String }
41
+ }
42
+
38
43
  override init(frame: CGRect) {
39
44
  super.init(frame: frame)
40
45
  let tap = UITapGestureRecognizer(target: self, action: #selector (self.handleTap (_:)))
@@ -42,30 +47,42 @@ class ActionSheetView: UIView {
42
47
  self.addGestureRecognizer(tap)
43
48
  self.addGestureRecognizer(longPress)
44
49
  }
45
-
50
+
46
51
  func launchActionSheet() {
47
52
 
48
53
  let alert = UIAlertController(title: _title, message: nil, preferredStyle: .actionSheet)
49
54
 
55
+ if #available(iOS 13.0, *) {
56
+ if self._themeVariant != nil {
57
+ if self._themeVariant == "dark" {
58
+ alert.overrideUserInterfaceStyle = .dark
59
+ } else if self._themeVariant == "light" {
60
+ alert.overrideUserInterfaceStyle = .light
61
+ } else {
62
+ alert.overrideUserInterfaceStyle = .unspecified
63
+ }
64
+ }
65
+ }
66
+
50
67
  self._actions.forEach({action in
51
68
  alert.addAction(action.copy() as! UIAlertAction)
52
69
  })
53
-
70
+
54
71
  alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
55
-
72
+
56
73
  if UIDevice.current.userInterfaceIdiom == .pad {
57
74
  alert.modalPresentationStyle = .popover
58
75
  alert.popoverPresentationController?.sourceView = self
59
76
  alert.popoverPresentationController?.sourceRect = self.bounds
60
77
  }
61
-
78
+
62
79
  if let root = RCTPresentedViewController() {
63
80
  root.present(alert, animated: true, completion: nil)
64
81
  }
65
-
82
+
66
83
  }
67
-
68
-
84
+
85
+
69
86
  @objc func handleTap(_ sender:UITapGestureRecognizer) {
70
87
  if shouldOpenOnLongPress {
71
88
  return
@@ -76,7 +93,7 @@ class ActionSheetView: UIView {
76
93
  }
77
94
  }
78
95
  }
79
-
96
+
80
97
  @objc func handleLongPress(_ sender: UILongPressGestureRecognizer) {
81
98
  if !shouldOpenOnLongPress {
82
99
  return
@@ -87,19 +104,19 @@ class ActionSheetView: UIView {
87
104
  }
88
105
  }
89
106
  }
90
-
107
+
91
108
  @objc func sendButtonAction(_ action: String) {
92
109
  if let onPress = onPressAction {
93
110
  onPress(["event":action])
94
111
  }
95
112
  }
96
-
113
+
97
114
  required init?(coder: NSCoder) {
98
115
  fatalError("init(coder:) has not been implemented")
99
116
  }
100
-
117
+
101
118
  override func reactSetFrame(_ frame: CGRect) {
102
- super.reactSetFrame(frame);
103
- };
104
-
119
+ super.reactSetFrame(frame)
120
+ }
121
+
105
122
  }
@@ -42,8 +42,10 @@ class MenuView: UIButton {
42
42
  }
43
43
  }
44
44
 
45
- @objc var darkMode: Bool = false {
45
+ private var _themeVariant: String?
46
+ @objc var themeVariant: NSString? {
46
47
  didSet {
48
+ self._themeVariant = themeVariant as? String
47
49
  self.setup()
48
50
  }
49
51
  }
@@ -56,11 +58,17 @@ class MenuView: UIButton {
56
58
 
57
59
  func setup () {
58
60
  let menu = UIMenu(title:_title, identifier: nil, children: self._actions)
59
- if self.darkMode {
60
- self.overrideUserInterfaceStyle = .dark
61
- } else {
62
- self.overrideUserInterfaceStyle = .light
61
+
62
+ if self._themeVariant != nil {
63
+ if self._themeVariant == "dark" {
64
+ self.overrideUserInterfaceStyle = .dark
65
+ } else if self._themeVariant == "light" {
66
+ self.overrideUserInterfaceStyle = .light
67
+ } else {
68
+ self.overrideUserInterfaceStyle = .unspecified
69
+ }
63
70
  }
71
+
64
72
  self.menu = menu
65
73
  self.showsMenuAsPrimaryAction = !shouldOpenOnLongPress
66
74
  }
@@ -20,8 +20,8 @@ RCT_EXPORT_VIEW_PROPERTY(onPressAction, RCTDirectEventBlock);
20
20
  */
21
21
  RCT_EXPORT_VIEW_PROPERTY(shouldOpenOnLongPress, BOOL)
22
22
  /**
23
- * darkMode: determines whether menu should be dark mode or light mode
23
+ * themeVariant: determines whether menu should use dark theme, light theme or system theme
24
24
  */
25
- RCT_EXPORT_VIEW_PROPERTY(darkMode, BOOL)
25
+ RCT_EXPORT_VIEW_PROPERTY(themeVariant, NSString)
26
26
 
27
27
  @end
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n ColorValue,\n processColor,\n StyleProp,\n ViewStyle,\n} from 'react-native';\nimport type * as React from 'react';\n\nexport type NativeActionEvent = {\n nativeEvent: {\n event: string;\n };\n};\n\ntype MenuAttributes = {\n /**\n * An attribute indicating the destructive style.\n */\n destructive?: boolean;\n /**\n * An attribute indicating the disabled style.\n */\n disabled?: boolean;\n /**\n * An attribute indicating the hidden style.\n */\n hidden?: boolean;\n};\n\n/**\n * The state of the action.\n * - off: A constant indicating the menu element is in the “off” state.\n * - on: A constant indicating the menu element is in the “on” state.\n * - mixed: A constant indicating the menu element is in the “mixed” state.\n */\ntype MenuState = 'off' | 'on' | 'mixed';\n\nexport type MenuAction = {\n /**\n * Identifier of the menu action.\n * The value set in this id will be returned when menu is selected.\n */\n id?: string;\n /**\n * The action's title.\n */\n title: string;\n /**\n * (Android only)\n * The action's title color.\n * @platform Android\n */\n titleColor?: number | ColorValue;\n /**\n * (iOS14+ only)\n * An elaborated title that explains the purpose of the action.\n * @platform iOS\n */\n subtitle?: string;\n /**\n * The attributes indicating the style of the action.\n */\n attributes?: MenuAttributes;\n /**\n * (iOS14+ only)\n * The state of the action.\n * @platform iOS\n */\n state?: MenuState;\n /**\n * (Android and iOS13+ only)\n * - The action's image.\n * - Allows icon name included in project or system (Android) resources drawables and\n * in SF Symbol (iOS)\n * @example // (iOS)\n * image=\"plus\"\n * @example // (Android)\n * image=\"ic_menu_add\"\n * - TODO: Allow images other than those included in SF Symbol and resources drawables\n */\n image?: string;\n /**\n * (Android and iOS13+ only)\n * - The action's image color.\n */\n imageColor?: number | ColorValue;\n /**\n * (Android and iOS14+ only)\n * - Actions to be displayed in the sub menu\n * - On Android it does not support nesting next sub menus in sub menu item\n */\n subactions?: MenuAction[];\n /**\n * Whether subactions should be inline (separated by divider) or nested (sub menu)\n */\n displayInline?: boolean;\n};\n\ntype MenuComponentPropsBase = {\n style?: StyleProp<ViewStyle>;\n /**\n * Callback function that will be called when selecting a menu item.\n * It will contain id of the given action.\n */\n onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;\n /**\n * Actions to be displayed in the menu.\n */\n actions: MenuAction[];\n /**\n * The title of the menu.\n */\n title?: string;\n /**\n * (Android API 23+)\n * Boolean value determines whether popup menu should be anchored\n * to right corner of parent view - default value is `false`\n * @platform Android\n */\n isAnchoredToRight?: boolean;\n /**\n * Determines if menu should open after long press or on normal press\n *\n * @default false\n */\n shouldOpenOnLongPress?: boolean;\n /**\n * Determines if menu should be displayed in dark mode or light mode\n * (Only support iOS for now)\n *\n * @default false\n * @platform iOS\n */\n darkMode?: boolean;\n};\n\nexport type MenuComponentProps =\n React.PropsWithChildren<MenuComponentPropsBase>;\n\nexport type ProcessedMenuAction = Omit<\n MenuAction,\n 'imageColor' | 'titleColor' | 'subactions'\n> & {\n imageColor: ReturnType<typeof processColor>;\n titleColor: ReturnType<typeof processColor>;\n subactions?: ProcessedMenuAction[];\n};\n\nexport type NativeMenuComponentProps = {\n style?: StyleProp<ViewStyle>;\n onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;\n actions: ProcessedMenuAction[];\n title?: string;\n};\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n ColorValue,\n processColor,\n StyleProp,\n ViewStyle,\n} from 'react-native';\nimport type * as React from 'react';\n\nexport type NativeActionEvent = {\n nativeEvent: {\n event: string;\n };\n};\n\ntype MenuAttributes = {\n /**\n * An attribute indicating the destructive style.\n */\n destructive?: boolean;\n /**\n * An attribute indicating the disabled style.\n */\n disabled?: boolean;\n /**\n * An attribute indicating the hidden style.\n */\n hidden?: boolean;\n};\n\n/**\n * The state of the action.\n * - off: A constant indicating the menu element is in the “off” state.\n * - on: A constant indicating the menu element is in the “on” state.\n * - mixed: A constant indicating the menu element is in the “mixed” state.\n */\ntype MenuState = 'off' | 'on' | 'mixed';\n\nexport type MenuAction = {\n /**\n * Identifier of the menu action.\n * The value set in this id will be returned when menu is selected.\n */\n id?: string;\n /**\n * The action's title.\n */\n title: string;\n /**\n * (Android only)\n * The action's title color.\n * @platform Android\n */\n titleColor?: number | ColorValue;\n /**\n * (iOS14+ only)\n * An elaborated title that explains the purpose of the action.\n * @platform iOS\n */\n subtitle?: string;\n /**\n * The attributes indicating the style of the action.\n */\n attributes?: MenuAttributes;\n /**\n * (iOS14+ only)\n * The state of the action.\n * @platform iOS\n */\n state?: MenuState;\n /**\n * (Android and iOS13+ only)\n * - The action's image.\n * - Allows icon name included in project or system (Android) resources drawables and\n * in SF Symbol (iOS)\n * @example // (iOS)\n * image=\"plus\"\n * @example // (Android)\n * image=\"ic_menu_add\"\n * - TODO: Allow images other than those included in SF Symbol and resources drawables\n */\n image?: string;\n /**\n * (Android and iOS13+ only)\n * - The action's image color.\n */\n imageColor?: number | ColorValue;\n /**\n * (Android and iOS14+ only)\n * - Actions to be displayed in the sub menu\n * - On Android it does not support nesting next sub menus in sub menu item\n */\n subactions?: MenuAction[];\n /**\n * Whether subactions should be inline (separated by divider) or nested (sub menu)\n */\n displayInline?: boolean;\n};\n\ntype MenuComponentPropsBase = {\n style?: StyleProp<ViewStyle>;\n /**\n * Callback function that will be called when selecting a menu item.\n * It will contain id of the given action.\n */\n onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;\n /**\n * Actions to be displayed in the menu.\n */\n actions: MenuAction[];\n /**\n * The title of the menu.\n */\n title?: string;\n /**\n * (Android API 23+)\n * Boolean value determines whether popup menu should be anchored\n * to right corner of parent view - default value is `false`\n * @platform Android\n */\n isAnchoredToRight?: boolean;\n /**\n * Determines if menu should open after long press or on normal press\n *\n * @default false\n */\n shouldOpenOnLongPress?: boolean;\n /**\n * Overrides theme variant of menu to light mode, dark mode or system theme\n * (Only support iOS for now)\n *\n * @platform iOS\n */\n themeVariant?: string;\n};\n\nexport type MenuComponentProps =\n React.PropsWithChildren<MenuComponentPropsBase>;\n\nexport type ProcessedMenuAction = Omit<\n MenuAction,\n 'imageColor' | 'titleColor' | 'subactions'\n> & {\n imageColor: ReturnType<typeof processColor>;\n titleColor: ReturnType<typeof processColor>;\n subactions?: ProcessedMenuAction[];\n};\n\nexport type NativeMenuComponentProps = {\n style?: StyleProp<ViewStyle>;\n onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;\n actions: ProcessedMenuAction[];\n title?: string;\n};\n"],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n ColorValue,\n processColor,\n StyleProp,\n ViewStyle,\n} from 'react-native';\nimport type * as React from 'react';\n\nexport type NativeActionEvent = {\n nativeEvent: {\n event: string;\n };\n};\n\ntype MenuAttributes = {\n /**\n * An attribute indicating the destructive style.\n */\n destructive?: boolean;\n /**\n * An attribute indicating the disabled style.\n */\n disabled?: boolean;\n /**\n * An attribute indicating the hidden style.\n */\n hidden?: boolean;\n};\n\n/**\n * The state of the action.\n * - off: A constant indicating the menu element is in the “off” state.\n * - on: A constant indicating the menu element is in the “on” state.\n * - mixed: A constant indicating the menu element is in the “mixed” state.\n */\ntype MenuState = 'off' | 'on' | 'mixed';\n\nexport type MenuAction = {\n /**\n * Identifier of the menu action.\n * The value set in this id will be returned when menu is selected.\n */\n id?: string;\n /**\n * The action's title.\n */\n title: string;\n /**\n * (Android only)\n * The action's title color.\n * @platform Android\n */\n titleColor?: number | ColorValue;\n /**\n * (iOS14+ only)\n * An elaborated title that explains the purpose of the action.\n * @platform iOS\n */\n subtitle?: string;\n /**\n * The attributes indicating the style of the action.\n */\n attributes?: MenuAttributes;\n /**\n * (iOS14+ only)\n * The state of the action.\n * @platform iOS\n */\n state?: MenuState;\n /**\n * (Android and iOS13+ only)\n * - The action's image.\n * - Allows icon name included in project or system (Android) resources drawables and\n * in SF Symbol (iOS)\n * @example // (iOS)\n * image=\"plus\"\n * @example // (Android)\n * image=\"ic_menu_add\"\n * - TODO: Allow images other than those included in SF Symbol and resources drawables\n */\n image?: string;\n /**\n * (Android and iOS13+ only)\n * - The action's image color.\n */\n imageColor?: number | ColorValue;\n /**\n * (Android and iOS14+ only)\n * - Actions to be displayed in the sub menu\n * - On Android it does not support nesting next sub menus in sub menu item\n */\n subactions?: MenuAction[];\n /**\n * Whether subactions should be inline (separated by divider) or nested (sub menu)\n */\n displayInline?: boolean;\n};\n\ntype MenuComponentPropsBase = {\n style?: StyleProp<ViewStyle>;\n /**\n * Callback function that will be called when selecting a menu item.\n * It will contain id of the given action.\n */\n onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;\n /**\n * Actions to be displayed in the menu.\n */\n actions: MenuAction[];\n /**\n * The title of the menu.\n */\n title?: string;\n /**\n * (Android API 23+)\n * Boolean value determines whether popup menu should be anchored\n * to right corner of parent view - default value is `false`\n * @platform Android\n */\n isAnchoredToRight?: boolean;\n /**\n * Determines if menu should open after long press or on normal press\n *\n * @default false\n */\n shouldOpenOnLongPress?: boolean;\n /**\n * Determines if menu should be displayed in dark mode or light mode\n * (Only support iOS for now)\n *\n * @default false\n * @platform iOS\n */\n darkMode?: boolean;\n};\n\nexport type MenuComponentProps =\n React.PropsWithChildren<MenuComponentPropsBase>;\n\nexport type ProcessedMenuAction = Omit<\n MenuAction,\n 'imageColor' | 'titleColor' | 'subactions'\n> & {\n imageColor: ReturnType<typeof processColor>;\n titleColor: ReturnType<typeof processColor>;\n subactions?: ProcessedMenuAction[];\n};\n\nexport type NativeMenuComponentProps = {\n style?: StyleProp<ViewStyle>;\n onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;\n actions: ProcessedMenuAction[];\n title?: string;\n};\n"],"mappings":""}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type {\n ColorValue,\n processColor,\n StyleProp,\n ViewStyle,\n} from 'react-native';\nimport type * as React from 'react';\n\nexport type NativeActionEvent = {\n nativeEvent: {\n event: string;\n };\n};\n\ntype MenuAttributes = {\n /**\n * An attribute indicating the destructive style.\n */\n destructive?: boolean;\n /**\n * An attribute indicating the disabled style.\n */\n disabled?: boolean;\n /**\n * An attribute indicating the hidden style.\n */\n hidden?: boolean;\n};\n\n/**\n * The state of the action.\n * - off: A constant indicating the menu element is in the “off” state.\n * - on: A constant indicating the menu element is in the “on” state.\n * - mixed: A constant indicating the menu element is in the “mixed” state.\n */\ntype MenuState = 'off' | 'on' | 'mixed';\n\nexport type MenuAction = {\n /**\n * Identifier of the menu action.\n * The value set in this id will be returned when menu is selected.\n */\n id?: string;\n /**\n * The action's title.\n */\n title: string;\n /**\n * (Android only)\n * The action's title color.\n * @platform Android\n */\n titleColor?: number | ColorValue;\n /**\n * (iOS14+ only)\n * An elaborated title that explains the purpose of the action.\n * @platform iOS\n */\n subtitle?: string;\n /**\n * The attributes indicating the style of the action.\n */\n attributes?: MenuAttributes;\n /**\n * (iOS14+ only)\n * The state of the action.\n * @platform iOS\n */\n state?: MenuState;\n /**\n * (Android and iOS13+ only)\n * - The action's image.\n * - Allows icon name included in project or system (Android) resources drawables and\n * in SF Symbol (iOS)\n * @example // (iOS)\n * image=\"plus\"\n * @example // (Android)\n * image=\"ic_menu_add\"\n * - TODO: Allow images other than those included in SF Symbol and resources drawables\n */\n image?: string;\n /**\n * (Android and iOS13+ only)\n * - The action's image color.\n */\n imageColor?: number | ColorValue;\n /**\n * (Android and iOS14+ only)\n * - Actions to be displayed in the sub menu\n * - On Android it does not support nesting next sub menus in sub menu item\n */\n subactions?: MenuAction[];\n /**\n * Whether subactions should be inline (separated by divider) or nested (sub menu)\n */\n displayInline?: boolean;\n};\n\ntype MenuComponentPropsBase = {\n style?: StyleProp<ViewStyle>;\n /**\n * Callback function that will be called when selecting a menu item.\n * It will contain id of the given action.\n */\n onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;\n /**\n * Actions to be displayed in the menu.\n */\n actions: MenuAction[];\n /**\n * The title of the menu.\n */\n title?: string;\n /**\n * (Android API 23+)\n * Boolean value determines whether popup menu should be anchored\n * to right corner of parent view - default value is `false`\n * @platform Android\n */\n isAnchoredToRight?: boolean;\n /**\n * Determines if menu should open after long press or on normal press\n *\n * @default false\n */\n shouldOpenOnLongPress?: boolean;\n /**\n * Overrides theme variant of menu to light mode, dark mode or system theme\n * (Only support iOS for now)\n *\n * @platform iOS\n */\n themeVariant?: string;\n};\n\nexport type MenuComponentProps =\n React.PropsWithChildren<MenuComponentPropsBase>;\n\nexport type ProcessedMenuAction = Omit<\n MenuAction,\n 'imageColor' | 'titleColor' | 'subactions'\n> & {\n imageColor: ReturnType<typeof processColor>;\n titleColor: ReturnType<typeof processColor>;\n subactions?: ProcessedMenuAction[];\n};\n\nexport type NativeMenuComponentProps = {\n style?: StyleProp<ViewStyle>;\n onPressAction?: ({ nativeEvent }: NativeActionEvent) => void;\n actions: ProcessedMenuAction[];\n title?: string;\n};\n"],"mappings":""}
@@ -115,13 +115,12 @@ declare type MenuComponentPropsBase = {
115
115
  */
116
116
  shouldOpenOnLongPress?: boolean;
117
117
  /**
118
- * Determines if menu should be displayed in dark mode or light mode
118
+ * Overrides theme variant of menu to light mode, dark mode or system theme
119
119
  * (Only support iOS for now)
120
120
  *
121
- * @default false
122
121
  * @platform iOS
123
122
  */
124
- darkMode?: boolean;
123
+ themeVariant?: string;
125
124
  };
126
125
  export declare type MenuComponentProps = React.PropsWithChildren<MenuComponentPropsBase>;
127
126
  export declare type ProcessedMenuAction = Omit<MenuAction, 'imageColor' | 'titleColor' | 'subactions'> & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-menu/menu",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "UIMenu component for react-native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/types.ts CHANGED
@@ -125,13 +125,12 @@ type MenuComponentPropsBase = {
125
125
  */
126
126
  shouldOpenOnLongPress?: boolean;
127
127
  /**
128
- * Determines if menu should be displayed in dark mode or light mode
128
+ * Overrides theme variant of menu to light mode, dark mode or system theme
129
129
  * (Only support iOS for now)
130
130
  *
131
- * @default false
132
131
  * @platform iOS
133
132
  */
134
- darkMode?: boolean;
133
+ themeVariant?: string;
135
134
  };
136
135
 
137
136
  export type MenuComponentProps =