Recently, Mustafa wrote a rule-based validation st...
# android
k
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
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