Skip to content

Commit 3ba417d

Browse files
committed
Fix #10
1 parent a6fb178 commit 3ba417d

File tree

5 files changed

+61
-14
lines changed

5 files changed

+61
-14
lines changed

Example/Example/View Controllers/Helper/PopMenuExamples.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ final class PopMenuExamples {
196196
PopMenuDefaultAction(title: "Add to Cart", image: #imageLiteral(resourceName: "Cart_Add"), color: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)),
197197
PopMenuDefaultAction(title: "Save to List", image: #imageLiteral(resourceName: "Plus"), color: #colorLiteral(red: 0.9764705896, green: 0.850980401, blue: 0.5490196347, alpha: 1)),
198198
PopMenuDefaultAction(title: "Favorite", image: #imageLiteral(resourceName: "Heart"), color: #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)),
199-
PopMenuDefaultAction(title: "Add to Cart", image: #imageLiteral(resourceName: "Cart_Add"), color: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1))
199+
PopMenuDefaultAction(title: "Add to Cart", image: #imageLiteral(resourceName: "Cart_Add"), color: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)),
200+
PopMenuDefaultAction(title: "Last Action", image: #imageLiteral(resourceName: "Download"), color: #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1))
200201
]
201202

202203
let popMenu = PopMenuViewController(actions: actions)

PopMenu/Classes/PopMenuAppearance.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ final public class PopMenuAppearance: NSObject {
3535

3636
/// How many actions are the breakpoint to trigger scrollable.
3737
public var popMenuActionCountForScrollable: UInt = 6
38+
39+
/// The scroll indicator style when the actions are scrollable.
40+
public var popMenuScrollIndicatorStyle: UIScrollView.IndicatorStyle = .white
41+
42+
/// Hide the scroll indicator or not when the actions are scrollable.
43+
public var popMenuScrollIndicatorHidden = false
3844

3945
/// The separator style for each action.
4046
public var popMenuItemSeparator: PopMenuActionSeparator = .none()

PopMenu/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.1.2</string>
18+
<string>2.1.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

PopMenu/View Controller & Views/PopMenuViewController.swift

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,10 @@ extension PopMenuViewController {
323323
fileprivate func calculateContentFittingFrame() -> CGRect {
324324
var height: CGFloat
325325

326-
if actions.count >= 6 {
326+
if actions.count >= appearance.popMenuActionCountForScrollable {
327327
// Make scroll view
328328
height = CGFloat(appearance.popMenuActionCountForScrollable) * appearance.popMenuActionHeight
329+
height -= 20
329330
} else {
330331
height = CGFloat(actions.count) * appearance.popMenuActionHeight
331332
}
@@ -424,8 +425,6 @@ extension PopMenuViewController {
424425

425426
/// Setup actions view.
426427
fileprivate func configureActionsView() {
427-
actionsView.addGestureRecognizer(panGestureForMenu)
428-
429428
actionsView.translatesAutoresizingMaskIntoConstraints = false
430429
actionsView.axis = .vertical
431430
actionsView.alignment = .fill
@@ -451,14 +450,45 @@ extension PopMenuViewController {
451450
actionsView.addArrangedSubview(action.view)
452451
}
453452

454-
contentView.addSubview(actionsView)
455-
456-
NSLayoutConstraint.activate([
457-
actionsView.leftAnchor.constraint(equalTo: contentView.leftAnchor),
458-
actionsView.rightAnchor.constraint(equalTo: contentView.rightAnchor),
459-
actionsView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 4),
460-
actionsView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -4)
461-
])
453+
// Check add scroll view or not
454+
if actions.count >= (appearance.popMenuActionCountForScrollable) {
455+
// Scrollable actions
456+
let scrollView = UIScrollView()
457+
scrollView.translatesAutoresizingMaskIntoConstraints = false
458+
scrollView.showsHorizontalScrollIndicator = false
459+
scrollView.showsVerticalScrollIndicator = !appearance.popMenuScrollIndicatorHidden
460+
scrollView.indicatorStyle = appearance.popMenuScrollIndicatorStyle
461+
scrollView.contentSize.height = appearance.popMenuActionHeight * CGFloat(actions.count)
462+
463+
scrollView.addSubview(actionsView)
464+
contentView.addSubview(scrollView)
465+
466+
NSLayoutConstraint.activate([
467+
scrollView.leftAnchor.constraint(equalTo: contentView.leftAnchor),
468+
scrollView.topAnchor.constraint(equalTo: contentView.topAnchor),
469+
scrollView.rightAnchor.constraint(equalTo: contentView.rightAnchor),
470+
scrollView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
471+
])
472+
473+
NSLayoutConstraint.activate([
474+
actionsView.leftAnchor.constraint(equalTo: contentView.leftAnchor),
475+
actionsView.rightAnchor.constraint(equalTo: contentView.rightAnchor),
476+
actionsView.topAnchor.constraint(equalTo: scrollView.topAnchor),
477+
actionsView.heightAnchor.constraint(equalToConstant: scrollView.contentSize.height)
478+
])
479+
} else {
480+
// Not scrollable
481+
actionsView.addGestureRecognizer(panGestureForMenu)
482+
483+
contentView.addSubview(actionsView)
484+
485+
NSLayoutConstraint.activate([
486+
actionsView.leftAnchor.constraint(equalTo: contentView.leftAnchor),
487+
actionsView.rightAnchor.constraint(equalTo: contentView.rightAnchor),
488+
actionsView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 4),
489+
actionsView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -4)
490+
])
491+
}
462492
}
463493

464494
/// Add separator view for the given action view.

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ You can, however, choose either way to have the same result, whichever works bes
112112

113113
[Basic Usage - Using Manager](#using-manager)
114114

115-
[Basic Usage - Using Controller](#using-controller)
115+
[Basic Usage - Using Controller (Recommended)](#using-controller)
116116

117117
-------
118118

@@ -493,7 +493,17 @@ To set the action item image sizing:
493493
let action = PopMenuDefaultAction(title: "Some Title", image: UIImage(named: "blah"), color: .gray)
494494
action.iconWidthHeight = 45
495495
```
496+
Scrollable when actions are more than 6 or custom
497+
---------
498+
499+
To set the scrolling properties:
496500

501+
```swift
502+
// The manual way
503+
menu.appearance.popMenuActionCountForScrollable = 10 // default 6
504+
menu.appearance.popMenuScrollIndicatorHidden = true // default false
505+
menu.appearance.popMenuScrollIndicatorStyle = .black // default .white
506+
```
497507
Status Bar Style // Default: automatic detection based on background color
498508
---------
499509

0 commit comments

Comments
 (0)