Google is committed to advancing racial equity for Black communities. See how.

androidx.compose.runtime.rxjava2

Extension functions summary

For io.reactivex.Completable
State<Boolean>
Completable.subscribeAsState()

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

For io.reactivex.Flowable
State<T?>
Flowable<T>.subscribeAsState()

Subscribes to this Flowable and represents its values via State.

State<R>
Flowable<T>.subscribeAsState(initial: R)

Subscribes to this Flowable and represents its values via State.

For io.reactivex.Maybe
State<T?>
Maybe<T>.subscribeAsState()

Subscribes to this Maybe and represents its value via State.

State<R>
Maybe<T>.subscribeAsState(initial: R)

Subscribes to this Maybe and represents its value via State.

For io.reactivex.Observable
State<T?>
Observable<T>.subscribeAsState()

Subscribes to this Observable and represents its values via State.

State<R>
Observable<T>.subscribeAsState(initial: R)

Subscribes to this Observable and represents its values via State.

For io.reactivex.Single
State<T?>
Single<T>.subscribeAsState()

Subscribes to this Single and represents its value via State.

State<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.foundation.Text
import androidx.compose.runtime.rxjava2.subscribeAsState

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

subscribeAsState

@Composable inline fun <T : Any> Flowable<T>.subscribeAsState(): State<T?>

Deprecated.

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.

subscribeAsState

@Composable fun <R, 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.foundation.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 inline fun <T : Any> Maybe<T>.subscribeAsState(): State<T?>

Deprecated.

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.

subscribeAsState

@Composable fun <R, 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.foundation.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 inline fun <T : Any> Observable<T>.subscribeAsState(): State<T?>

Deprecated.

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.

subscribeAsState

@Composable fun <R, 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.foundation.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 inline fun <T : Any> Single<T>.subscribeAsState(): State<T?>

Deprecated.

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.

subscribeAsState

@Composable fun <R, 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.foundation.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