You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 5, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
7
7
## [Unreleased]
8
+
9
+
## [2.3.0]
10
+
### Added
11
+
- Added support for Native environment. Now if the service is initialized with `nativeMode` flag, it will skip creating window event listeners, measuring coordinates and other web-only features. It will still continue to register all focusable components and update `focused` flag on them.
12
+
- Added new method `stealFocus` to `withFocusable` hoc. It works exactly the same as `setFocus` apart from that it doesn't care about arguments passed to this method. This is useful when binding it to a callback that passed some params back that you don't care about.
13
+
14
+
## [2.2.1]
8
15
### Changed
9
16
- Improved the main navigation algorithm. Instead of calculating distance between center of the borders between 2 items in the direction of navigation, the new algorithm now prioritises the distance by the main coordinate and then takes into account the distance by the secondary coordinate. Inspired by this [algorithm](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS_for_TV/TV_remote_control_navigation#Algorithm_design)
Since in native environment the focus is controlled by the native engine, we can only "sync" with it by setting focus on the component itself when it gets focused.
142
+
Native navigation system automatically converts all `Touchable` component to focusable components and enhances them with the callbacks such as `onFocus` and `onBlur`.
143
+
Read more here: [React Native on TVs](https://facebook.github.io/react-native/docs/building-for-apple-tv).
Native mode should be only used to keep the tree of focusable components and to sync the `focused` flag to enable styling for focused components.
196
+
In Native mode you can only `stealFocus` to some component to flag it as `focused`, normal `setFocus` method is blocked because it will not propagate to native layer.
197
+
198
+
***false (default)**
199
+
***true**
200
+
167
201
### `setKeyMap`: function
168
202
Function to set custom key codes.
169
203
```jsx
@@ -182,14 +216,14 @@ Main HOC wrapper function. Accepts [config](#config) as a param.
Determine whether to track when any child component is focused. Wrapped component can rely on `hasFocusedChild` prop when this mode is enabled. Otherwise `hasFocusedChild` will be always `false`.
188
222
189
223
***false (default)** - Disabled by default because it causes unnecessary render call when `hasFocusedChild` changes
190
224
***true**
191
225
192
-
### `forgetLastFocusedChild`: boolean
226
+
#####`forgetLastFocusedChild`: boolean
193
227
Determine whether this component should not remember the last focused child components. By default when focus goes away from the component and then it gets focused again, it will focus the last focused child. This functionality is enabled by default.
194
228
195
229
***false (default)**
@@ -263,13 +297,26 @@ Whether component is currently focused. It is only `true` if this exact componen
263
297
This prop indicates that the component currently has some focused child on any depth of the focusable tree.
264
298
265
299
### `setFocus`: function
266
-
This method sets the focus to another component (when focus key is passed as param) or steals the focus to itself (when used w/o params). It is also possible to set focus to a non-existent component, and it will be automatically picked up when component with that focus key will get mounted. This preemptive setting of the focus might be useful when rendering lists of data. You can assign focus key with the item index and set it to e.g. first item, then as soon as it will be rendered, that item will get focused.
300
+
This method sets the focus to another component (when focus key is passed as param) or steals the focus to itself (when used w/o params). It is also possible to set focus to a non-existent component, and it will be automatically picked up when component with that focus key will get mounted.
301
+
This preemptive setting of the focus might be useful when rendering lists of data.
302
+
You can assign focus key with the item index and set it to e.g. first item, then as soon as it will be rendered, that item will get focused.
303
+
In Native mode this method is ignored (`noop`).
267
304
268
305
```jsx
269
306
setFocus(); // set focus to self
270
307
setFocus('SOME_COMPONENT'); // set focus to another component if you know its focus key
271
308
```
272
309
310
+
### `stealFocus`: function
311
+
This method works exactly like `setFocus`, but it always sets focus to current component no matter which params you pass in.
312
+
This is the only way to set focus in Native mode.
313
+
314
+
```jsx
315
+
<TouchableOpacity
316
+
onFocus={stealFocus}
317
+
/>
318
+
```
319
+
273
320
### `pauseSpatialNavigation`: function
274
321
This function pauses key listeners. Useful when you need to temporary disable navigation. (e.g. when player controls are hidden during video playback and you want to bind the keys to show controls again).
275
322
@@ -302,21 +349,19 @@ Source code is in `src/App.js`
302
349
303
350
### `spatialNavigation` Service
304
351
* New components are added in `addFocusable`and removed in `removeFocusable`
305
-
* Main function to change focus is `setFocus`. First it decides next focus key (`getNextFocusKey`), then set focus to the new component (`setCurrentFocusedKey`), then the service updates all components that has focused child and finally updates layout (coordinates and dimensions) for all focusable component.
352
+
* Main function to change focus in web environment is `setFocus`. First it decides next focus key (`getNextFocusKey`), then set focus to the new component (`setCurrentFocusedKey`), then the service updates all components that has focused child and finally updates layout (coordinates and dimensions) for all focusable component.
306
353
*`getNextFocusKey` is used to determine the good candidate to focus when you call `setFocus`. This method will either return the target focus key for the component you are trying to focus, or go down by the focusable tree and select the best child component to focus. This function is recoursive and going down by the focusable tree.
307
354
*`smartNavigate` is similar to the previous one, but is called in response to a key press event. It tries to focus the best sibling candidate in the direction of key press, or delegates this task to a focusable parent, that will do the same attempt for its sibling and so on.
355
+
* In Native environment the only way to set focus is `stealFocus`. This service mostly works as a "sync" between native navigation system and JS to apply `focused` state and keep the tree structure of focusable components. All the layout and coordinates measurement features are disabled because native engine takes care of it.
308
356
309
357
## Contributing
310
358
Please follow the [Contribution Guide](https://github.com/NoriginMedia/react-spatial-navigation/blob/master/CONTRIBUTING.md)
311
359
312
360
# TODOs
313
-
-[x] Get rid of `propagateFocus`, because it is used in 99% of the times when component has children
314
361
-[ ] Unit tests
315
-
-[x] Implement more advanced coordination calculation [algorithm](https://developer.mozilla.org/en-US/docs/Mozilla/Firefox_OS_for_TV/TV_remote_control_navigation#Algorithm_design).
316
362
-[ ] Refactor with React Hooks instead of recompose.
317
-
-[ ] Implement HOC for react-native tvOS and AndroidTV components.
363
+
-[x] Native environment support
318
364
-[ ] Add custom navigation logic per component. I.e. possibility to override default decision making algorithm and decide where to navigate next based on direction.
319
-
-[x] Add "preferable focused component" feature for components with children. By default it's first element, but it is useful to customize this behaviour.
320
365
-[ ] Implement mouse support. On some TV devices (or in the Browser) it is possible to use mouse-like input, e.g. magic remote in LG TVs. This system should support switching between "key" and "pointer" modes and apply "focused" state accordingly.
0 commit comments