Created
March 2, 2023 04:45
-
-
Save akshaykalola28/26a4e896558c4b7534192d837ff102c0 to your computer and use it in GitHub Desktop.
Kotlin Extension functions for handling the view visibility in android
This file contains 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
import android.view.View | |
fun View.gone() = run { visibility = View.GONE } | |
fun View.visible() = run { visibility = View.VISIBLE } | |
fun View.invisible() = run { visibility = View.INVISIBLE } | |
infix fun View.visibleIf(condition: Boolean) = | |
run { visibility = if (condition) View.VISIBLE else View.GONE } | |
infix fun View.goneIf(condition: Boolean) = | |
run { visibility = if (condition) View.GONE else View.VISIBLE } | |
infix fun View.invisibleIf(condition: Boolean) = | |
run { visibility = if (condition) View.INVISIBLE else View.VISIBLE } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another one I used before: