https://kotlinlang.org logo
#android
Title
# android
k

Katarzyna

06/30/2022, 11:26 AM
Recently, Mustafa wrote a rule-based validation structure for all my inputs. It’s very flexible and manageable. Today he will try to explain the validator library. Read the article written by Mustafa Yigit. 👇 validator | Rule Based Validation Library in Android | by Mustafa Yiğit | Jun, 2022 | Kt. Academy (kotlin-academy.com)
k

kotlinforandroid

06/30/2022, 11:42 AM
I like the idea of validation happening in the business/logic layer of an app. But the library here pulls in strings on that layer, which is IMO not the right approach. Since this is an Android specific slack, I'd probably store resource IDs instead of the string and pull the string on the UI layer. What I did was expose the form properties using
StateFlow
. One for an error message of type @StringRes, one called
hasError
. That way you can even observe the values in compose and re-compose if needed. And the date is updated using simple callbacks or state delegation.
1
4 Views