FocusManager module provides custom focus management functionality based on You.i TV’s module.
It aims to provide a way for you to change the way focus transitions occur between components, as compared to the default behavior in React Native. APIs are imperative in nature as they help app developers separate business logic from layout logic.
Example usage
The following example is adapted from this You.i TV demo.Methods
getFocused()
setNextFocus()
fromTag to the component indicated by toTag.
The list of possible directions is as follows:
ComponentOrHandleType is the same for every method. It could be either:
- component’s ref (e.g. from
useRef)- however, due to type checking issues, this will cause transpiler issue, see known issues section
- component’s id (e.g. value from
findNodeHandle)
clearNextFocus()
fromTag.
If direction parameter is not provided, it defaults to ‘all’ which clears focus for all directions.
setFocusRoot()
tag and its children.
isFocusRoot- true if the component should be a focus root; false otherwise.
focus()
tag into focus.
blur()
tag from focus.
Known issues
- Calling these APIs from the
useEffecthook can fail the first time that the component is mounted. This occurs due to a known issue in Vega whereuseEffectcan execute earlier than expected. You can work around this issue by adding a timeout/delay to youruseEffectlogic. tag*parameters of the api accept either ref or the tag of the component. However, there is an issue with typechecking if a ref is used directly. Please usefindNodeHandleas shown in example to resolve type related issues. You would get error similar to this one:src/App.tsx:15:32 - error TS2345: Argument of type 'TouchableOpacity' is not assignable to parameter of type 'ComponentOrHandleType'.

