Created
November 6, 2022 15:39
-
-
Save asissuthar/234e73d6835fd88a203ddaf23900e43d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.asissuthar.validation.formfields | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.asStateFlow | |
abstract class FormField<T> { | |
protected val stateInternal = MutableStateFlow<T?>(null) | |
// state is StateFlow. It will be helpful for collecting any change in current value. | |
val state = stateInternal.asStateFlow() | |
protected val isValidInternal = MutableStateFlow(true) | |
// isValid is StateFlow. It will be helpful for collecting any change in validation process. | |
val isValid = isValidInternal.asStateFlow() | |
// We will call validate method, when we want to perform validation. | |
abstract suspend fun validate(focusIfError: Boolean = true): Boolean | |
open fun clearError() {} | |
open fun clearFocus() {} | |
open fun disable() {} | |
open fun enable() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment