icerockdev / moko-widgets

Multiplatform UI DSL with screen management in common code for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev
Apache License 2.0
387 stars 32 forks source link

Improve extensibility of core ViewFactories #224

Open Alex009 opened 4 years ago

Alex009 commented 4 years ago

Now each core ViewFactory is final classes, all actions doing in buildView function. It's reason why we should copy-paste core factories for small customization, even when we want change small piece of view building logic. I suggest to do core factories is open classes with open functions which show each step of building. Example API of InputViewFactory: common:

expect open class SystemInputViewFactory

android:

actual open class SystemInputViewFactory {
    open fun createEditText(context: Context): EditText
    open fun applyBackground(editText: EditText)
    open fun applyMargins(editText: EditText)
    open fun applyPaddings(editText: EditText)
    open fun applyTextStyle(editText: EditText)
    open fun applyAlignment(editText: EditText)
    open fun bindFormField(editText: EditText, formField: FormField)
    open fun bindLabel(editText: EditText, label: LiveData)
    open fun bindEnabled(editText: EditText, enabled: LiveData)
    open fun bindMaxLines(editText: EditText, maxLines: LiveData)
}

something like on android will be and for ios.

this change allow us to just create subclass of core factory without duplication of all logic and simple change some piece, for example create custom EditText from some library, not just system