Often times I find myself observing simple values from LiveData or Rx observables and setting them to view items like TextViews or EditTexts. Or setting visibility of a Button or TextView.
Post values in ViewModelObserve values in MainActivity
Well, it looks ugly to me. We can do it more readable. RxSwift has bind() function to simply do this operation.
It binds ViewModel value to Label or Image Field
In order to achieve something similar, we can use Extension functions. So I created a file that called ReactiveBindExtensions in our project.
Here are some of the functions
With the help of these extension functions, we can convert our bindings into much readable and clean version. Even cleaner than RxSwift bind() function 🙂
Makes binding much readable
You can find the sample extension code in this gist.
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