Google se compromete a impulsar la igualdad racial para las comunidades afrodescendientes. Obtén información al respecto.

androidx.compose.ui.viewinterop

Top-level functions summary

Unit
AndroidView(factory: (Context) -> T, modifier: Modifier = Modifier, update: (T) -> Unit = NoOpUpdate)

Composes an Android View obtained from factory.

Unit
AndroidViewBinding(factory: (inflater: LayoutInflater, parent: ViewGroup, attachToParent: Boolean) -> T, modifier: Modifier = Modifier, update: T.() -> Unit = {})

Composes an Android layout resource in the presence of ViewBinding.

Top-level properties summary

View.() -> Unit

An empty update block used by AndroidView.

Top-level functions

AndroidView

@Composable fun <T : View> AndroidView(
    factory: (Context) -> T,
    modifier: Modifier = Modifier,
    update: (T) -> Unit = NoOpUpdate
): Unit

Composes an Android View obtained from factory. The factory block will be called exactly once to obtain the View to be composed, and it is also guaranteed to be invoked on the UI thread. Therefore, in addition to creating the factory, the block can also be used to perform one-off initializations and View constant properties' setting. The update block can be run multiple times (on the UI thread as well) due to recomposition, and it is the right place to set View properties depending on state. When state changes, the block will be reexecuted to set the new properties. Note the block will also be ran once right after the factory block completes.

import android.widget.TextView
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.viewinterop.AndroidView

// Compose a TextView.
AndroidView({ context -> TextView(context).apply { text = "This is a TextView" } })
// Compose a View and update its size based on state. Note the modifiers.
var size by remember { mutableStateOf(20) }
AndroidView(::View, Modifier.clickable { size += 20 }.background(Color.Blue)) { view ->
    view.layoutParams = ViewGroup.LayoutParams(size, size)
}
Parameters
factory: (Context) -> T The block creating the View to be composed.
modifier: Modifier = Modifier The modifier to be applied to the layout.
update: (T) -> Unit = NoOpUpdate The callback to be invoked after the layout is inflated.

AndroidViewBinding

@Composable fun <T : ViewBinding> AndroidViewBinding(
    factory: (inflater: LayoutInflater, parent: ViewGroup, attachToParent: Boolean) -> T,
    modifier: Modifier = Modifier,
    update: T.() -> Unit = {}
): Unit

Composes an Android layout resource in the presence of ViewBinding. The binding is obtained from the factory block, which will be called exactly once to obtain the ViewBinding to be composed, and it is also guaranteed to be invoked on the UI thread. Therefore, in addition to creating the ViewBinding, the block can also be used to perform one-off initializations and View constant properties' setting. The update block can be run multiple times (on the UI thread as well) due to recomposition, and it is the right place to set View properties depending on state. When state changes, the block will be reexecuted to set the new properties. Note the block will also be ran once right after the factory block completes.

import androidx.compose.ui.viewinterop.AndroidViewBinding

// Inflates and composes sample_layout.xml and changes the color of the `second` View.
// The `second` View is part of sample_layout.xml.
AndroidViewBinding(SampleLayoutBinding::inflate) {
    second.setBackgroundColor(Color.GRAY)
}
Parameters
factory: (inflater: LayoutInflater, parent: ViewGroup, attachToParent: Boolean) -> T The block creating the ViewBinding to be composed.
modifier: Modifier = Modi