Skip to content

Commit 6492e71

Browse files
committed
Updated
1 parent 6d6f1bc commit 6492e71

20 files changed

+1199
-625
lines changed

Assets/UIFloatMenu-Banner.png

-873 Bytes
Loading

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- TextFieldCell
3232
- SwitchCell
3333
- SegmentCell
34+
- CustomCell
3435
```
3536

3637
Action item color
@@ -89,12 +90,14 @@ let actions: [UIFloatMenuAction] = [
8990
.init(item: .ActionCell(icon: UIImage(systemName: "arrow.right.square.fill")!, title: "Title", subtitle: "Test subtitle", layout: .Icon_Title), itemColor: .filled(.systemPurple), action: { _ in
9091
print("Action")
9192
}),
92-
.init(item: .HorizontalCell(items: h_actions, height: .standard))
93+
.init(item: .HorizontalCell(items: h_actions, height: .standard)),
94+
.init(item: .CustomCell(view: CustomViewRow(title: "Custom rows", subtitle: "View custom rows", icon: UIImage(systemName: "tablecells")!)), action: { _ in
95+
})
9396
]
9497

9598
let menu = UIFloatMenu.setup(actions: actions)
9699
menu.header.title = "UIFloatMenu title"
97-
menu.header.subTitle = "UIFloatMenu subtitle"
100+
menu.header.subtitle = "UIFloatMenu subtitle"
98101
menu.header.showHeader = true
99102
menu.header.showLine = true
100103
menu.header.lineInset = 15
@@ -127,7 +130,11 @@ menu.delegate.textField = self
127130
```
128131

129132
```swift
130-
func UIFloatMenuGetTextFieldData(_ data: [String]) {
131-
print("TextField -", data)
133+
func UIFloatMenuGetTextFieldData(_ rows: [TextFieldRow]) {
134+
let login = UIFloatMenuHelper.find(rows, by: "Login")
135+
let password = UIFloatMenuHelper.find(rows, by: "Password")
136+
137+
print("Login -", login)
138+
print("Password -", password)
132139
}
133140
```

Sources/UIFloatMenu.swift

Lines changed: 248 additions & 87 deletions
Large diffs are not rendered by default.

Sources/UIFloatMenuAction.swift

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55

66
import UIKit
77

