Improve InlineTextButton API

This commit is contained in:
Alfonso Grillo
2022-10-26 22:04:19 +02:00
parent d625a3f73a
commit da548fc314
3 changed files with 5 additions and 4 deletions
@@ -39,10 +39,11 @@ struct InlineTextButton: View {
/// - mainText: The main text that shouldn't appear tappable. This must contain a single `%@` placeholder somewhere within.
/// - tappableText: The tappable text that will be substituted into the `%@` placeholder.
/// - action: The action to perform when tapping the button.
internal init(_ mainText: String, tappableText: String, action: @escaping () -> Void) {
/// - alwaysCallAction: If true calls the action on tap action even if the `tappableText` isn't found inside the `mainText`
init(_ mainText: String, tappableText: String, alwaysCallAction: Bool = true, action: @escaping () -> Void) {
guard let range = mainText.range(of: "%@") else {
components = [StringComponent(string: Substring(mainText), isTinted: false)]
self.action = action
self.action = alwaysCallAction ? action : { }
return
}