# InteractableComponent

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/InteractableComponent.kt+class:androidx.xr.scenecore.InteractableComponent) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
class InteractableComponent : Component
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.xr.scenecore.Component](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component) ||
|   | ↳ | [androidx.xr.scenecore.InteractableComponent](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InteractableComponent) |

*** ** * ** ***

Provides access to raw `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent`s for given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`, so a client can implement their own interaction logic.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InteractableComponent` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InteractableComponent#create(androidx.xr.runtime.Session,java.util.function.Consumer)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, inputEventListener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent>)` Public factory for creating an InteractableComponent. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InteractableComponent` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InteractableComponent#create(androidx.xr.runtime.Session,java.util.concurrent.Executor,java.util.function.Consumer)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, inputEventListener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent> )` Public factory for creating an InteractableComponent. |

| ### Protected functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InteractableComponent#onAttach(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Attaches this component to the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InteractableComponent#onDetach(androidx.xr.scenecore.Entity)(entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)` Detaches this component from the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. |

## Public companion functions

### create

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun create(session: Session, inputEventListener: Consumer<InputEvent>): InteractableComponent
```

Public factory for creating an InteractableComponent. It enables access to raw input events.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` to create the InteractableComponent in. |
| `inputEventListener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent>` | `https://developer.android.com/reference/java/util/function/Consumer.html` that accepts `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent`s. The listener callbacks will be invoked on the main thread. |

### create

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
fun create(
    session: Session,
    executor: Executor,
    inputEventListener: Consumer<InputEvent>
): InteractableComponent
```

Public factory for creating an InteractableComponent. It enables access to raw input events.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` to create the InteractableComponent in. |
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | Executor for invoking the inputEventListener. |
| `inputEventListener: https://developer.android.com/reference/java/util/function/Consumer.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent>` | `https://developer.android.com/reference/java/util/function/Consumer.html` that accepts `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent`s. |

## Protected functions

### onAttach

```
protected open fun onAttach(entity: Entity): Boolean
```

Attaches this component to the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`. When attached, the component begins listening for `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InputEvent`s on this `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`, and any descendant `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`s in its subgraph that do not have a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/InteractableComponent` attached to themselves.

| Parameters |
|---|---|
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` to attach this component to. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the component was successfully attached, `false` otherwise. |

### onDetach

```
protected open fun onDetach(entity: Entity): Unit
```

Detaches this component from the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity`.

| Parameters |
|---|---|
| `entity: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` to detach this component from. |