# 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)

*** ** * ** ***


```
public final class InteractableComponent extends Component
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.xr.scenecore.Component](https://developer.android.com/reference/androidx/xr/scenecore/Component) ||
|   | ↳ | [androidx.xr.scenecore.InteractableComponent](https://developer.android.com/reference/androidx/xr/scenecore/InteractableComponent) |

*** ** * ** ***

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

## Summary

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

| ### Protected methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/xr/scenecore/InteractableComponent#onAttach(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity)` Attaches this component to the given `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |
| `void` | `https://developer.android.com/reference/androidx/xr/scenecore/InteractableComponent#onDetach(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity entity)` Detaches this component from the given `https://developer.android.com/reference/androidx/xr/scenecore/Entity`. |

## Public methods

### create

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

```
public static final @NonNull InteractableComponent create(
    @NonNull Session session,
    @NonNull Consumer<@NonNull InputEvent> inputEventListener
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | `https://developer.android.com/reference/androidx/xr/runtime/Session` to create the InteractableComponent in. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/function/Consumer.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/InputEvent> inputEventListener` | `https://developer.android.com/reference/java/util/function/Consumer.html` that accepts `https://developer.android.com/reference/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)

```
public static final @NonNull InteractableComponent create(
    @NonNull Session session,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull InputEvent> inputEventListener
)
```

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

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

## Protected methods

### onAttach

```
protected boolean onAttach(@NonNull Entity entity)
```

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

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

| Returns |
|---|---|
| `boolean` | `true` if the component was successfully attached, `false` otherwise. |

### onDetach

```
protected void onDetach(@NonNull Entity entity)
```

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

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