8+
//MARK: - selectionConfig
9+
public enum selectionConfig {
10+
case multi(isSelected: Bool = false, selectedIcon: UIImage?, selectedTitle: String, defaultIcon: UIImage?, defaultTitle: String)
11+
case `default`(icon: UIImage? = nil, title: String)
12+
}
13+
14+
//MARK: - transition_style
15+
public enum transition_style {
16+
case `default`(animated: Bool = true)
17+
case fade
18+
}
19+
820
//MARK: - h_heightStyle
921
public enum h_heightStyle {
1022
case compact
@@ -53,18 +65,20 @@ public enum spacerType {
5365
case divider
5466
}
5567

68+
69+
5670
//MARK: - itemSetup
5771
public enum itemSetup {
5872
/**
5973
UIFloatMenu: ActionCell
6074

61-
- Parameter icon: Optional
62-
- Parameter title: Title
75+
- Parameter selection: selectionConfig **(.multi - with 2 state, .default)**
6376
- Parameter subtitle: Optional
6477
- Parameter layout: Loyout of cell (**.Title_Icon**, **.Icon_Title**), Default: **.Title_Icon**.
6578
- Parameter height: Height of cell (**.standard**, **.compact**), Default: **.standard**.
6679
*/
67-
case ActionCell(icon: UIImage? = nil, title: String, subtitle: String = "", layout: cellLayout = .Title_Icon, height: heightStyle = .standard)
80+
case ActionCell(selection: selectionConfig, subtitle: String = "", itemColor: itemColor = .standard,
81+
layout: cellLayout = .Icon_Title, height: heightStyle = .standard)
6882

6983
/**
7084
UIFloatMenu: Title
@@ -101,7 +115,7 @@ public enum itemSetup {
101115
- Parameter keyboard: UIKeyboardType
102116
*/
103117
case TextFieldCell(title: String = "", placeholder: String, isResponder: Bool = false,
104-
isSecure: Bool = false, content: UITextContentType? = nil, keyboard: UIKeyboardType = .default)
118+
isSecure: Bool = false, content: UITextContentType? = nil, keyboard: UIKeyboardType = .default, identifier: String = "")
105119

106120
/**
107121
UIFloatMenu: SwitchCell
@@ -110,7 +124,7 @@ public enum itemSetup {
110124
- Parameter title: Title
111125
- Parameter isOn: Is On at start
112126
- Parameter tintColor: Tint color
113-
- Parameter action: Action for Switch
127+
- Parameter action: Selector for Switch
114128
*/
115129
case SwitchCell(icon: UIImage? = nil, title: String, isOn: Bool = false, tintColor: UIColor = .systemBlue, action: Selector)
116130

@@ -120,16 +134,25 @@ public enum itemSetup {
120134
- Parameter title: Optional
121135
- Parameter items: Items **[UIImage, String]**
122136
- Parameter selected: Selected item
123-
- Parameter action: Action for SegmentControl
137+
- Parameter action: Selector for SegmentControl
124138
*/
125139
case SegmentCell(title: String = "", items: [Any], selected: Int = 0, action: Selector)
126140

127141
/**
128142
UIFloatMenu: HorizontalCell
129143

130-
- Parameter items: [UIFloatMenuAction]
144+
- Parameter items: actions [UIFloatMenuAction]
145+
- Parameter height: h_heightStyle
146+
- Parameter layout: h_cellLayout
131147
*/
132148
case HorizontalCell(items: [UIFloatMenuAction], height: h_heightStyle = .standard, layout: h_cellLayout = .center)
149+
150+
/**
151+
UIFloatMenu: CustomCell
152+
153+
- Parameter view: custom UIView
154+
*/
155+
case CustomCell(view: UIView)
133156
}
134157

135158
public typealias UIFloatMenuActionHandler = (UIFloatMenuAction) -> Void
@@ -142,11 +165,6 @@ public class UIFloatMenuAction {
142165
*/
143166
public var item: itemSetup
144167

145-
/**
146-
UIFloatMenu: itemColor
147-
*/
148-
public var itemColor: itemColor
149-
150168
/**
151169
UIFloatMenu: closeOnTap
152170
*/
@@ -157,14 +175,16 @@ public class UIFloatMenuAction {
157175
*/
158176
public var action: UIFloatMenuActionHandler?
159177

178+
/**
179+
UIFloatMenu: isSelected
180+
*/
181+
public var isSelected: Bool?
182+
160183
public init(item: itemSetup,
161-
itemColor: itemColor = .standard,
162184
closeOnTap: Bool = true,
163185
action: UIFloatMenuActionHandler? = nil) {
164186
self.item = item
165187

166-
self.itemColor = itemColor
167-
168188
self.closeOnTap = closeOnTap
169189
self.action = action
170190
}

Sources/UIFloatMenuAnimation.swift

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
//
2+
// UIFloatMenuAnimation.swift
3+
// UIFloatMenu
4+
//
5+
6+
import UIKit
7+
import Foundation
8+
9+
extension UIView {
10+
11+
public var _matchedTransition_layerAnimations: [CAAnimation] {
12+
(layer.animationKeys() ?? []).compactMap {
13+
layer.animation(forKey: $0)
14+
}
15+
}
16+
17+
public var isAnimatingByPropertyAnimator: Bool {
18+
(layer.animationKeys() ?? []).contains(where: {
19+
$0.hasPrefix("UIPacingAnimationForAnimatorsKey")
20+
})
21+
}
22+
23+
/**
24+
Returns a relative frame in view.
25+
*/
26+
public func _matchedTransition_relativeFrame(in view: UICoordinateSpace, ignoresTransform: Bool) -> CGRect {
27+
if ignoresTransform {
28+
CATransaction.begin()
29+
CATransaction.setDisableActions(true)
30+
31+
let currentTransform = transform
32+
let currentAlpha = alpha
33+
self.transform = .identity
34+
self.alpha = 0
35+
let rect = self.convert(bounds, to: view)
36+
self.transform = currentTransform
37+
self.alpha = currentAlpha
38+
39+
CATransaction.commit()
40+
return rect
41+
} else {
42+
let rect = self.convert(bounds, to: view)
43+
return rect
44+
}
45+
}
46+
47+
fileprivate func setFrameIgnoringTransforming(_ newFrame: CGRect) {
48+
bounds.size = newFrame.size
49+
center = newFrame.center
50+
}
51+
52+
}
53+
54+
extension UIViewPropertyAnimator {
55+
56+
public func addMovingAnimation(from fromView: UIView, to toView: UIView, sourceView: UIView, in containerView: UIView) {
57+
let fromFrameInContainerView = fromView._matchedTransition_relativeFrame(in: containerView, ignoresTransform: true)
58+
let toFrameInContainerView = toView._matchedTransition_relativeFrame(in: containerView, ignoresTransform: true)
59+
60+
if toView === sourceView {
61+
if toView.isAnimatingByPropertyAnimator == false {
62+
toView.transform = Self.makeCGAffineTransform(from: toFrameInContainerView, to: fromFrameInContainerView)
63+
}
64+
}
65+
66+
addAnimations {
67+
if fromView === sourceView {
68+
// sourceView(`fromView`) moves to `toView`.
69+
fromView.transform = Self.makeCGAffineTransform(from: fromFrameInContainerView, to: toFrameInContainerView)
70+
} else if toView === sourceView {
71+
// sourceView(`toView`) moves back from `fromView`.
72+
toView.transform = .identity
73+
} else {
74+
assertionFailure("sourceView must be either fromView or toView.")
75+
}
76+
}
77+
}
78+
79+
private static func makeCGAffineTransform(from: CGRect, to: CGRect) -> CGAffineTransform {
80+
return .init(
81+
a: to.width / from.width,
82+
b: 0,
83+
c: 0,
84+
d: to.height / from.height,
85+
tx: to.midX - from.midX,
86+
ty: to.midY - from.midY
87+
)
88+
}
89+
90+
}
91+
92+
extension CGRect {
93+
var center: CGPoint {
94+
return .init(x: midX, y: midY)
95+
}
96+
}

Sources/UIFloatMenuConfig.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public struct UIFloatMenuHeaderConfig {
111111
Default: **true**.
112112
*/
113113
public var showHeader: Bool
114-
public var image: UIImage?
115114

116115
/**
117116
UIFloatMenu: Title of header
@@ -121,7 +120,7 @@ public struct UIFloatMenuHeaderConfig {
121120
/**
122121
UIFloatMenu: Subtitle of header (optional)
123122
*/
124-
public var subTitle: String?
123+
public var subtitle: String?
125124

126125
/**
127126
UIFloatMenu: Show line under header
@@ -137,13 +136,12 @@ public struct UIFloatMenuHeaderConfig {
137136
*/
138137
public var lineInset: CGFloat
139138

140-
public init(showHeader: Bool = true, image: UIImage? = nil, title: String = "", subTitle: String? = "",
139+
public init(showHeader: Bool = true, title: String = "", subtitle: String? = "",
141140
showLine: Bool = true, lineInset: CGFloat = 15) {
142141
self.showHeader = showHeader
143-
self.image = image
144142

145143
self.title = title
146-
self.subTitle = subTitle
144+
self.subtitle = subtitle
147145

148146
self.showLine = showLine
149147
self.lineInset = lineInset
@@ -156,12 +154,14 @@ public struct UIFloatMenuQueue {
156154

157155
public var uuid: Int!
158156
public var viewHeight: CGFloat!
157+
public var header: UIFloatMenuHeaderConfig!
159158
public var config: UIFloatMenuConfig!
160159
public var actions: [UIFloatMenuAction]!
161160

162-
public init(uuid: Int, viewHeight: CGFloat = 0, config: UIFloatMenuConfig, actions: [UIFloatMenuAction]) {
161+
public init(uuid: Int, viewHeight: CGFloat = 0, header: UIFloatMenuHeaderConfig, config: UIFloatMenuConfig, actions: [UIFloatMenuAction]) {
163162
self.uuid = uuid
164163
self.viewHeight = viewHeight
164+
self.header = header
165165
self.config = config
166166
self.actions = actions
167167
}
@@ -174,13 +174,13 @@ class UIFloatMenuID {
174174
let shared = UIFloatMenuID()
175175

176176
static let backViewID = 100010001
177+
static let containerViewID = 11223300332211
177178

178179
static func genUUID(_ count: Int) -> Int {
179180
if count == 0 {
180181
return backViewID
181-
} else {
182-
return backViewID+count
183182
}
183+
return backViewID+count
184184
}
185185

186186
}
@@ -189,7 +189,16 @@ class UIFloatMenuColors {
189189

190190
let shared = UIFloatMenuColors()
191191

192-
static let mainColor = UIColor(named: "UIMenuMainColor")
192+
//static let mainColor = UIColor(named: "UIMenuMainColor")
193193
static let revColor = UIColor(named: "UIMenuRevColor")
194194

195+
static func mainColor() -> UIColor {
196+
let light = UIColor(red: 250/255, green: 250/255, blue: 249/255, alpha: 1)
197+
let dark = UIColor(red: 39/255, green: 44/255, blue: 49/255, alpha: 1)
198+
199+
return UIColor { (trait) -> UIColor in
200+
return trait.userInterfaceStyle == .light ? light : dark
201+
}
202+
}
203+
195204
}

0 commit comments

Comments
 (0)