androidx.compose.runtime.rxjava2

Extension functions summary

State<Boolean>

Subscribes to this Completable and represents its completed state via State.

State<R>
@Composable
<R : Any?, T : R> Flowable<T>.subscribeAsState(initial: R)

Subscribes to this Flowable and represents its values via State.

State<R>
@Composable
<R : Any?, T : R> Maybe<T>.subscribeAsState(initial: R)

Subscribes to this Maybe and represents its value via State.

State<R>
@Composable
<R : Any?, T : R> Observable<T>.subscribeAsState(initial: R)

Subscribes to this Observable and represents its values via State.

State<R>
@Composable
<R : Any?, T : R> Single<T>.subscribeAsState(initial: R)

Subscribes to this Single and represents its value via State.

Extension functions

subscribeAsState

@Composable
fun Completable.subscribeAsState(): State<Boolean>

Subscribes to this Completable and represents its completed state via State. Once the Completable will be completed the returned State will be updated with true value causing recomposition of every State.value usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default RxJavaPlugins.onError logic will be used. To handle the error in a more meaningful way you can use operators like Completable.onErrorComplete or Completable.onErrorResumeNext.

import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val completed by completable.subscribeAsState()
Text("Completable is $completed")

subscribeAsState

@Composable
fun <R : Any?, T : R> Flowable<T>.subscribeAsState(initial: R): State<R>

Subscribes to this Flowable and represents its values via State. Every time there would be new value posted into the Flowable the returned State will be updated causing recomposition of every State.value usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default RxJavaPlugins.onError logic will be used. To handle the error in a more meaningful way you can use operators like Flowable.onErrorReturn or Flowable.onErrorResumeNext.

import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val value: String by flowable.subscribeAsState("initial")
Text("Value is $value")
Parameters
initial: R

The initial value for the returned State which will be asynchronously updated with the real one once we receive it from the stream

subscribeAsState

@Composable
fun <R : Any?, T : R> Maybe<T>.subscribeAsState(initial: R): State<R>

Subscribes to this Maybe and represents its value via State. Once the value would be posted into the Maybe the returned State will be updated causing recomposition of every State.value usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default RxJavaPlugins.onError logic will be used. To handle the error in a more meaningful way you can use operators like Maybe.onErrorComplete, Maybe.onErrorReturn or Maybe.onErrorResumeNext.

import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val value: String by maybe.subscribeAsState("initial")
Text("Value is $value")
Parameters
initial: R

The initial value for the returned State which will be asynchronously updated with the real one once we receive it from the stream

subscribeAsState

@Composable
fun <R : Any?, T : R> Observable<T>.subscribeAsState(initial: R): State<R>

Subscribes to this Observable and represents its values via State. Every time there would be new value posted into the Observable the returned State will be updated causing recomposition of every State.value usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default RxJavaPlugins.onError logic will be used. To handle the error in a more meaningful way you can use operators like Observable.onErrorReturn or Observable.onErrorResumeNext.

import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val value: String by observable.subscribeAsState("initial")
Text("Value is $value")
Parameters
initial: R

The initial value for the returned State which will be asynchronously updated with the real one once we receive it from the stream

subscribeAsState

@Composable
fun <R : Any?, T : R> Single<T>.subscribeAsState(initial: R): State<R>

Subscribes to this Single and represents its value via State. Once the value would be posted into the Single the returned State will be updated causing recomposition of every State.value usage.

The internal observer will be automatically disposed when this composable disposes.

Note that errors are not handled and the default RxJavaPlugins.onError logic will be used. To handle the error in a more meaningful way you can use operators like Single.onErrorReturn or Single.onErrorResumeNext.

import androidx.compose.material.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

val value: String by single.subscribeAsState("initial")
Text("Value is $value")
Parameters
initial: R

The initial value for the returned State which will be asynchronously updated with the real one once we receive it from the stream