Skip to content

Commit 84d11bd

Browse files
committed
refactor: rename navigationStrategy to nextFocusResolver
Made-with: Cursor
1 parent e17ccdb commit 84d11bd

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

packages/core/src/SpatialNavigation.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export type NodeType = NodeTypeOverrides extends { node: infer N }
3737

3838
export type Direction = 'up' | 'down' | 'left' | 'right';
3939

40-
export type NavigationStrategy = (
40+
export type NextFocusResolver = (
4141
direction: Direction,
4242
focusKey: string,
4343
siblings: FocusableComponent[]
@@ -118,7 +118,7 @@ export interface FocusableComponent {
118118
focusBoundaryDirections?: Direction[];
119119
autoRestoreFocus: boolean;
120120
forceFocus: boolean;
121-
navigationStrategy?: NavigationStrategy;
121+
nextFocusResolver?: NextFocusResolver;
122122
lastFocusedChildKey?: string;
123123
layout?: FocusableComponentLayout;
124124
layoutUpdatedAt?: number;
@@ -136,7 +136,7 @@ interface FocusableComponentUpdatePayload {
136136
onArrowRelease: (direction: string) => void;
137137
onFocus: (layout: FocusableComponentLayout, details: FocusDetails) => void;
138138
onBlur: (layout: FocusableComponentLayout, details: FocusDetails) => void;
139-
navigationStrategy?: NavigationStrategy;
139+
nextFocusResolver?: NextFocusResolver;
140140
}
141141

142142
interface FocusableComponentRemovePayload {
@@ -1129,16 +1129,16 @@ export class SpatialNavigationService {
11291129

11301130
let nextComponent: FocusableComponent | null = null;
11311131

1132-
const { navigationStrategy } =
1132+
const { nextFocusResolver } =
11331133
this.focusableComponents[parentFocusKey] ?? {};
11341134

1135-
if (navigationStrategy) {
1135+
if (nextFocusResolver) {
11361136
const siblings = filter(
11371137
this.focusableComponents,
11381138
(component) =>
11391139
component.parentFocusKey === parentFocusKey && component.focusable
11401140
);
1141-
nextComponent = navigationStrategy(
1141+
nextComponent = nextFocusResolver(
11421142
direction as Direction,
11431143
focusKey,
11441144
siblings
@@ -1147,7 +1147,7 @@ export class SpatialNavigationService {
11471147
if (this.debug) {
11481148
this.log(
11491149
'smartNavigate',
1150-
'navigation overrided by navigationStrategy',
1150+
'navigation overrided by nextFocusResolver',
11511151
nextComponent
11521152
);
11531153
}
@@ -1425,7 +1425,7 @@ export class SpatialNavigationService {
14251425
focusable,
14261426
isFocusBoundary,
14271427
focusBoundaryDirections,
1428-
navigationStrategy
1428+
nextFocusResolver
14291429
}: FocusableComponent) {
14301430
this.focusableComponents[focusKey] = {
14311431
focusKey,
@@ -1439,7 +1439,7 @@ export class SpatialNavigationService {
14391439
onBlur,
14401440
onUpdateFocus,
14411441
onUpdateHasFocusedChild,
1442-
navigationStrategy,
1442+
nextFocusResolver,
14431443
saveLastFocusedChild,
14441444
trackChildren,
14451445
preferredChildFocusKey,
@@ -1807,7 +1807,7 @@ export class SpatialNavigationService {
18071807
onArrowPress,
18081808
onFocus,
18091809
onBlur,
1810-
navigationStrategy
1810+
nextFocusResolver
18111811
}: FocusableComponentUpdatePayload
18121812
) {
18131813
const component = this.focusableComponents[focusKey];
@@ -1822,7 +1822,7 @@ export class SpatialNavigationService {
18221822
component.onArrowPress = onArrowPress;
18231823
component.onFocus = onFocus;
18241824
component.onBlur = onBlur;
1825-
component.navigationStrategy = navigationStrategy;
1825+
component.nextFocusResolver = nextFocusResolver;
18261826
// Reset layout updated at to force a layout update
18271827
component.layoutUpdatedAt = 0;
18281828

packages/react/src/useFocusable.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
FocusDetails,
1414
KeyPressDetails,
1515
Direction,
16-
NavigationStrategy
16+
NextFocusResolver
1717
} from '@noriginmedia/norigin-spatial-navigation-core';
1818
import { useFocusContext } from './useFocusContext';
1919

@@ -57,7 +57,7 @@ export interface UseFocusableConfig<P = object> {
5757
focusBoundaryDirections?: Direction[];
5858
focusKey?: string;
5959
preferredChildFocusKey?: string;
60-
navigationStrategy?: NavigationStrategy;
60+
nextFocusResolver?: NextFocusResolver;
6161
onEnterPress?: EnterPressHandler<P>;
6262
onEnterRelease?: EnterReleaseHandler<P>;
6363
onArrowPress?: ArrowPressHandler<P>;
@@ -85,7 +85,7 @@ const useFocusableHook = <P, E = any>({
8585
focusBoundaryDirections,
8686
focusKey: propFocusKey,
8787
preferredChildFocusKey,
88-
navigationStrategy,
88+
nextFocusResolver,
8989
onEnterPress = noop,
9090
onEnterRelease = noop,
9191
onArrowPress = () => true,
@@ -162,7 +162,7 @@ const useFocusableHook = <P, E = any>({
162162
node,
163163
parentFocusKey,
164164
preferredChildFocusKey,
165-
navigationStrategy,
165+
nextFocusResolver,
166166
onEnterPress: onEnterPressHandler,
167167
onEnterRelease: onEnterReleaseHandler,
168168
onArrowPress: onArrowPressHandler,
@@ -197,7 +197,7 @@ const useFocusableHook = <P, E = any>({
197197
focusable,
198198
isFocusBoundary,
199199
focusBoundaryDirections,
200-
navigationStrategy,
200+
nextFocusResolver,
201201
onEnterPress: onEnterPressHandler,
202202
onEnterRelease: onEnterReleaseHandler,
203203
onArrowPress: onArrowPressHandler,
@@ -211,7 +211,7 @@ const useFocusableHook = <P, E = any>({
211211
focusable,
212212
isFocusBoundary,
213213
focusBoundaryDirections,
214-
navigationStrategy,
214+
nextFocusResolver,
215215
onEnterPressHandler,
216216
onEnterReleaseHandler,
217217
onArrowPressHandler,

0 commit comments

Comments
 (0)