KeplerAppStateManager for interactive components to listen to app state changes.
Methods
useVegaAppStateManager
useKeplerAppStateManager() is a custom hook that returns a KeplerAppStateManager instance that can be used to query and listen to app state changes. Please follow the React’s Rules of Hooks when calling this hook.
useGetCurrentKeplerAppStateCallback = (): () => KeplerAppStateStatus
Deprecated. Use getCurrentState from VegaAppStateManager instead.
useGetCurrentKeplerAppStateCallback is a custom hook that returns a callback that, when invoked, returns the current app state of your interactive component. Please follow the React’s Rules of Hooks when calling this hook. The returned callback function takes no parameters and returns KeplerAppStateStatus, which is described below in the types section.
Note: Calling the hook does not return the app state. You have to invoke the callback function returned by the hook to get your interactive component’s app state.
useAddKeplerAppStateListenerCallback = (): KeplerAppStateCallback
Deprecated. Use addEventListener from VegaAppStateManager instead.
useAddKeplerAppStateListenerCallback is a custom hook that returns a callback that, when invoked, adds a listener for the given event. Please follow the React’s Rules of Hooks when calling this hook. The returned callback function, typed as KeplerAppStateCallback, takes two parameters, the event name (KeplerAppStateEvent) to subscribe to and the callback function (OnEventCallback) to invoke when the event occurs. The callback function returns a handle to the subscription. Call remove() to remove the subscription.
Note: Calling the hook does not register an app state listener. You have to invoke the callback function returned by the hook to register an app state listener.
Note: This method can also be called with aOnAppStateEventCallbackcallback (instead ofOnEventCallback), but this variant is deprecated.
useAddKeplerAppStateListenerWithReplayCallback = (): () => KeplerAppStateWithReplay
Deprecated. Use addEventListenerWithReplay from VegaAppStateManager instead.
useAddKeplerAppStateListenerWithReplayCallback is a custom hook that returns a callback that, when invoked, adds a listener for the given event. The callback is immediately invoked if any past events have occurred before the app subscribed to the listeners (events will be replayed). Otherwise it behaves like useAddVegaAppStateListenerCallback. Please follow the React’s Rules of Hooks when calling this hook. The returned callback function takes no parameters and returns KeplerAppStateWithReplay, which is described below in the types section.
Note: Replayed events will be sent in the order in which their respective listeners are added.
Note: Only the first listener of a particular event will receive the replayed event.
Note: Calling the hook does not register an app state listener. You have to invoke the callback function returned by the hook to register an app state listener.
useComponentInstance = (): () => IComponentInstance
Deprecated. Use getComponentInstance from VegaAppStateManager instead.
useComponentInstance is a custom hook that provides an interface, IComponentInstance, which represents an application component. This interface includes properties such as the component’s name and type.
Classes
VegaAppStateManager
getCurrentState()
getCurrentState returns the current app state of your interactive component. It takes no parameters and returns KeplerAppStateStatus, which is described below in the types section.
addEventListener()
addEventListener adds a listener for the given event. It takes two parameters, the event name (KeplerAppStateEvent) to subscribe to and the callback function (OnEventCallback) to invoke when the event occurs. Returns a handle to the subscription. Call remove() to remove the subscription.
This API is available starting from version 2.1.0 of @amazon-devices/react-native-kepler.
addAppStateListener()
Deprecated. Use addEventListener instead.
addAppStateListener adds a listener for the given event. It takes two parameters, the event name (KeplerAppStateEvent) to subscribe to and the callback function (OnEventCallback) to invoke when the event occurs. Returns a handle to the subscription. Call remove() to remove the subscription.
Note: This is an older api that has same functionality as addEventListener. Api is kept for backward compatibility.
addEventListenerWithReplay()
addEventListenerWithReplay adds a listener for the given event and this will capture and replay the events that came before it was attached.
Note: Replayed events will be sent in the order in which their respective listeners are added.
Note: Only the first listener of a particular event will receive the replayed event.
getComponentInstance()
getComponentInstance returns an interface of type IComponentInstance, which represents an application component. This interface includes properties such as the component’s name and type.
Types
type KeplerAppStateStatus = 'active' | 'background' | 'inactive' | 'unknown';
- active: The app is running in the foreground.
- background: The app is running in the background. The user is either in another app or on the home screen.
- inactive: This is a transition state that currently never happens for typical React Native apps.
- unknown : Initial value until the current app state is determined.
type KeplerAppStateEvent = 'change' | 'memoryWarning' | 'blur' | 'focus' | 'reconfigure' | 'displayChange';
- change: This even is received when the app state has changed.
- memoryWarning: Received when the app receives a memory warning.
- focus: Received when the app gains focus (the user is interacting with the app).
- blur: Received when the user is not actively interacting with the app.
- reconfigure: Received when an application reconfiguration event occurs.
- displayChange - Received when a display is connected or disconnected.

