# androidx.compose.foundation.content

Common/AllAndroid/JVM

## Interfaces

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/ReceiveContentListener` | A set of callbacks for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/contentReceiver.modifier#(androidx.compose.ui.Modifier).contentReceiver(androidx.compose.foundation.content.ReceiveContentListener)` modifier to get information about certain Drag-and-Drop state changes, as well as receiving the payload carrying `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent`. | Cmn |

## Classes

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/MediaType` | Type identifier for contents that are transferable between applications or processes. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/PlatformTransferableContent` | All the platform-specific information regarding a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` that cannot be abstracted away in a platform agnostic way. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` | Represents content that can be transferred between applications or processes. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent.Source` | Defines the type of operation that a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` originates from. | Cmn |

## Modifiers

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/contentReceiver.modifier` | Configures the current node and any children nodes as a Content Receiver. | Cmn |

## Extension functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent?` | `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/ExperimentalFoundationApi https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent.https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/package-summary#(androidx.compose.foundation.content.TransferableContent).consume(kotlin.Function1)(predicate: (https://developer.android.com/reference/android/content/ClipData.Item.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Helper function to consume parts of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` in Android by splitting it to `https://developer.android.com/reference/android/content/ClipData.Item.html` parts. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/ExperimentalFoundationApi https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent.https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/package-summary#(androidx.compose.foundation.content.TransferableContent).hasMediaType(androidx.compose.foundation.content.MediaType)(mediaType: https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/MediaType)` Returns whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` can provide an item with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/package-summary#(androidx.compose.foundation.content.TransferableContent).hasMediaType(androidx.compose.foundation.content.MediaType)`. | Cmn android |

## Extension functions

### TransferableContent.consume

android Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/content/TransferableContent.android.kt+function:consume)

```
@ExperimentalFoundationApi
fun TransferableContent.consume(predicate: (ClipData.Item) -> Boolean): TransferableContent?
```

Helper function to consume parts of `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` in Android by splitting it to `https://developer.android.com/reference/android/content/ClipData.Item.html` parts. Use this function in `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/contentReceiver.modifier#(androidx.compose.ui.Modifier).contentReceiver(androidx.compose.foundation.content.ReceiveContentListener)` modifier's `onReceive` callback to easily separate remaining parts from incoming `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent`.

```kotlin
import androidx.compose.foundation.Image
import androidx.compose.foundation.content.MediaType
import androidx.compose.foundation.content.consume
import androidx.compose.foundation.content.contentReceiver
import androidx.compose.foundation.content.hasMediaType
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.input.rememberTextFieldState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap

val state = rememberTextFieldState()
var images by remember { mutableStateOf<List<ImageBitmap>>(emptyList()) }
Column {
    Row { images.forEach { Image(bitmap = it, contentDescription = null) } }
    BasicTextField(
        state = state,
        modifier =
            Modifier.contentReceiver { transferableContent ->
                if (!transferableContent.hasMediaType(MediaType.Image)) {
                    return@contentReceiver transferableContent
                }
                val newImages = mutableListOf<ImageBitmap>()
                transferableContent
                    .consume { item ->
                        // only consume this item if we can read an imageBitmap
                        item.readImageBitmap()?.let {
                            newImages += it
                            true
                        } ?: false
                    }
                    .also { images = newImages }
            },
    )
}
```

| Parameters |
|---|---|
| `predicate: (https://developer.android.com/reference/android/content/ClipData.Item.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Decides whether to consume or leave the given item out. Return true to indicate that this particular item was processed here, it shouldn't be passed further down the content receiver chain. Return false to keep it in the returned `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent`. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent?` | Remaining parts of this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent`. |

### TransferableContent.hasMediaType

Cmn android Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/content/TransferableContent.+function:hasMediaType)

```
@ExperimentalFoundationApi
fun TransferableContent.hasMediaType(mediaType: MediaType): Boolean
```

Returns whether this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/TransferableContent` can provide an item with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/content/package-summary#(androidx.compose.foundation.content.TransferableContent).hasMediaType(androidx.compose.foundation.content.MediaType)`.