From 2ddd960ee2f88d92fd161174f2b0fab9dff59b4d Mon Sep 17 00:00:00 2001 From: Robin Lemaire Date: Fri, 8 Nov 2024 11:23:11 +0100 Subject: [PATCH] [Counter] Add the counter for TextFieldAddonsUIView --- Package.swift | 9 +++++++++ Sources/Core/View/UIKit/FormFieldUIView.swift | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Package.swift b/Package.swift index 0e5ad07..25e9a9f 100644 --- a/Package.swift +++ b/Package.swift @@ -25,6 +25,11 @@ let package = Package( // path: "../spark-ios-common" /*version*/ "0.0.1"..."999.999.999" ), + .package( + url: "https://github.com/adevinta/spark-ios-component-text-input.git", + // path: "../spark-ios-component-text-input" + /*version*/ "0.0.1"..."999.999.999" + ), .package( url: "https://github.com/adevinta/spark-ios-theming.git", // path: "../spark-ios-theming" @@ -39,6 +44,10 @@ let package = Package( name: "SparkCommon", package: "spark-ios-common" ), + .product( + name: "SparkTextInput", + package: "spark-ios-component-text-input" + ), .product( name: "SparkTheming", package: "spark-ios-theming" diff --git a/Sources/Core/View/UIKit/FormFieldUIView.swift b/Sources/Core/View/UIKit/FormFieldUIView.swift index 475c411..2a81999 100644 --- a/Sources/Core/View/UIKit/FormFieldUIView.swift +++ b/Sources/Core/View/UIKit/FormFieldUIView.swift @@ -11,6 +11,7 @@ import SwiftUI import UIKit @_spi(SI_SPI) import SparkCommon import SparkTheming +import SparkTextInput // TODO: compression resistance @@ -412,3 +413,15 @@ public extension FormFieldUIView where Component: UITextInput { self.viewModel.setCounter(text: text, limit: limit) } } + +public extension FormFieldUIView where Component: TextFieldAddonsUIView { + + // MARK: - Public Setter + + /// Display a counter value (X/Y) in the secondary helper label with a text and the limit. + /// - parameter text: the text where the characters must be counted. + /// - parameter limit: the counter limit. If the value is nil, the counter is not displayed. + func setCounter(on text: String?, limit: Int?) { + self.viewModel.setCounter(text: text, limit: limit) + } +}