@@ -176,117 +176,116 @@ public struct OUDSButton: View {
176176
177177 // MARK: Initializers
178178
179- /// Creates a button with text and icon.
179+ // swiftlint:disable function_default_parameter_at_end
180+ /// Creates a button with a localized text and icon, looking up the key in the given bundle..
181+ /// A raw string can also be given to be displayed.
182+ ///
183+ /// ```swift
184+ /// // Use localizable
185+ /// OUDSButton(LocalizedStringKey("validate_button"), bundle: Bundle.module, icon: Image("ic_checkmark"), appearance: .strong) { }
186+ /// ```
180187 ///
181188 /// - Parameters:
182- /// - text: The text to display in the button
189+ /// - key: A `LocalizedStringKey` used to look up the text in the given bundle, or a raw `String` to display
190+ /// - tableName: The name of the `.strings` file, or `nil` for the default
191+ /// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
183192 /// - icon: An image which shoud contains an icon
184193 /// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
185194 /// - appearance: The button appearance, default set to `.default`
186195 /// - style: The button style, default set to `.default`
187196 /// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
188197 /// - action: The action to perform when the user triggers the button
189- public init ( text: String ,
198+ public init ( _ key: LocalizedStringKey ,
199+ tableName: String ? = nil ,
200+ bundle: Bundle = . main,
190201 icon: Image ,
191202 flipIcon: Bool = false ,
192203 appearance: Appearance = . default,
193204 style: Style = . default,
194205 isFullWidth: Bool = false ,
195206 action: @escaping ( ) -> Void )
196207 {
197- type = . textAndIcon( text: text, icon: icon, flipIcon: flipIcon)
198- self . appearance = appearance
199- self . style = style
200- self . isFullWidth = isFullWidth
201- self . action = action
202- isHover = false
208+ let resolvedText = key. resolved ( tableName: tableName, bundle: bundle)
209+ self . init ( text: resolvedText, icon: icon, flipIcon: flipIcon, style: style, isFullWidth: isFullWidth, action: action)
203210 }
204211
205- // swiftlint:disable function_default_parameter_at_end
206- /// Creates a button with a localized text and icon, looking up the key in the given bundle..
207- /// A raw string can also be given to be displayed.
208- ///
209- /// ```swift
210- /// // Use localizable
211- /// OUDSButton(LocalizedStringKey("validate_button"), bundle: Bundle.module, icon: Image("ic_checkmark"), appearance: .strong) { }
212- /// ```
212+ // swiftlint:enable function_default_parameter_at_end
213+
214+ /// Creates a button with text and icon.
213215 ///
214216 /// - Parameters:
215- /// - key: A `LocalizedStringKey` used to look up the text in the given bundle, or a raw `String` to display
216- /// - tableName: The name of the `.strings` file, or `nil` for the default
217- /// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
217+ /// - text: The text to display in the button
218218 /// - icon: An image which shoud contains an icon
219219 /// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
220220 /// - appearance: The button appearance, default set to `.default`
221221 /// - style: The button style, default set to `.default`
222222 /// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
223223 /// - action: The action to perform when the user triggers the button
224- public init ( _ key: LocalizedStringKey ,
225- tableName: String ? = nil ,
226- bundle: Bundle = . main,
224+ public init ( text: String ,
227225 icon: Image ,
228226 flipIcon: Bool = false ,
229227 appearance: Appearance = . default,
230228 style: Style = . default,
231229 isFullWidth: Bool = false ,
232230 action: @escaping ( ) -> Void )
233231 {
234- let resolvedText = key. resolved ( tableName: tableName, bundle: bundle)
235- type = . textAndIcon( text: resolvedText, icon: icon, flipIcon: flipIcon)
232+ type = . textAndIcon( text: text, icon: icon, flipIcon: flipIcon)
236233 self . appearance = appearance
237234 self . style = style
238235 self . isFullWidth = isFullWidth
239236 self . action = action
240237 isHover = false
241238 }
242239
243- // swiftlint:enable function_default_parameter_at_end
244-
245240 /// Creates a button with an icon only.
246241 ///
247242 /// - Parameters:
248243 /// - icon: An image which shoud contains an icon
249- /// - accessibilityLabel: The text to vocalize with *Voice Over* describing the button action
244+ /// - key: The text to vocalize with *Voice Over* describing the button action, as as `LocalizedStringKey` for the given `Bundle`
245+ /// - tableName: The name of the `.strings` file, or `nil` for the default
246+ /// - bundle: The bundle in which to look up the localized string. Defaults to `Bundle.main`.
250247 /// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
251248 /// - appearance: The button appearance, default set to `.default`
252249 /// - style: The button style, default set to `.default`
253250 /// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
254251 /// - action: The action to perform when the user triggers the button
255252 public init ( icon: Image ,
256- accessibilityLabel: String ,
253+ accessibilityLabel key: LocalizedStringKey ,
254+ tableName: String ? = nil ,
255+ bundle: Bundle = . main,
257256 flipIcon: Bool = false ,
258257 appearance: Appearance = . default,
259258 style: Style = . default,
260259 isFullWidth: Bool = false ,
261260 action: @escaping ( ) -> Void )
262261 {
263- type = . icon( icon, flipIcon: flipIcon, accessibilityLabel)
264- self . appearance = appearance
265- self . style = style
266- self . isFullWidth = isFullWidth
267- self . action = action
268- isHover = false
262+ let resolvedText = key. resolved ( tableName: tableName, bundle: bundle)
263+ self . init ( icon: icon, accessibilityLabel: resolvedText, flipIcon: flipIcon, appearance: appearance, style: style, isFullWidth: isFullWidth, action: action)
269264 }
270265
271- /// Create a button with a text only.
266+ /// Creates a button with an icon only.
272267 ///
273268 /// - Parameters:
274- /// - text: The text of the button to display
269+ /// - icon: An image which shoud contains an icon
270+ /// - accessibilityLabel: The text to vocalize with *Voice Over* describing the button action
271+ /// - flipIcon: Default set to `false`, set to `true` to reverse the image (i.e. flip vertically)
275272 /// - appearance: The button appearance, default set to `.default`
276273 /// - style: The button style, default set to `.default`
277274 /// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
278275 /// - action: The action to perform when the user triggers the button
279- public init ( text: String ,
276+ public init ( icon: Image ,
277+ accessibilityLabel: String ,
278+ flipIcon: Bool = false ,
280279 appearance: Appearance = . default,
281280 style: Style = . default,
282281 isFullWidth: Bool = false ,
283282 action: @escaping ( ) -> Void )
284283 {
285- type = . text ( text )
284+ type = . icon ( icon , flipIcon : flipIcon , accessibilityLabel )
286285 self . appearance = appearance
287286 self . style = style
288- self . action = action
289287 self . isFullWidth = isFullWidth
288+ self . action = action
290289 isHover = false
291290 }
292291
@@ -313,7 +312,24 @@ public struct OUDSButton: View {
313312 action: @escaping ( ) -> Void )
314313 {
315314 let resolvedText = key. resolved ( tableName: tableName, bundle: bundle)
316- type = . text( resolvedText)
315+ self . init ( text: resolvedText, appearance: appearance, style: style, isFullWidth: isFullWidth, action: action)
316+ }
317+
318+ /// Create a button with a text only.
319+ ///
320+ /// - Parameters:
321+ /// - text: The text of the button to display
322+ /// - appearance: The button appearance, default set to `.default`
323+ /// - style: The button style, default set to `.default`
324+ /// - isFullWidth: Flag to let button take all the screen width, set to *false* by default.
325+ /// - action: The action to perform when the user triggers the button
326+ public init ( text: String ,
327+ appearance: Appearance = . default,
328+ style: Style = . default,
329+ isFullWidth: Bool = false ,
330+ action: @escaping ( ) -> Void )
331+ {
332+ type = . text( text)
317333 self . appearance = appearance
318334 self . style = style
319335 self . action = action
0 commit comments