{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

PlatformTextInputPluginRegistryImpl

@InternalTextApi
public final class PlatformTextInputPluginRegistryImpl implements PlatformTextInputPluginRegistry


Implementation of PlatformTextInputPluginRegistry that manages a map of adapters to cached services and allows retrieval of the first active one.

Summary

Nested types

Public constructors

Public methods

final PlatformTextInputAdapter

Returns the currently-focused adapter, or null if no adapter is focused.

final @NonNull PlatformTextInputPluginRegistryImpl.AdapterHandle<@NonNull T>

Returns the text input service T managed by plugin.

@NonNull T

Returns an instance of the PlatformTextInputAdapter type T specified by plugin.

Public constructors

PlatformTextInputPluginRegistryImpl

public PlatformTextInputPluginRegistryImpl(
    @NonNull Function2<@NonNull PlatformTextInputPlugin<@NonNull ?>, @NonNull PlatformTextInput, @NonNull PlatformTextInputAdapter> factory
)
Parameters
@NonNull Function2<@NonNull PlatformTextInputPlugin<@NonNull ?>, @NonNull PlatformTextInput, @NonNull PlatformTextInputAdapter> factory

A platform-specific function that invokes the appropriate create method on a PlatformTextInputAdapter to return a service.

Public methods

getFocusedAdapter

public final PlatformTextInputAdapter getFocusedAdapter()

Returns the currently-focused adapter, or null if no adapter is focused.

An adapter can request input focus by calling PlatformTextInput.requestInputFocus. It will keep input focus until either:

  1. It calls PlatformTextInput.releaseInputFocus, or

  2. Another adapter calls PlatformTextInput.requestInputFocus.

getOrCreateAdapter

@InternalTextApi
public final @NonNull PlatformTextInputPluginRegistryImpl.AdapterHandle<@NonNull T> <T extends PlatformTextInputAdapter> getOrCreateAdapter(
    @NonNull PlatformTextInputPlugin<@NonNull T> plugin
)

Returns the text input service T managed by plugin.

The first time this method is called for a given PlatformTextInputAdapter, the adapter's platform-specific factory method is called to instantiate the service. The service is then added to the cache and returned. Subsequent calls passing the same adapter, over the entire lifetime of this service provider, will return the same service instance. It is expected that adapters will be singleton objects, and in most apps there will only ever be one or maybe two input adapters in use, since each input adapter represents an entire text input subsystem.

Parameters
<T extends PlatformTextInputAdapter>

The type of the PlatformTextInputAdapter that plugin creates.

@NonNull PlatformTextInputPlugin<@NonNull T> plugin

The factory for service objects and the key into the cache of those objects.

rememberAdapter

@Composable
public @NonNull T <T extends PlatformTextInputAdapter> rememberAdapter(
    @NonNull PlatformTextInputPlugin<@NonNull T> plugin
)

Returns an instance of the PlatformTextInputAdapter type T specified by plugin.

The returned adapter instance will be shared by all callers of this method passing the same plugin object. The adapter will be created when the first call is made, then cached and returned by every subsequent call in the same or subsequent compositions. When there are no longer any calls to this method for a given plugin, the adapter instance will be PlatformTextInputAdapter.onDisposed.

Parameters
<T extends PlatformTextInputAdapter>

The type of PlatformTextInputAdapter that plugin creates.

@NonNull PlatformTextInputPlugin<@NonNull T> plugin

The factory for adapters and the key into the cache of those adapters.