Skip to content

Commit f3ebb77

Browse files
committed
Merge branch 'master' of ssh://github.com/react-native-menu/menu
2 parents d862640 + 08212f5 commit f3ebb77

File tree

5 files changed

+452
-420
lines changed

5 files changed

+452
-420
lines changed

ios/MenuView.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MenuView: UIButton {
2323
self.setup()
2424
}
2525
}
26-
26+
2727
private var _title: String = "";
2828
@objc var title: NSString? {
2929
didSet {
@@ -35,35 +35,35 @@ class MenuView: UIButton {
3535
}
3636
}
3737
@objc var onPressAction: RCTDirectEventBlock?
38-
38+
3939
@objc var shouldOpenOnLongPress: Bool = false {
4040
didSet {
4141
self.setup()
4242
}
4343
}
44-
44+
4545
override init(frame: CGRect) {
4646
super.init(frame: frame)
4747
self.setup()
4848
}
4949

50-
50+
5151
func setup () {
52-
let menu = UIMenu(title:_title, identifier: nil, options: .displayInline, children: self._actions)
52+
let menu = UIMenu(title:_title, identifier: nil, children: self._actions)
5353

5454
self.menu = menu
5555
self.showsMenuAsPrimaryAction = !shouldOpenOnLongPress
5656
}
57-
57+
5858
override func reactSetFrame(_ frame: CGRect) {
5959
super.reactSetFrame(frame);
6060
};
61-
62-
61+
62+
6363
required init?(coder aDecoder: NSCoder) {
6464
fatalError("init(coder:) has not been implemented")
6565
}
66-
66+
6767
@objc func sendButtonAction(_ action: UIAction) {
6868
if let onPress = onPressAction {
6969
onPress(["event":action.identifier.rawValue])

ios/RCTMenuItem.swift

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,45 @@ import UIKit;
99

1010
@available(iOS 13.0, *)
1111
class RCTMenuAction {
12-
12+
1313
var identifier: UIAction.Identifier?;
1414
var title: String;
1515
var subtitle: String?
16+
var displayInline: Bool
1617
var image: UIImage?
1718
var attributes: UIAction.Attributes = []
1819
var state: UIAction.State = .off
1920
var subactions: [RCTMenuAction] = []
20-
21+
2122
init(details: NSDictionary){
22-
23+
2324
if let identifier = details["id"] as? NSString {
2425
self.identifier = UIAction.Identifier(rawValue: identifier as String);
2526
}
26-
27+
2728
if let image = details["image"] as? NSString {
2829
self.image = UIImage(systemName: image as String);
2930
if let imageColor = details["imageColor"] {
3031
self.image = self.image?.withTintColor(RCTConvert.uiColor(imageColor), renderingMode: .alwaysOriginal)
3132
}
3233
}
33-
34+
3435
if let title = details["title"] as? NSString {
3536
self.title = title as String;
3637
} else {
3738
self.title = "";
3839
}
39-
40+
4041
if let subtitle = details["subtitle"] as? NSString {
4142
self.subtitle = subtitle as String;
4243
}
43-
44+
45+
if let displayInline = details["displayInline"] as? Bool {
46+
self.displayInline = displayInline as Bool;
47+
} else {
48+
self.displayInline = false;
49+
}
50+
4451
if let attributes = details["attributes"] as? NSDictionary {
4552
if (attributes["destructive"] as? Bool) == true {
4653
self.attributes.update(with: .destructive)
@@ -52,7 +59,7 @@ class RCTMenuAction {
5259
self.attributes.update(with: .hidden)
5360
}
5461
}
55-
62+
5663
if let state = details["state"] as? NSString {
5764
if state=="on" {
5865
self.state = .on
@@ -64,25 +71,29 @@ class RCTMenuAction {
6471
self.state = .mixed
6572
}
6673
}
67-
74+
6875
if let subactions = details["subactions"] as? NSArray {
6976
if subactions.count > 0 {
7077
for subaction in subactions {
7178
self.subactions.append(RCTMenuAction(details: subaction as! NSDictionary))
7279
}
7380
}
7481
}
75-
76-
82+
83+
7784
}
78-
85+
7986
func createUIMenuElement(_ handler: @escaping UIActionHandler) -> UIMenuElement {
8087
if subactions.count > 0 {
8188
var subMenuActions: [UIMenuElement] = []
8289
subactions.forEach { subaction in
8390
subMenuActions.append(subaction.createUIMenuElement(handler))
8491
}
85-
return UIMenu(title: title, image: image, identifier: nil, children: subMenuActions)
92+
if self.displayInline {
93+
return UIMenu(title: title, image: image, options: .displayInline, children: subMenuActions)
94+
} else {
95+
return UIMenu(title: title, image: image, children: subMenuActions)
96+
}
8697
}
8798
return UIAction(title: title, image: image, identifier: identifier, discoverabilityTitle: subtitle, attributes: attributes, state: state, handler: handler)
8899
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@types/jest": "^29.1.2",
4949
"@types/react": "^17.0.1",
5050
"@types/react-native": "0.67.6",
51-
"eslint": "8.25.0",
51+
"eslint": "8.26.0",
5252
"eslint-config-prettier": "^8.1.0",
5353
"eslint-plugin-prettier": "^4.2.1",
5454
"jest": "^29.1.2",

src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ export type MenuAction = {
9090
* - On Android it does not support nesting next sub menus in sub menu item
9191
*/
9292
subactions?: MenuAction[];
93+
/**
94+
* Whether subactions should be inline (separated by divider) or nested (sub menu)
95+
*/
96+
displayInline?: boolean;
9397
};
9498

9599
type MenuComponentPropsBase = {

0 commit comments

Comments
 (0)