FlowBinding 1.0
Tags: android, kotlin
Published: 2020-12-24 07:48:18

It's been over a year since the initial release of [FlowBinding](https://github.com/ReactiveCircus/FlowBinding/releases/tag/0.11.0).

Over the last year we've added 4 new artifacts for AndroidX libraries, dropped our minimum SDK all the way back to API 14, introduced a new `InitialValueFlow` API for widgets that emit state changes, and [new API docs](https://reactivecircus.github.io/FlowBinding/api/-modules.html).

Today I'm excited share the [1.0 stable release](https://github.com/ReactiveCircus/FlowBinding/releases/tag/1.0.0) of FlowBinding!

### What's new

While the majority of the APIs have remained the same since the first public release ([original blogpost](https://dev.to/ychescale9/binding-android-ui-with-kotlin-flow-22ok)) last year, we've made a decent amount of improvements to the library over the last 14 months.

#### New artifacts

Our focus has been on providing bindings for `flowbinding-material` which is where most of the new UI widgets are being developed, but we also added 4 new artifacts for AndroidX libraries:

- [flowbinding-activity](https://github.com/ReactiveCircus/FlowBinding/tree/main/flowbinding-activity) - provides binding on `OnBackPressedDispatcher` from [AndroidX Activity](https://developer.android.com/guide/components/activities/intro-activities)
- [flowbinding-lifecycle](https://github.com/ReactiveCircus/FlowBinding/tree/main/flowbinding-lifecycle) - turns lifecycle change events from [AndroidX Lifecycle](https://developer.android.com/topic/libraries/architecture/lifecycle) into `Flow<Lifecycle.Event>`
- [flowbinding-preference](https://github.com/ReactiveCircus/FlowBinding/tree/main/flowbinding-preference
) - provides bindings for `Preference` and `EditTextPreference` from [AndroidX Preference (Settings)](https://developer.android.com/guide/topics/ui/settings)
- [flowbinding-viewpager](https://github.com/ReactiveCircus/FlowBinding/tree/main/flowbinding-viewpager
) - backports bindings from `flowbinding-viewpager2` for the legacy `androidx.viewpager.widget.ViewPager` artifact.

#### Min SDK 14

Originally the `minSdkVersion` FlowBinding required was **API 21**. While this is reasonable for most users, support for lower API levels remains essential for users who are developing for emerging markets (see this [tweet](https://twitter.com/ychescale9/status/1232472676645535744) for more context).

We've now dropped our `minSdkVersion` to **API 14**.

#### Initial value

For UI widgets that hold a state internally such as the current value of a **Slider** (a recently added [Material Component](https://github.com/material-components/material-components-android/blob/master/docs/components/Slider.md)), our bindings used to provide an optional `emitImmediately: Boolean` to indicate whether the current value should be emitted **immediately** when collected:

```kotlin
@CheckResult
@UseExperimental(ExperimentalCoroutinesApi::class)
fun Slider.valueChanges(emitImmediately: Boolean = false): Flow<Float> = callbackFlow {
...
}
```

The default value of `emitImmediately` was `false` which [not everyone agrees](https://github.com/ReactiveCircus/FlowBinding/issues/94).

After discussions within the community we've decided to introduce a new `InitialValueFlow` for the bindings that emit state changes (many thanks to [Sven Jacobs](https://github.com/svenjacobs) for the idea).

An `InitialValueFlow` emits the current value (state) of the widget immediately upon collection of the Flow.

This effectively changed the previous default value of `emitImmediately` from `false` to `true`, but communicates the behavior more clearly in the type itself.

To skip the initial emission of the current value, call the `skipInitialValue()` function on the `InitialValueFlow`:

```kotlin
slider.valueChanges()
    .skipInitialValue()
    .onEach { value ->
        // handle value
    }
    .launchIn(uiScope) // current value won't be emitted immediately
```

This is also consistent with RxBinding's `InitialValueObservable`.

#### New API Docs

FlowBinding has many artifacts and APIs. We now have a new [project website](https://reactivecircus.github.io/FlowBinding/) that documents all transitive AndroidX dependencies and the bindings available in each artifact, along with [new API docs](https://reactivecircus.github.io/FlowBinding/api/-modules.html) powered by Dokka 1.4.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/my69kf34uhx4pm6kjfut.png)

### What's next?

Jetpack Compose is clearly the **future** of UI development for Android, while FlowBinding specifically targets the **current** generation of UI toolkits, which isn't going away anytime soon. The [material-components-android](https://github.com/material-components/material-components-android) library is still being actively developed with many new view-based components being added or planned.

Therefore we're planning to continue the work on maintaining AndroidX bindings and adding bindings for the new Material Design Components (e.g. [TimePicker](https://material.io/components/time-pickers/android#code)) as they become available.

### Thanks!

I'd like to thank everyone who has used FlowBinding, reported bugs, made feature requests, participated in discussions or sent PRs in the last 14 months, which all contributed to what we've achieved with the library today!