Function

modifierLocalOf

Creates a ProvidableModifierLocal and specifies a default factory.

ModifierLocalParentChildCommunicationWithinLayoutNodeSample

@Sampled
@Composable
fun ModifierLocalParentChildCommunicationWithinLayoutNodeSample() {

    // Define the type of data.
    val ModifierLocalMessage = modifierLocalOf { "Unknown" }

    Box(
        Modifier
            // Provide an instance associated with the data type.
            .modifierLocalProvider(ModifierLocalMessage) { "World" }
            .composed {
                var message by remember { mutableStateOf("") }
                Modifier
                    // Use the data type to read the message.
                    .modifierLocalConsumer { message = ModifierLocalMessage.current }
                    .clickable { println("Hello $message") }
            }
    )
}

ModifierLocalChildParentCommunicationWithinLayoutNodeSample

@Sampled
@Composable
fun ModifierLocalChildParentCommunicationWithinLayoutNodeSample() {

    class Sender(val onMessageReceived: (String) -> Unit) {

ModifierLocalParentChildCommunicationInterLayoutNodeSample

@Sampled
@Composable
fun ModifierLocalParentChildCommunicationInterLayoutNodeSample() {

    // Define the type of data.
    val ModifierLocalMessage = modifierLocalOf { "Unknown" }

    Box(
        // Provide an instance associated with the data type.
        Modifier.modifierLocalProvider(ModifierLocalMessage) { "World" }
    ) {
        var message by remember { mutableStateOf("") }
        Box(
            Modifier
                // Use the data type to read the message.
                .modifierLocalConsumer { message = ModifierLocalMessage.current }
                .clickable { println("Hello $message") }
        )
    }
}

ModifierLocalChildParentCommunicationInterLayoutNodeSample

@Sampled
@Composable
fun ModifierLocalChildParentCommunicationInterLayoutNodeSample() {

    class Sender(val onMessageReceived: (String) -> Unit) {
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: