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

androidx.ui.viewinterop

Top-level functions summary

Unit
AndroidView(@LayoutRes resId: Int, modifier: Modifier = Modifier, postInflationCallback: (View) -> Unit = { _ -> })

Composes an Android View given a layout resource resId.

Unit
AndroidView(view: View, modifier: Modifier = Modifier)

Composes an Android View.

Unit
emitView(ctor: (Context) -> T, update: (T) -> Unit)

Emit a view into the current composition.

Unit
emitView(ctor: (Context) -> T, update: (T) -> Unit, children: () -> Unit)

Emit a ViewGroup into the current composition, with the emitted nodes of children as the content.

Top-level functions

AndroidView

@Composable fun AndroidView(
    @LayoutRes resId: Int,
    modifier: Modifier = Modifier,
    postInflationCallback: (View) -> Unit = { _ -> }
): Unit

Composes an Android View given a layout resource resId. The method handles the inflation of the View and will call the postInflationCallback after this happens. Note that the callback will always be invoked on the main thread.

Parameters
resId: Int The id of the layout resource to be inflated.
modifier: Modifier = Modifier The modifier to be applied to the layout.
postInflationCallback: (View) -> Unit = { _ -> } The callback to be invoked after the layout is inflated.

AndroidView

@Composable fun AndroidView(
    view: View,
    modifier: Modifier = Modifier
): Unit

Composes an Android View.

Parameters
view: View The View to compose.
modifier: Modifier = Modifier The Modifier to be applied to the view.

emitView

@Composable fun <T : View> emitView(
    ctor: (Context) -> T,
    update: (T) -> Unit
): Unit

Emit a view into the current composition.

import androidx.ui.viewinterop.emitView

@Composable
fun Button(
    text: String,
    onClick: (() -> Unit)? = null
) {
    emitView<Button>(::Button) {
        it.text = text
        it.setOnClickListener(onClick?.let { View.OnClickListener { it() } })
    }
}
Parameters
ctor: (Context) -> T The constructor of the view with a single Context parameter.
update: (T) -> Unit A function which will execute when the composition is applied, with the emitted view instance passed in. This function is expected to be used to handle the "update" logic to handle any changes.

emitView

@Composable fun <T : ViewGroup> emitView(
    ctor: (Context) -> T,
    update: (T) -> Unit,
    children: () -> Unit
): Unit

Emit a ViewGroup into the current composition, with the emitted nodes of children as the content.

import androidx.ui.viewinterop.emitView

@Composable
fun LinearLayout(
    orientation: Int = android.widget.LinearLayout.VERTICAL,
    children: @Composable () -> Unit
) {
    emitView<LinearLayout>(::LinearLayout, { it.orientation = orientation }) {
        children()
    }
}
Parameters
ctor: (Context) -> T The constructor of the view with a single Context parameter.
update: (T) -> Unit A function which will execute when the composition is applied, with the emitted view instance passed in. This function is expected to be used to handle the "update" logic to handle any changes.
children: () -> Unit the composable content that will emit the "children" of this view.