@applicaster/zapp-react-native-utils 13.0.0-rc.2 → 13.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actionsExecutor/ActionExecutor.ts +16 -9
- package/actionsExecutor/ActionExecutorContext.tsx +74 -9
- package/alertUtils/alert.ts +148 -0
- package/alertUtils/index.ts +1 -148
- package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
- package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/appUtils/HooksManager/{Hook.js → Hook.ts} +35 -23
- package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +10 -8
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +693 -0
- package/appUtils/HooksManager/__tests__/hook.test.js +196 -184
- package/appUtils/HooksManager/__tests__/hooksManager.test.js +96 -99
- package/appUtils/HooksManager/{constants.js → constants.ts} +1 -1
- package/appUtils/HooksManager/{index.js → index.ts} +121 -112
- package/appUtils/HooksManager/types.ts +119 -0
- package/appUtils/RiverFocusManager/index.js +17 -12
- package/appUtils/accessibilityManager/index.ts +42 -1
- package/appUtils/contextKeysManager/contextResolver.ts +73 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +6 -6
- package/appUtils/focusManager/index.ts +90 -63
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +25 -3
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +1 -3
- package/appUtils/focusManager/utils/enums.ts +4 -0
- package/appUtils/focusManagerAux/utils/index.ts +4 -3
- package/appUtils/{index.js → index.ts} +1 -1
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +4 -4
- package/appUtils/keyCodes/{index.js → index.ts} +2 -0
- package/appUtils/keyCodes/keys/index.ts +3 -0
- package/appUtils/keyCodes/{keys.android.js → keys/keyEventMapper.ts} +0 -19
- package/appUtils/keyCodes/keys/keys.android.ts +18 -0
- package/appUtils/keyCodes/keys/keys.ios.ts +25 -0
- package/appUtils/keyCodes/keys/keys.ts +15 -0
- package/appUtils/keyCodes/{keysByPlatform.js → keys/keysByPlatform.ts} +4 -0
- package/appUtils/keyCodes/keysByPlatform.ts +8 -0
- package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
- package/appUtils/orientationHelper.ts +1 -1
- package/appUtils/platform/const.ts +14 -0
- package/appUtils/platform/platformUtils.ts +17 -15
- package/appUtils/playerManager/index.ts +6 -2
- package/appUtils/playerManager/player.ts +17 -5
- package/appUtils/playerManager/playerFactory.ts +5 -4
- package/appUtils/playerManager/playerNative.ts +3 -2
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +3 -3
- package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
- package/domUtils/{cookieManager.js → cookieManager.ts} +1 -2
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
- package/functionUtils/index.ts +15 -11
- package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
- package/idleUtils/index.ts +1 -1
- package/idleUtils/withTimeout.ts +15 -2
- package/logger/const.ts +9 -67
- package/manifestUtils/__tests__/createConfig.test.js +18 -16
- package/modalState/index.ts +1 -5
- package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +6 -6
- package/navigationUtils/__tests__/itemTypes.test.js +2 -2
- package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
- package/navigationUtils/index.ts +14 -5
- package/package.json +3 -2
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -1
- package/reactHooks/cell-click/__tests__/index.test.js +10 -2
- package/reactHooks/cell-click/index.ts +7 -1
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +20 -13
- package/reactHooks/feed/useFeedLoader.tsx +12 -8
- package/reactHooks/feed/usePipesCacheReset.ts +5 -5
- package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
- package/reactHooks/layout/__tests__/index.test.tsx +10 -10
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
- package/reactHooks/navigation/__tests__/index.test.tsx +0 -4
- package/reactHooks/navigation/index.ts +29 -218
- package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
- package/reactHooks/navigation/useGetTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useIsScreenActive.ts +17 -0
- package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
- package/reactHooks/navigation/useNavigationType.ts +15 -0
- package/reactHooks/navigation/usePathname.ts +4 -0
- package/reactHooks/navigation/useRoute.ts +100 -0
- package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
- package/reactHooks/player/TVSeekControlller/ISeekController.ts +32 -0
- package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +71 -0
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +258 -0
- package/reactHooks/player/TVSeekControlller/TapSeekController.ts +53 -0
- package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -3
- package/reactHooks/player/const.ts +0 -4
- package/reactHooks/player/index.ts +0 -6
- package/reactHooks/utils/index.ts +13 -0
- package/reactUtils/__tests__/reactUtils.test.js +10 -28
- package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +19 -19
- package/reactUtils/createContext/__tests__/__snapshots__/index.test.js.snap +2 -2
- package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -3
- package/reactUtils/createContext/__tests__/helpers.test.js +8 -8
- package/reactUtils/index.ts +0 -14
- package/theme/__mocks__/index.ts +4 -0
- package/time/Timer.ts +1 -1
- package/types.ts +1 -0
- package/appUtils/keyCodes/keys.ios.js +0 -46
- package/reactHooks/player/useAutoSeek.tsx +0 -87
- package/reactHooks/player/useSeek.tsx +0 -66
- package/reactHooks/player/useTapSeek.tsx +0 -58
- /package/appUtils/HooksManager/{logger.js → logger.ts} +0 -0
- /package/appUtils/{directionHelper.js → directionHelper.ts} +0 -0
- /package/appUtils/keyCodes/{androidTVKeys.js → androidTVKeys.ts} +0 -0
- /package/appUtils/keyCodes/{keys.web.js → keys/keys.web.ts} +0 -0
- /package/appUtils/{localizationsHelper.js → localizationsHelper.ts} +0 -0
- /package/domUtils/{logger.js → logger.ts} +0 -0
- /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { SubscriberObj } from "../../functionUtils";
|
|
2
|
+
import { HOOKS_EVENTS } from "./constants";
|
|
3
|
+
|
|
4
|
+
export interface HookConfiguration {}
|
|
5
|
+
|
|
6
|
+
/* existing Hook Plugn props: sample */
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
interface _HookModulePlugin {
|
|
10
|
+
Component:
|
|
11
|
+
| React.FC<HookPluginProps>
|
|
12
|
+
| React.Component<HookPluginProps, any>
|
|
13
|
+
| React.ReactNode;
|
|
14
|
+
ModalContainer?: React.FC<ModalProps> | React.Component<ModalProps, any>;
|
|
15
|
+
skipHook?: (payload: ZappRiver | ZappEntry) => boolean;
|
|
16
|
+
presentFullScreen: boolean;
|
|
17
|
+
showNavBar?: boolean;
|
|
18
|
+
isFlowBlocker: (() => boolean) | boolean; // narrow this
|
|
19
|
+
hasPlayerHook?: boolean;
|
|
20
|
+
name: string;
|
|
21
|
+
runInBackground?: (
|
|
22
|
+
item: HookPluginProps["payload"],
|
|
23
|
+
callback: hookCallback,
|
|
24
|
+
hookPlugin: HookScreenData,
|
|
25
|
+
presentUI: (payload?: HookPluginProps["payload"]) => void
|
|
26
|
+
) => any;
|
|
27
|
+
}
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
//* Derived from usage */
|
|
31
|
+
export interface HookModule {
|
|
32
|
+
ModalContainer?: React.ComponentType<any>;
|
|
33
|
+
Component: React.ComponentType<any>;
|
|
34
|
+
presentFullScreen: boolean;
|
|
35
|
+
run?: (
|
|
36
|
+
arg0: unknown,
|
|
37
|
+
callback: () => void,
|
|
38
|
+
configuration: HookConfiguration
|
|
39
|
+
) => void; // not sure about optional parameter
|
|
40
|
+
hasPlayerHook?: boolean;
|
|
41
|
+
configuration?: HookConfiguration;
|
|
42
|
+
isFlowBlocker: () => boolean;
|
|
43
|
+
skipHook?: (payload?: ZappRiver | ZappEntry) => boolean;
|
|
44
|
+
runInBackground?: (
|
|
45
|
+
arg0: unknown,
|
|
46
|
+
callback: () => void,
|
|
47
|
+
hookPlugin: Hook,
|
|
48
|
+
presentUI: (payload?: HookPluginProps["payload"]) => void
|
|
49
|
+
) => void;
|
|
50
|
+
name: string;
|
|
51
|
+
showNavBar?: boolean; // unsure
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type HookManagerArgs = {
|
|
55
|
+
rivers: Record<string, ZappRiver>;
|
|
56
|
+
plugins: ZappPlugin[];
|
|
57
|
+
targetScreen: ZappRiver;
|
|
58
|
+
startUpHooksData?: {
|
|
59
|
+
startUpHooks?: unknown[] | "in_process";
|
|
60
|
+
setStartUpHooks?: (arg0: string) => void;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export interface HookManager {
|
|
65
|
+
subscriber: SubscriberObj;
|
|
66
|
+
presentScreenHook: (
|
|
67
|
+
hook: Hook,
|
|
68
|
+
payload: unknown,
|
|
69
|
+
callback: (...any) => void
|
|
70
|
+
) => void;
|
|
71
|
+
executeHook: (
|
|
72
|
+
hook: Hook,
|
|
73
|
+
payload: unknown,
|
|
74
|
+
callback: (...any) => void
|
|
75
|
+
) => void;
|
|
76
|
+
handleHooks: (payload: unknown) => void;
|
|
77
|
+
runInBackground: (
|
|
78
|
+
hook: Hook,
|
|
79
|
+
payload: unknown,
|
|
80
|
+
callback: (...any) => void,
|
|
81
|
+
presentUI: (payload?: HookPluginProps["payload"]) => void
|
|
82
|
+
) => void;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type HookIniObj = {
|
|
86
|
+
hook: HookModule & {
|
|
87
|
+
module: HookModule;
|
|
88
|
+
general: unknown;
|
|
89
|
+
screen_id?: string;
|
|
90
|
+
identifier?: string;
|
|
91
|
+
weight?: number | string;
|
|
92
|
+
};
|
|
93
|
+
hooks: Hook<any>[];
|
|
94
|
+
manager: HookManager;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export interface Hook<T extends HookModule = HookModule> {
|
|
98
|
+
manager: HookManager;
|
|
99
|
+
lastHook: boolean;
|
|
100
|
+
state: number;
|
|
101
|
+
module: T;
|
|
102
|
+
screen_id: string;
|
|
103
|
+
identifier: string;
|
|
104
|
+
configuration: T["configuration"];
|
|
105
|
+
setStateAndNotify(
|
|
106
|
+
event: typeof HOOKS_EVENTS[keyof typeof HOOKS_EVENTS],
|
|
107
|
+
opts: {
|
|
108
|
+
error?: typeof Error;
|
|
109
|
+
route?: string;
|
|
110
|
+
hookPlugin: Hook<T>;
|
|
111
|
+
payload: unknown;
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
general?: {
|
|
115
|
+
transition_type: typeof HOOKS_EVENTS[keyof typeof HOOKS_EVENTS];
|
|
116
|
+
allow_screen_plugin_presentation: boolean;
|
|
117
|
+
is_flow_blocker: boolean;
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -26,7 +26,7 @@ export const riverFocusManager = (function () {
|
|
|
26
26
|
/**
|
|
27
27
|
* Retrieve screen focus data by id
|
|
28
28
|
*
|
|
29
|
-
* @param {
|
|
29
|
+
* @param {{screenFocusableGroupId: string}} screenFocusableGroupId Unique Id of the screen from layout.json
|
|
30
30
|
*
|
|
31
31
|
*/
|
|
32
32
|
function screenFocusableData({ screenFocusableGroupId }) {
|
|
@@ -36,8 +36,9 @@ export const riverFocusManager = (function () {
|
|
|
36
36
|
/**
|
|
37
37
|
* Clear screen data for specific screen
|
|
38
38
|
*
|
|
39
|
-
* @param {
|
|
40
|
-
*
|
|
39
|
+
* @param {{ screenId: string, isInsideContainer: boolean }}
|
|
40
|
+
* screenId Unique Id of the screen from layout.json
|
|
41
|
+
* isInsideContainer If this screen a screen picker child
|
|
41
42
|
*
|
|
42
43
|
*/
|
|
43
44
|
function clearScreenData({ screenId, isInsideContainer }) {
|
|
@@ -60,9 +61,13 @@ export const riverFocusManager = (function () {
|
|
|
60
61
|
/**
|
|
61
62
|
* Focus on selected items
|
|
62
63
|
*
|
|
63
|
-
* @param {
|
|
64
|
-
*
|
|
65
|
-
*
|
|
64
|
+
* @param {{
|
|
65
|
+
* screenFocusableGroupId: string,
|
|
66
|
+
* screenFocusedOnItem: () => void,
|
|
67
|
+
* previousAction: QuickBrickNavigationActionType,
|
|
68
|
+
* isDeepLink: boolean }} object contains data for focus
|
|
69
|
+
* - `screenFocusedOnItem` focusable item to focus
|
|
70
|
+
* - `previousActionhistory` navigator history object
|
|
66
71
|
*
|
|
67
72
|
*/
|
|
68
73
|
function focusOnSelectedItem({
|
|
@@ -115,15 +120,15 @@ export const riverFocusManager = (function () {
|
|
|
115
120
|
|
|
116
121
|
/**
|
|
117
122
|
* Create unique key that will be used for save focused group data inside specific screen
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
123
|
+
* @param {{ screenId: string, isInsideContainer: boolean }}
|
|
124
|
+
* screenId Unique Id of the screen from layout.json
|
|
125
|
+
* isInsideContainer If this screen a screen picker child
|
|
121
126
|
*
|
|
122
127
|
*/
|
|
123
128
|
function screenFocusableGroupId({ screenId, isInsideContainer }) {
|
|
124
|
-
return
|
|
125
|
-
?
|
|
126
|
-
|
|
129
|
+
return `RiverFocusableGroup-${screenId}${
|
|
130
|
+
R.isNil(isInsideContainer) ? "" : "-isInsideContainer"
|
|
131
|
+
}`;
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
return {
|
|
@@ -6,6 +6,9 @@ import { AccessibilityRole } from "react-native";
|
|
|
6
6
|
|
|
7
7
|
export class AccessibilityManager {
|
|
8
8
|
private static _instance: AccessibilityManager | null = null;
|
|
9
|
+
private headingTimeout: NodeJS.Timeout | null = null;
|
|
10
|
+
private WORDS_PER_MINUTE = 160;
|
|
11
|
+
private MINIMUM_PAUSE = 500;
|
|
9
12
|
private state$ = new BehaviorSubject<AccessibilityState>({
|
|
10
13
|
screenReaderEnabled: false,
|
|
11
14
|
reduceMotionEnabled: false,
|
|
@@ -20,6 +23,7 @@ export class AccessibilityManager {
|
|
|
20
23
|
|
|
21
24
|
private ttsManager = TTSManager.getInstance();
|
|
22
25
|
private localizations: { [key: string]: string } = {};
|
|
26
|
+
private headingQueue: string[] = [];
|
|
23
27
|
|
|
24
28
|
private constructor() {}
|
|
25
29
|
|
|
@@ -52,6 +56,28 @@ export class AccessibilityManager {
|
|
|
52
56
|
return this.state$.asObservable();
|
|
53
57
|
}
|
|
54
58
|
|
|
59
|
+
/** Calculates the reading time for a given text
|
|
60
|
+
* This method is a bit of a hack because we don't have a callback, or promise from VIZIO API
|
|
61
|
+
* @param text - The text to calculate the reading time for
|
|
62
|
+
* @returns The reading time in milliseconds
|
|
63
|
+
*/
|
|
64
|
+
private calculateReadingTime(text: string): number {
|
|
65
|
+
const words = text.trim().split(/\s+/).length;
|
|
66
|
+
|
|
67
|
+
return Math.max(
|
|
68
|
+
this.MINIMUM_PAUSE,
|
|
69
|
+
(words / this.WORDS_PER_MINUTE) * 60 * 1000
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Adds a heading to the queue, headings will be read before the next text
|
|
75
|
+
* Each heading will be read once and removed from the queue
|
|
76
|
+
*/
|
|
77
|
+
public addHeading(heading: string) {
|
|
78
|
+
this.headingQueue.push(heading);
|
|
79
|
+
}
|
|
80
|
+
|
|
55
81
|
/**
|
|
56
82
|
* text you want to be read, if you want to use localized text pass keyOfLocalizedText instead
|
|
57
83
|
* keyOfLocalizedText is the key to the localized text
|
|
@@ -85,7 +111,22 @@ export class AccessibilityManager {
|
|
|
85
111
|
textToRead = localizedMessage;
|
|
86
112
|
}
|
|
87
113
|
|
|
88
|
-
this.
|
|
114
|
+
if (this.headingQueue.length > 0) {
|
|
115
|
+
const heading = this.headingQueue.shift()!;
|
|
116
|
+
this.ttsManager?.readText(heading);
|
|
117
|
+
|
|
118
|
+
if (this.headingTimeout) {
|
|
119
|
+
clearTimeout(this.headingTimeout);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const pauseTime = this.calculateReadingTime(heading);
|
|
123
|
+
|
|
124
|
+
this.headingTimeout = setTimeout(() => {
|
|
125
|
+
this.ttsManager?.readText(textToRead);
|
|
126
|
+
}, pauseTime);
|
|
127
|
+
} else {
|
|
128
|
+
this.ttsManager?.readText(textToRead);
|
|
129
|
+
}
|
|
89
130
|
|
|
90
131
|
this.announcements$.next({
|
|
91
132
|
message: textToRead,
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createLogger } from "../../logger";
|
|
2
|
+
import { ContextKeysManager } from "./index";
|
|
3
|
+
import * as R from "ramda";
|
|
4
|
+
|
|
5
|
+
const { log_error } = createLogger({
|
|
6
|
+
subsystem: "contextResolver",
|
|
7
|
+
category: "General",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
interface IResolver {
|
|
11
|
+
resolve: (string) => Promise<string | number | object>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class EntryResolver implements IResolver {
|
|
15
|
+
entry: ZappEntry;
|
|
16
|
+
|
|
17
|
+
constructor(entry: ZappEntry) {
|
|
18
|
+
this.entry = entry;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async resolve(key: string) {
|
|
22
|
+
if (!key || key.length === 0) {
|
|
23
|
+
return this.entry;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return R.view(R.lensPath(key.split(".")), this.entry);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class ContextResolver implements IResolver {
|
|
31
|
+
resolve = async (compositeKey: string) =>
|
|
32
|
+
ContextKeysManager.instance.getKey(compositeKey);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const resolveObjectValues = async (
|
|
36
|
+
data: Record<string, any>,
|
|
37
|
+
resolvers: Record<string, IResolver> = null
|
|
38
|
+
) => {
|
|
39
|
+
const entries = Object.entries(data);
|
|
40
|
+
|
|
41
|
+
const exResolvers = { ctx: new ContextResolver(), ...resolvers };
|
|
42
|
+
|
|
43
|
+
const resolvedEntries = await Promise.all(
|
|
44
|
+
entries.map(async ([key, value]) => {
|
|
45
|
+
const regex = /@{([^/]+)\/([^}]*)}/;
|
|
46
|
+
|
|
47
|
+
if (typeof value !== "string") {
|
|
48
|
+
return [key, value];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const match = (value as string).match(regex);
|
|
52
|
+
|
|
53
|
+
if (match) {
|
|
54
|
+
const contextResolverName = match[1];
|
|
55
|
+
const compositeKey = match[2];
|
|
56
|
+
|
|
57
|
+
const resolver = exResolvers[contextResolverName] || exResolvers.ctx;
|
|
58
|
+
const resolvedValue = await resolver.resolve(compositeKey);
|
|
59
|
+
|
|
60
|
+
return [key, resolvedValue];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
log_error("resolveObjectValues: invalid context string", {
|
|
64
|
+
key,
|
|
65
|
+
value,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return [key, null];
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return Object.fromEntries(resolvedEntries);
|
|
73
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`focusManager should be defined 1`] = `
|
|
4
|
-
|
|
4
|
+
{
|
|
5
5
|
"blur": [Function],
|
|
6
6
|
"disableFocus": [Function],
|
|
7
7
|
"enableFocus": [Function],
|
|
8
8
|
"focusableTree": Tree {
|
|
9
9
|
"loadingCounter": 0,
|
|
10
|
-
"root":
|
|
11
|
-
"children":
|
|
10
|
+
"root": {
|
|
11
|
+
"children": [],
|
|
12
12
|
"component": null,
|
|
13
13
|
"id": "root",
|
|
14
14
|
"lastFocusedItem": null,
|
|
@@ -39,12 +39,12 @@ Object {
|
|
|
39
39
|
`;
|
|
40
40
|
|
|
41
41
|
exports[`focusManagerIOS should be defined 1`] = `
|
|
42
|
-
|
|
42
|
+
{
|
|
43
43
|
"focus": [Function],
|
|
44
44
|
"focusableTree": Tree {
|
|
45
45
|
"loadingCounter": 0,
|
|
46
|
-
"root":
|
|
47
|
-
"children":
|
|
46
|
+
"root": {
|
|
47
|
+
"children": [],
|
|
48
48
|
"component": null,
|
|
49
49
|
"id": "root",
|
|
50
50
|
"lastFocusedItem": null,
|
|
@@ -11,8 +11,8 @@ import {
|
|
|
11
11
|
haveSameParentBeforeRoot,
|
|
12
12
|
} from "./treeDataStructure/Utils";
|
|
13
13
|
import { subscriber } from "../../functionUtils";
|
|
14
|
-
import * as FOCUS_EVENTS from "./events";
|
|
15
14
|
import { coreLogger } from "../../logger";
|
|
15
|
+
import { ACTION } from "./utils/enums";
|
|
16
16
|
const logger = coreLogger.addSubsystem("focusManager");
|
|
17
17
|
|
|
18
18
|
const isFocusEnabled = (focusableItem): boolean => {
|
|
@@ -167,13 +167,82 @@ export const focusManager = (function () {
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
/**
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
170
|
+
* Computes the difference in parent groups between two nodes.
|
|
171
|
+
* It returns the IDs of parents that are present in the current node but not in the previous node,
|
|
172
|
+
* as well as the IDs of parents that are present in the previous node but not in the current node.
|
|
173
|
+
*
|
|
174
|
+
* @param {string} currentNodeID - The ID of the current node.
|
|
175
|
+
* @param {string} previousNodeID - The ID of the previous node.
|
|
176
|
+
* @returns {Object} An object containing the differences in parent IDs:
|
|
177
|
+
* - {Array<string>} currentNodeParentsIDs: Parent IDs present in the current node but not in the previous node.
|
|
178
|
+
* - {Array<string>} previousNodeParentsIDs: Parent IDs present in the previous node but not in the current node.
|
|
173
179
|
*/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
180
|
+
const getParentDiffs = (currentNodeID, previousNodeID) => {
|
|
181
|
+
const currentNodeParentsIDs =
|
|
182
|
+
focusableTree.getParentGroupIds(currentNodeID);
|
|
183
|
+
|
|
184
|
+
const previousNodeParentsIDs =
|
|
185
|
+
focusableTree.getParentGroupIds(previousNodeID);
|
|
186
|
+
|
|
187
|
+
return {
|
|
188
|
+
currentNodeParentsIDs: R.difference(
|
|
189
|
+
currentNodeParentsIDs,
|
|
190
|
+
previousNodeParentsIDs
|
|
191
|
+
),
|
|
192
|
+
previousNodeParentsIDs: R.difference(
|
|
193
|
+
previousNodeParentsIDs,
|
|
194
|
+
currentNodeParentsIDs
|
|
195
|
+
),
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Updates the focus state of nodes identified by their IDs.
|
|
201
|
+
* For each ID, if `setFocus` is true, the node will receive focus;
|
|
202
|
+
* otherwise, it will lose focus.
|
|
203
|
+
*
|
|
204
|
+
* @param {Array<string>} ids - An array of node IDs to update.
|
|
205
|
+
* @param {boolean} setFocus - A flag indicating whether to set focus (true) or blur (false) on the nodes.
|
|
206
|
+
*/
|
|
207
|
+
const updateNodeFocus = (ids, action) => {
|
|
208
|
+
if (!ids || ids.length === 0) {
|
|
209
|
+
return; // Nothing to do
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const startNode = focusableTree.findInTree(ids[0]);
|
|
213
|
+
|
|
214
|
+
if (!startNode) {
|
|
215
|
+
return; // Start node not found
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const endNodeId = ids[ids.length - 1]; // Get the ID of the end node
|
|
219
|
+
|
|
220
|
+
let currentNode = startNode;
|
|
221
|
+
|
|
222
|
+
// Function to apply the action (focus or blur)
|
|
223
|
+
const applyAction = (node) => {
|
|
224
|
+
if (node && node.component) {
|
|
225
|
+
if (action === "focus") {
|
|
226
|
+
node.component.setFocus();
|
|
227
|
+
} else if (action === "blur") {
|
|
228
|
+
node.component.setBlur();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// Apply action to the starting node
|
|
234
|
+
applyAction(currentNode);
|
|
235
|
+
|
|
236
|
+
// Traverse upwards
|
|
237
|
+
while (currentNode && currentNode.id !== endNodeId) {
|
|
238
|
+
currentNode = currentNode.parent;
|
|
239
|
+
|
|
240
|
+
if (currentNode) {
|
|
241
|
+
// check if current node exists, as parent might be root
|
|
242
|
+
applyAction(currentNode);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
};
|
|
177
246
|
|
|
178
247
|
/**
|
|
179
248
|
* Sets the current focus to the provided id. If there is an existing focus, it will
|
|
@@ -181,34 +250,29 @@ export const focusManager = (function () {
|
|
|
181
250
|
* @private
|
|
182
251
|
* @param {String} id of the focusable to set as currentFocus
|
|
183
252
|
* @param {Object} direction of the navigation, which led to this focus change
|
|
184
|
-
* @param {Object} options
|
|
185
|
-
* @param {Boolean} options.groupFocusedChanged tells wether the focus has moved
|
|
186
253
|
* to another group or not. defaults to false
|
|
187
254
|
*/
|
|
188
|
-
function setFocus(
|
|
189
|
-
id: string,
|
|
190
|
-
direction?: FocusManager.Web.Direction,
|
|
191
|
-
options?: Partial<{ groupFocusedChanged: boolean }>
|
|
192
|
-
) {
|
|
255
|
+
function setFocus(id: string, direction?: FocusManager.Web.Direction) {
|
|
193
256
|
if (focusDisabled) return false;
|
|
194
257
|
|
|
195
|
-
const { groupFocusedChanged = false } = options || {};
|
|
196
|
-
|
|
197
258
|
// due to optimisiation it's recommanded to set currentFocusNode before setFocus
|
|
198
259
|
// is called, so there will be no delays on tree search.
|
|
199
260
|
// If currentFocusNode is null or undefined we still want it to findInTree
|
|
200
261
|
if (currentFocusNode?.id !== id) {
|
|
262
|
+
const { currentNodeParentsIDs, previousNodeParentsIDs } = getParentDiffs(
|
|
263
|
+
id,
|
|
264
|
+
currentFocusNode?.id
|
|
265
|
+
);
|
|
266
|
+
|
|
267
|
+
// Set focus on current node parents and blur on previous node parents
|
|
268
|
+
updateNodeFocus(currentNodeParentsIDs, ACTION.FOCUS);
|
|
269
|
+
updateNodeFocus(previousNodeParentsIDs, ACTION.BLUR);
|
|
270
|
+
|
|
201
271
|
currentFocusNode = focusableTree.findInTree(id);
|
|
202
272
|
}
|
|
203
273
|
|
|
204
274
|
setLastFocusOnParentNode(currentFocusNode);
|
|
205
275
|
|
|
206
|
-
const currentGroup = getCurrentGroup();
|
|
207
|
-
|
|
208
|
-
if (groupFocusedChanged && currentGroup) {
|
|
209
|
-
currentGroup.hasLostFocus(currentGroup, direction);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
276
|
focus(direction);
|
|
213
277
|
}
|
|
214
278
|
|
|
@@ -251,6 +315,7 @@ export const focusManager = (function () {
|
|
|
251
315
|
!focusableItem.isGroup &&
|
|
252
316
|
isFocusEnabled(focusableItem)
|
|
253
317
|
) {
|
|
318
|
+
// TODO: Move this to setFocus method
|
|
254
319
|
blur();
|
|
255
320
|
|
|
256
321
|
logger.log({
|
|
@@ -261,7 +326,7 @@ export const focusManager = (function () {
|
|
|
261
326
|
});
|
|
262
327
|
|
|
263
328
|
currentFocusNode = focusCandidate;
|
|
264
|
-
|
|
329
|
+
|
|
265
330
|
focusableItem && setFocus(focusCandidate.id, null);
|
|
266
331
|
|
|
267
332
|
return { success: true };
|
|
@@ -448,20 +513,10 @@ export const focusManager = (function () {
|
|
|
448
513
|
const nextRect = nextFocusable.component.getRect();
|
|
449
514
|
|
|
450
515
|
if (nextRect && nextRect.width > 0) {
|
|
451
|
-
|
|
452
|
-
nextFocusable.component,
|
|
453
|
-
direction
|
|
454
|
-
);
|
|
455
|
-
|
|
516
|
+
// TODO: Move this to setFocus method
|
|
456
517
|
blur(direction);
|
|
457
518
|
|
|
458
|
-
|
|
459
|
-
nextFocusable.component.props.groupId !==
|
|
460
|
-
currentFocusNode?.component?.props?.groupId;
|
|
461
|
-
|
|
462
|
-
setFocus(nextFocusable.id, direction, {
|
|
463
|
-
groupFocusedChanged: groupChanged,
|
|
464
|
-
});
|
|
519
|
+
setFocus(nextFocusable.id, direction);
|
|
465
520
|
}
|
|
466
521
|
} else {
|
|
467
522
|
currentFocusNode.component.failedLostFocus(currentFocusNode, direction);
|
|
@@ -481,34 +536,6 @@ export const focusManager = (function () {
|
|
|
481
536
|
|
|
482
537
|
const { on, invokeHandler, removeHandler } = eventHandler;
|
|
483
538
|
|
|
484
|
-
on(FOCUS_EVENTS.FOCUS, (focusable, direction) => {
|
|
485
|
-
if (focusable.props.groupId) {
|
|
486
|
-
const parent = focusableTree.findInTree(focusable.props.groupId);
|
|
487
|
-
parent?.component?.onFocus(focusable.component, direction);
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
on(FOCUS_EVENTS.BLUR, (focusable, direction) => {
|
|
492
|
-
if (focusable.props.groupId) {
|
|
493
|
-
const parent = focusableTree.findInTree(focusable.props.groupId);
|
|
494
|
-
parent?.component?.onBlur(focusable.component, direction);
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
on(FOCUS_EVENTS.HAS_LOST_FOCUS, (focusable, direction) => {
|
|
499
|
-
if (focusable.props.groupId) {
|
|
500
|
-
const parent = focusableTree.findInTree(focusable.props.groupId);
|
|
501
|
-
parent?.component?.hasLostFocus(parent.component, direction);
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
on(FOCUS_EVENTS.WILL_RECEIVE_FOCUS, (focusable, direction) => {
|
|
506
|
-
if (focusable.props.groupId) {
|
|
507
|
-
const parent = focusableTree.findInTree(focusable.props.groupId);
|
|
508
|
-
parent?.component?.willReceiveFocus(focusable.component, direction);
|
|
509
|
-
}
|
|
510
|
-
});
|
|
511
|
-
|
|
512
539
|
/**
|
|
513
540
|
* this is the list of the functions available externally
|
|
514
541
|
* when importing the focus manager
|
|
@@ -59,7 +59,7 @@ export class Tree {
|
|
|
59
59
|
/**
|
|
60
60
|
* Update node with provided data from newNode
|
|
61
61
|
* @private
|
|
62
|
-
* @param {Object}
|
|
62
|
+
* @param {Object} currentNode to update
|
|
63
63
|
* @param {Object} newNode node to take data from
|
|
64
64
|
*/
|
|
65
65
|
updateNode(currentNode, newNode) {
|
|
@@ -175,7 +175,6 @@ export class Tree {
|
|
|
175
175
|
* @private
|
|
176
176
|
* @param {Object} node to check
|
|
177
177
|
* @returns True if node has defined groupID
|
|
178
|
-
* @returns False if node has NOT defined groupID
|
|
179
178
|
*/
|
|
180
179
|
hasGroupID(node) {
|
|
181
180
|
return node.component && node.component.props.groupId;
|
|
@@ -191,7 +190,7 @@ export class Tree {
|
|
|
191
190
|
const findChildNode = this.findInTree(node.component.props.groupId);
|
|
192
191
|
|
|
193
192
|
if (findChildNode) {
|
|
194
|
-
this.root.children.pop(
|
|
193
|
+
this.root.children.pop();
|
|
195
194
|
node.children.push(findChildNode);
|
|
196
195
|
}
|
|
197
196
|
}
|
|
@@ -232,4 +231,27 @@ export class Tree {
|
|
|
232
231
|
|
|
233
232
|
return retVal;
|
|
234
233
|
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Gets the IDs of all parent groups for a given node id.
|
|
237
|
+
* @public
|
|
238
|
+
* @param {String} nodeId - The id of the node to get parent IDs for.
|
|
239
|
+
* @returns {Array} An array of parent group IDs or an empty array if the node is not found.
|
|
240
|
+
*/
|
|
241
|
+
getParentGroupIds(nodeId) {
|
|
242
|
+
const parentIds = [];
|
|
243
|
+
let currentNode = this.findInTree(nodeId);
|
|
244
|
+
|
|
245
|
+
if (!currentNode) {
|
|
246
|
+
return []; // Node not found, return an empty array
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Traverse up the tree, collecting parent IDs
|
|
250
|
+
while (currentNode.parent && currentNode.parent.id !== "root") {
|
|
251
|
+
parentIds.push(currentNode.parent.id);
|
|
252
|
+
currentNode = currentNode.parent;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return parentIds;
|
|
256
|
+
}
|
|
235
257
|
}
|
|
@@ -191,7 +191,6 @@ const toDistance = ({ target, direction, comparisonRect }) => {
|
|
|
191
191
|
* Get target in shortest distance in specified direction
|
|
192
192
|
* @private
|
|
193
193
|
* @param {Object} direction of the navigation, which led to this focus change
|
|
194
|
-
* @param {Object} excludedNode node which should be excluded from target group
|
|
195
194
|
* @param {Array} targetNodes array of input target nodes
|
|
196
195
|
* @param {Object} comparisonRect rectangle to compare sides in direction.
|
|
197
196
|
* @returns {Object} target in direction.
|
|
@@ -300,8 +299,7 @@ export function findFocusableNode(direction, currentFocusNode) {
|
|
|
300
299
|
* @public
|
|
301
300
|
* @param {Object} direction of the navigation, which led to this focus change
|
|
302
301
|
* @param {Object} component - object to check props.prioritiseFocusOn
|
|
303
|
-
* @returns {Boolean} TRUE if object has priority in direction.
|
|
304
|
-
* @returns {Boolean} FALSE if object has NO priority in direction.
|
|
302
|
+
* @returns {Boolean} TRUE if object has priority in direction. FALSE if object has NO priority in direction.
|
|
305
303
|
*/
|
|
306
304
|
export function hasPriorityInDirection(direction, component) {
|
|
307
305
|
const { prioritiseFocusOn = 0 } = component.props;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
|
|
2
|
-
import { find, last,
|
|
2
|
+
import { find, last, pathOr, startsWith } from "ramda";
|
|
3
3
|
import {
|
|
4
|
-
QUICK_BRICK_NAVBAR,
|
|
5
4
|
QUICK_BRICK_CONTENT,
|
|
5
|
+
QUICK_BRICK_NAVBAR,
|
|
6
6
|
} from "@applicaster/quick-brick-core/const";
|
|
7
7
|
|
|
8
8
|
// run check each 300 ms
|
|
@@ -66,7 +66,8 @@ export const getContentNode = (focusableTree) => {
|
|
|
66
66
|
const content = find(
|
|
67
67
|
(child) =>
|
|
68
68
|
startsWith(QUICK_BRICK_CONTENT, child.id) ||
|
|
69
|
-
startsWith("player", child.id)
|
|
69
|
+
startsWith("player", child.id) ||
|
|
70
|
+
startsWith("/hooks", child?.parent?.id), // For startup hooks case
|
|
70
71
|
getActiveScreenChildren(focusableTree)
|
|
71
72
|
);
|
|
72
73
|
|
|
@@ -9,7 +9,7 @@ export { KEYS, ARROW_KEYS } from "./keyCodes/keys";
|
|
|
9
9
|
|
|
10
10
|
export { playerManager } from "./playerManager";
|
|
11
11
|
|
|
12
|
-
export {
|
|
12
|
+
export { AccessibilityManager } from "./accessibilityManager";
|
|
13
13
|
|
|
14
14
|
export function deprecationMessage(fn, replacement) {
|
|
15
15
|
if (__DEV__ && process.env.NODE_ENV !== "test") {
|