@momo-kits/native-kits 0.162.2-beta.21 → 0.162.2-beta.22
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/ios/Button/Button.swift +47 -23
- package/package.json +1 -3
package/ios/Button/Button.swift
CHANGED
|
@@ -125,7 +125,12 @@ public struct Button: View {
|
|
|
125
125
|
var iconRight: AnyView?
|
|
126
126
|
var isFull: Bool
|
|
127
127
|
var loading: Bool
|
|
128
|
+
var iconOnly: Bool
|
|
128
129
|
|
|
130
|
+
/// When `iconOnly` is true the label is hidden and the button collapses to a compact,
|
|
131
|
+
/// icon-sized box (it ignores `isFull`). `title` stays required and is exposed as the
|
|
132
|
+
/// accessibility label. Supply the glyph via `iconLeft` (preferred) or `iconRight`;
|
|
133
|
+
/// while `loading` the spinner replaces the icon.
|
|
129
134
|
public init(
|
|
130
135
|
title: String = "",
|
|
131
136
|
action: @escaping () -> Void,
|
|
@@ -134,7 +139,8 @@ public struct Button: View {
|
|
|
134
139
|
iconLeft: AnyView? = nil,
|
|
135
140
|
iconRight: AnyView? = nil,
|
|
136
141
|
isFull: Bool = true,
|
|
137
|
-
loading: Bool = false
|
|
142
|
+
loading: Bool = false,
|
|
143
|
+
iconOnly: Bool = false
|
|
138
144
|
) {
|
|
139
145
|
self.title = title
|
|
140
146
|
self.action = action
|
|
@@ -144,6 +150,7 @@ public struct Button: View {
|
|
|
144
150
|
self.iconRight = iconRight
|
|
145
151
|
self.isFull = isFull
|
|
146
152
|
self.loading = loading
|
|
153
|
+
self.iconOnly = iconOnly
|
|
147
154
|
}
|
|
148
155
|
|
|
149
156
|
private func shouldLoadingOnLeft(_ left: AnyView?, _ right: AnyView?) -> Bool {
|
|
@@ -166,35 +173,46 @@ public struct Button: View {
|
|
|
166
173
|
let border = type.borderColor
|
|
167
174
|
let borderWidth = type.borderWidth
|
|
168
175
|
|
|
169
|
-
SwiftUI.Button(action: {
|
|
176
|
+
let button = SwiftUI.Button(action: {
|
|
170
177
|
if !loading, type != .disabled {
|
|
171
178
|
action()
|
|
172
179
|
}
|
|
173
180
|
}) {
|
|
174
181
|
HStack(spacing: size.iconSpacing) {
|
|
175
|
-
if
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
iconLeft
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
182
|
+
if iconOnly {
|
|
183
|
+
if loading {
|
|
184
|
+
LottieView(name: "lottie_circle_loader", loopMode: .loop)
|
|
185
|
+
.frame(width: size.iconSize, height: size.iconSize)
|
|
186
|
+
.colorMultiply(fg)
|
|
187
|
+
|
|
188
|
+
} else if let icon = iconLeft ?? iconRight {
|
|
189
|
+
icon.frame(width: size.iconSize, height: size.iconSize)
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
if loading && loadingOnLeft {
|
|
193
|
+
LottieView(name: "lottie_circle_loader", loopMode: .loop)
|
|
194
|
+
.frame(width: size.iconSize, height: size.iconSize)
|
|
195
|
+
.colorMultiply(fg)
|
|
196
|
+
|
|
197
|
+
} else if let iconLeft = iconLeft {
|
|
198
|
+
iconLeft.frame(width: size.iconSize, height: size.iconSize)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
MomoText(title, typography: size.typographyStyle, color: fg)
|
|
202
|
+
.lineLimit(1)
|
|
203
|
+
.truncationMode(.tail)
|
|
204
|
+
|
|
205
|
+
if loading && !loadingOnLeft {
|
|
206
|
+
LottieView(name: "lottie_circle_loader", loopMode: .loop)
|
|
207
|
+
.frame(width: size.iconSize, height: size.iconSize)
|
|
208
|
+
.colorMultiply(fg)
|
|
209
|
+
|
|
210
|
+
} else if let iconRight = iconRight {
|
|
211
|
+
iconRight.frame(width: size.iconSize, height: size.iconSize)
|
|
212
|
+
}
|
|
195
213
|
}
|
|
196
214
|
}
|
|
197
|
-
.frame(maxWidth: isFull ? .infinity : nil)
|
|
215
|
+
.frame(maxWidth: isFull && !iconOnly ? .infinity : nil)
|
|
198
216
|
.padding(.horizontal, size.padding)
|
|
199
217
|
.frame(height: size.height)
|
|
200
218
|
.background(bg)
|
|
@@ -206,5 +224,11 @@ public struct Button: View {
|
|
|
206
224
|
.opacity(loading ? 0.75 : 1)
|
|
207
225
|
}
|
|
208
226
|
.disabled(type == .disabled || loading)
|
|
227
|
+
|
|
228
|
+
if iconOnly {
|
|
229
|
+
button.accessibilityLabel(Text(title))
|
|
230
|
+
} else {
|
|
231
|
+
button
|
|
232
|
+
}
|
|
209
233
|
}
|
|
210
234
|
}
|