@applicaster/zapp-react-native-utils 13.0.0-alpha.1552112220 → 13.0.0-alpha.1692038547
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/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/appUtils/HooksManager/Hook.ts +2 -2
- package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +7 -7
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +186 -186
- package/appUtils/HooksManager/types.ts +5 -2
- package/appUtils/accessibilityManager/index.ts +42 -1
- package/appUtils/contextKeysManager/contextResolver.ts +77 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +7 -6
- package/appUtils/focusManager/index.ts +100 -65
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +23 -0
- package/appUtils/focusManager/utils/enums.ts +4 -0
- package/appUtils/focusManagerAux/utils/index.ts +4 -3
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +1 -1
- package/appUtils/orientationHelper.ts +1 -1
- package/appUtils/platform/const.ts +14 -0
- package/appUtils/platform/platformUtils.ts +41 -4
- package/appUtils/playerManager/player.ts +2 -2
- package/appUtils/playerManager/playerNative.ts +1 -1
- package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
- package/focusManager/FocusManager.ts +27 -3
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
- 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 +16 -16
- 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 +3 -3
- 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 +10 -11
- package/reactHooks/feed/useFeedLoader.tsx +1 -1
- 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/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
- package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +0 -4
- package/reactHooks/navigation/index.ts +22 -214
- package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
- package/reactHooks/navigation/useGetTabBarHeight.ts +10 -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/TVSeekController.ts +4 -4
- package/reactHooks/player/__tests__/useAutoSeek._test.tsx +115 -0
- package/reactHooks/player/__tests__/useTapSeek._test.ts +94 -0
- package/reactHooks/state/useRefWithInitialValue.ts +14 -0
- package/reactHooks/state/useStateFromSubscribe.ts +23 -0
- package/reactHooks/usePluginConfiguration.ts +1 -1
- package/reactHooks/useSubscriberFor.ts +4 -3
- 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/screenState/index.ts +24 -10
- package/theme/__mocks__/index.ts +4 -0
- package/theme/index.ts +1 -1
- package/time/Timer.ts +5 -2
- package/types.ts +1 -0
- package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
+
/* eslint max-len: off */
|
|
3
|
+
|
|
4
|
+
import { useContext } from "react";
|
|
5
|
+
|
|
6
|
+
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
7
|
+
|
|
8
|
+
import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
|
|
9
|
+
|
|
10
|
+
import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
|
|
11
|
+
|
|
12
|
+
import { getTargetScreenData } from "../screen/useTargetScreenData";
|
|
13
|
+
|
|
14
|
+
import { useNavigation } from "./useNavigation";
|
|
15
|
+
import { useModalStore } from "../../modalState";
|
|
16
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
17
|
+
import { usePathname } from "./usePathname";
|
|
18
|
+
|
|
19
|
+
// starts with modal/
|
|
20
|
+
const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
|
|
21
|
+
|
|
22
|
+
const isVideoModalPathname = (pathname: string) =>
|
|
23
|
+
/^video-modal\//.test(pathname);
|
|
24
|
+
|
|
25
|
+
const isHookModalPathname = (pathname: string) =>
|
|
26
|
+
/^hooks-modal\//.test(pathname);
|
|
27
|
+
|
|
28
|
+
const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
29
|
+
|
|
30
|
+
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
31
|
+
|
|
32
|
+
export const useRoute = (): {
|
|
33
|
+
screenData: VariousScreenData;
|
|
34
|
+
pathname: string;
|
|
35
|
+
} => {
|
|
36
|
+
const pathname = usePathname() || "";
|
|
37
|
+
const navigator = useNavigation();
|
|
38
|
+
|
|
39
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
40
|
+
|
|
41
|
+
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
42
|
+
"plugins",
|
|
43
|
+
"rivers",
|
|
44
|
+
"contentTypes",
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
const { modalState } = useModalStore();
|
|
48
|
+
const hookModalState = useZappHooksModalState();
|
|
49
|
+
|
|
50
|
+
const modalScreenData = modalState.screen;
|
|
51
|
+
|
|
52
|
+
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
53
|
+
|
|
54
|
+
const videoModalScreenData =
|
|
55
|
+
navigator?.videoModalState?.item &&
|
|
56
|
+
legacyScreenData(
|
|
57
|
+
{
|
|
58
|
+
entry: navigator.videoModalState?.item as ZappEntry,
|
|
59
|
+
screen: getTargetScreenData(
|
|
60
|
+
navigator.videoModalState?.item as ZappEntry,
|
|
61
|
+
rivers,
|
|
62
|
+
contentTypes
|
|
63
|
+
),
|
|
64
|
+
},
|
|
65
|
+
plugins
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// There are 4 route scenarios
|
|
69
|
+
// For regular screens take date from navigator stack.
|
|
70
|
+
// is path is model grab screenData from modal state
|
|
71
|
+
// if path is video modal grab screenData from video state
|
|
72
|
+
// if path is hook modal grab screenData from hook state
|
|
73
|
+
// if path is hook grab screenData from screenData
|
|
74
|
+
|
|
75
|
+
if (isModalPathname(pathname)) {
|
|
76
|
+
const screenData = modalScreenData ?? ({} as ZappEntry);
|
|
77
|
+
|
|
78
|
+
return { screenData, pathname };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (isVideoModalPathname(pathname)) {
|
|
82
|
+
const screenData = videoModalScreenData as LegacyNavigationScreenData;
|
|
83
|
+
|
|
84
|
+
return { screenData, pathname };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (isHookModalPathname(pathname)) {
|
|
88
|
+
const screenData = hookModalScreenData;
|
|
89
|
+
|
|
90
|
+
return { screenData, pathname };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (isHookPathname(pathname)) {
|
|
94
|
+
return { screenData: screenDataContext, pathname };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const screenData = screenDataContext;
|
|
98
|
+
|
|
99
|
+
return { screenData, pathname };
|
|
100
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { isWeb } from "../../reactUtils";
|
|
3
|
+
import { useNavigation } from "./useNavigation";
|
|
4
|
+
import { usePathname } from "./usePathname";
|
|
5
|
+
import {
|
|
6
|
+
QUICK_BRICK_CONTENT,
|
|
7
|
+
QUICK_BRICK_NAVBAR,
|
|
8
|
+
} from "@applicaster/quick-brick-core/const";
|
|
9
|
+
|
|
10
|
+
type Return = (prefix: string) => string;
|
|
11
|
+
|
|
12
|
+
export const useUniqueRouteSuffix = (): Return => {
|
|
13
|
+
const pathname = usePathname();
|
|
14
|
+
const { currentRoute } = useNavigation();
|
|
15
|
+
|
|
16
|
+
const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
|
|
17
|
+
|
|
18
|
+
const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
|
|
19
|
+
if (isWeb()) {
|
|
20
|
+
// we should use extended route prefix only on Web, where we have stack-navigator
|
|
21
|
+
return `${prefix}___${suffix}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// for other platforms use previous version
|
|
25
|
+
return prefix;
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return withUniqueRouteSuffix;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const useNavbarId = () => {
|
|
32
|
+
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
33
|
+
|
|
34
|
+
return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const useContentId = () => {
|
|
38
|
+
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
39
|
+
|
|
40
|
+
return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
|
|
41
|
+
};
|
|
@@ -32,10 +32,10 @@ const CONFIG_LONG_PRESS = {
|
|
|
32
32
|
|
|
33
33
|
const LONG_PRESS_THRESHOLD = 500;
|
|
34
34
|
const SEEK_END_TIMEOUT_DURATION = 700;
|
|
35
|
+
// prettier-ignore
|
|
35
36
|
|
|
36
37
|
export class TVSeekController
|
|
37
|
-
implements SeekKeyHandlerListener, ISeekControllerDelegate
|
|
38
|
-
{
|
|
38
|
+
implements SeekKeyHandlerListener, ISeekControllerDelegate {
|
|
39
39
|
public delayedSeekPosition: number | null = null;
|
|
40
40
|
private readonly playerController: Player;
|
|
41
41
|
private delayedSeekProgressSubject = new BehaviorSubject<number | null>(null);
|
|
@@ -117,8 +117,8 @@ export class TVSeekController
|
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
onSeekEnd = () => {
|
|
120
|
+
this.clearLongPressThresholdTimeout();
|
|
120
121
|
this.currentSeekController.onSeekEnd();
|
|
121
|
-
this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
|
|
122
122
|
};
|
|
123
123
|
|
|
124
124
|
onRewindPressOut = () => {
|
|
@@ -129,7 +129,7 @@ export class TVSeekController
|
|
|
129
129
|
this.onSeekEnd();
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
onVideoProgress = (position: number) => {
|
|
133
133
|
if (this.delayedSeekPosition !== null) {
|
|
134
134
|
return;
|
|
135
135
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { act, renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
|
|
3
|
+
|
|
4
|
+
import { ON_HOLD_INTERVAL, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
5
|
+
|
|
6
|
+
import { useAutoSeek } from "../useAutoSeek";
|
|
7
|
+
|
|
8
|
+
jest.useFakeTimers({ legacyFakeTimers: true });
|
|
9
|
+
|
|
10
|
+
const rewind = jest.fn();
|
|
11
|
+
const forward = jest.fn();
|
|
12
|
+
|
|
13
|
+
jest
|
|
14
|
+
.spyOn(playerManager, "getInstanceController")
|
|
15
|
+
.mockReturnValue({ rewind, forward });
|
|
16
|
+
|
|
17
|
+
describe("useAutoSeek", () => {
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
rewind.mockReset();
|
|
20
|
+
forward.mockReset();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("autoSeekStart", () => {
|
|
24
|
+
it("should call forward method on playerInstance", () => {
|
|
25
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
26
|
+
|
|
27
|
+
act(() => {
|
|
28
|
+
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
expect(forward).toBeCalled();
|
|
32
|
+
result.current.autoSeekStop();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should call rewind method on playerManager", () => {
|
|
36
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
37
|
+
|
|
38
|
+
act(() => {
|
|
39
|
+
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(rewind).toBeCalled();
|
|
43
|
+
result.current.autoSeekStop();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should call rewind with default skip time", () => {
|
|
47
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
48
|
+
|
|
49
|
+
act(() => {
|
|
50
|
+
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
54
|
+
result.current.autoSeekStop();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should call forward with default skip time", () => {
|
|
58
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
59
|
+
|
|
60
|
+
act(() => {
|
|
61
|
+
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
65
|
+
result.current.autoSeekStop();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should call rewind in intervals set in configuration", () => {
|
|
69
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
70
|
+
|
|
71
|
+
act(() => {
|
|
72
|
+
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(rewind).toBeCalled();
|
|
76
|
+
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
77
|
+
expect(rewind).toBeCalledTimes(4);
|
|
78
|
+
result.current.autoSeekStop();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should call forward in intervals set in configuration", () => {
|
|
82
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
83
|
+
|
|
84
|
+
act(() => {
|
|
85
|
+
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(forward).toBeCalled();
|
|
89
|
+
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
90
|
+
expect(forward).toBeCalledTimes(4);
|
|
91
|
+
result.current.autoSeekStop();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("autoSeekStop", () => {
|
|
96
|
+
it("should stop calling playerManager method after autoSeekStop is called", () => {
|
|
97
|
+
const { result } = renderHook(() => useAutoSeek());
|
|
98
|
+
|
|
99
|
+
act(() => {
|
|
100
|
+
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
expect(forward).toBeCalled();
|
|
104
|
+
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
105
|
+
expect(forward).toBeCalledTimes(4);
|
|
106
|
+
|
|
107
|
+
act(() => {
|
|
108
|
+
result.current.autoSeekStop();
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
112
|
+
expect(forward).toBeCalledTimes(4);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
|
|
3
|
+
import { useTapSeek } from "../useTapSeek";
|
|
4
|
+
|
|
5
|
+
import { ON_PRESS_RESET_DURATION, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
6
|
+
|
|
7
|
+
const rewind = jest.fn();
|
|
8
|
+
const forward = jest.fn();
|
|
9
|
+
|
|
10
|
+
jest
|
|
11
|
+
.spyOn(playerManager, "getInstanceController")
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
.mockImplementation(() => ({ rewind, forward }));
|
|
14
|
+
|
|
15
|
+
describe("useTapSeek", () => {
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
rewind.mockReset();
|
|
18
|
+
forward.mockReset();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("forward", () => {
|
|
22
|
+
it("should call forward method on playerManager", () => {
|
|
23
|
+
const { result } = renderHook(() => useTapSeek());
|
|
24
|
+
|
|
25
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
26
|
+
expect(forward).toBeCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should call forward with default skip time", () => {
|
|
30
|
+
const { result } = renderHook(() => useTapSeek());
|
|
31
|
+
|
|
32
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
33
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should multiply skip time for every call", async () => {
|
|
37
|
+
const { result } = renderHook(() => useTapSeek());
|
|
38
|
+
|
|
39
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
40
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
41
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
42
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should reset multiplier if waiting more then resetDuration between press actions", () => {
|
|
46
|
+
const { result, waitFor } = renderHook(() => useTapSeek());
|
|
47
|
+
|
|
48
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
49
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
50
|
+
waitFor(jest.fn(), { timeout: ON_PRESS_RESET_DURATION });
|
|
51
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
52
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe("rewind", () => {
|
|
57
|
+
it("should call rewind method on playerManager", () => {
|
|
58
|
+
const { result } = renderHook(() => useTapSeek());
|
|
59
|
+
|
|
60
|
+
result.current(SEEK_TYPE.REWIND);
|
|
61
|
+
expect(rewind).toBeCalled();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should call rewind with default skip time", () => {
|
|
65
|
+
const { result } = renderHook(() => useTapSeek());
|
|
66
|
+
|
|
67
|
+
result.current(SEEK_TYPE.REWIND);
|
|
68
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("should multiply skip time for every call", async () => {
|
|
72
|
+
const { result } = renderHook(() => useTapSeek());
|
|
73
|
+
|
|
74
|
+
result.current(SEEK_TYPE.REWIND);
|
|
75
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
76
|
+
result.current(SEEK_TYPE.REWIND);
|
|
77
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("mixed usage", () => {
|
|
82
|
+
it("should reset timer if different type of event is emitted", () => {
|
|
83
|
+
const { result } = renderHook(() => useTapSeek());
|
|
84
|
+
result.current(SEEK_TYPE.REWIND);
|
|
85
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
86
|
+
|
|
87
|
+
result.current(SEEK_TYPE.REWIND);
|
|
88
|
+
expect(rewind).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
89
|
+
|
|
90
|
+
result.current(SEEK_TYPE.FORWARD);
|
|
91
|
+
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* returns a ref with an initial value that is lazily evaluated once
|
|
5
|
+
* */
|
|
6
|
+
export const useRefWithInitialValue = <T>(initialValueGetter: () => T) => {
|
|
7
|
+
const ref = React.useRef<T>(null);
|
|
8
|
+
|
|
9
|
+
if (ref.current === null) {
|
|
10
|
+
ref.current = initialValueGetter();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return ref;
|
|
14
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import type { Subject } from "rxjs";
|
|
3
|
+
|
|
4
|
+
export const useStateFromSubscribe = <T, U>(
|
|
5
|
+
subject: Subject<T>,
|
|
6
|
+
onUpdate: (
|
|
7
|
+
observerValue: T,
|
|
8
|
+
next: React.Dispatch<React.SetStateAction<U>>
|
|
9
|
+
) => void,
|
|
10
|
+
initialValue: U
|
|
11
|
+
) => {
|
|
12
|
+
const [state, setState] = useState<U>(initialValue);
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const subscription = subject.subscribe((observer) =>
|
|
16
|
+
onUpdate(observer, setState)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
return () => subscription.unsubscribe();
|
|
20
|
+
}, [subject]);
|
|
21
|
+
|
|
22
|
+
return state;
|
|
23
|
+
};
|
|
@@ -4,9 +4,10 @@ import { subscriber } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
|
4
4
|
const subscriberObjects = Object.create({});
|
|
5
5
|
|
|
6
6
|
interface UseSubscriberFor {
|
|
7
|
-
(
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
(
|
|
8
|
+
eventName: string,
|
|
9
|
+
handler?: (...args: unknown[]) => void
|
|
10
|
+
): (...args: unknown[]) => ReturnType<typeof subscriber>;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
jest.mock("create-react-ref/lib/createRef", () => jest.fn());
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import * as helpers from "../helpers";
|
|
4
3
|
|
|
@@ -8,13 +7,7 @@ import {
|
|
|
8
7
|
componentDidMount,
|
|
9
8
|
} from "./fixtures";
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
attachLifeCycleMethods,
|
|
13
|
-
createReactRef,
|
|
14
|
-
mergeChildrenProps,
|
|
15
|
-
} = require("../index");
|
|
16
|
-
|
|
17
|
-
const createRef = require("create-react-ref/lib/createRef");
|
|
10
|
+
import { attachLifeCycleMethods, createReactRef, mergeChildrenProps } from "..";
|
|
18
11
|
|
|
19
12
|
describe("attachLifeCycleMethods", () => {
|
|
20
13
|
let addLifeCycleMethodsSpy;
|
|
@@ -50,30 +43,19 @@ describe("attachLifeCycleMethods", () => {
|
|
|
50
43
|
|
|
51
44
|
describe("createReactRef", () => {
|
|
52
45
|
it("calls the React.createRef function if it exists", () => {
|
|
53
|
-
jest.
|
|
54
|
-
|
|
55
|
-
jest.doMock("react", () => ({
|
|
56
|
-
...jest.requireActual("react"),
|
|
57
|
-
createRef: jest.fn(),
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
const React = require("react");
|
|
46
|
+
jest.clearAllMocks();
|
|
61
47
|
|
|
62
|
-
createReactRef();
|
|
63
|
-
expect(
|
|
64
|
-
expect(createRef).not.toHaveBeenCalled();
|
|
48
|
+
const ref = createReactRef();
|
|
49
|
+
expect(ref).toHaveProperty("current");
|
|
65
50
|
});
|
|
66
51
|
|
|
67
52
|
it("calls the polyfill if React.createRef doesn't exist", () => {
|
|
68
|
-
jest.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
createReactRef();
|
|
76
|
-
expect(createRef).toHaveBeenCalled();
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
const originalCreateRef = React.createRef;
|
|
55
|
+
React.createRef = undefined;
|
|
56
|
+
const ref = createReactRef();
|
|
57
|
+
expect(ref).toHaveProperty("current");
|
|
58
|
+
React.createRef = originalCreateRef;
|
|
77
59
|
});
|
|
78
60
|
});
|
|
79
61
|
|
|
@@ -1,104 +1,104 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 1`] = `
|
|
4
|
-
|
|
4
|
+
{
|
|
5
5
|
"bar": "bar",
|
|
6
6
|
"foo": "foo",
|
|
7
7
|
}
|
|
8
8
|
`;
|
|
9
9
|
|
|
10
10
|
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 2`] = `
|
|
11
|
-
|
|
11
|
+
{
|
|
12
12
|
"bar": "bar",
|
|
13
13
|
"foo": "invalid foo",
|
|
14
14
|
}
|
|
15
15
|
`;
|
|
16
16
|
|
|
17
17
|
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 3`] = `
|
|
18
|
-
|
|
18
|
+
{
|
|
19
19
|
"bar": "invalid bar",
|
|
20
20
|
"foo": "invalid foo",
|
|
21
21
|
}
|
|
22
22
|
`;
|
|
23
23
|
|
|
24
24
|
exports[`createContextSetters when no state validator is provided calls setState when the setters are called, no matter what the value is 4`] = `
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
[
|
|
26
|
+
[
|
|
27
27
|
[Function],
|
|
28
28
|
],
|
|
29
|
-
|
|
29
|
+
[
|
|
30
30
|
[Function],
|
|
31
31
|
],
|
|
32
32
|
]
|
|
33
33
|
`;
|
|
34
34
|
|
|
35
35
|
exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 1`] = `
|
|
36
|
-
|
|
36
|
+
{
|
|
37
37
|
"bar": "bar",
|
|
38
38
|
"foo": "foo",
|
|
39
39
|
}
|
|
40
40
|
`;
|
|
41
41
|
|
|
42
42
|
exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 2`] = `
|
|
43
|
-
|
|
43
|
+
{
|
|
44
44
|
"bar": "bar",
|
|
45
45
|
"foo": "new foo",
|
|
46
46
|
}
|
|
47
47
|
`;
|
|
48
48
|
|
|
49
49
|
exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 3`] = `
|
|
50
|
-
|
|
50
|
+
{
|
|
51
51
|
"bar": "new bar",
|
|
52
52
|
"foo": "new foo",
|
|
53
53
|
}
|
|
54
54
|
`;
|
|
55
55
|
|
|
56
56
|
exports[`createContextSetters when state validator is provided calls setState when the setters are called & the validator passes 4`] = `
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
[
|
|
58
|
+
[
|
|
59
59
|
[Function],
|
|
60
60
|
],
|
|
61
|
-
|
|
61
|
+
[
|
|
62
62
|
[Function],
|
|
63
63
|
],
|
|
64
64
|
]
|
|
65
65
|
`;
|
|
66
66
|
|
|
67
67
|
exports[`createContextSetters when state validator is provided skips the update if the new value is the same as the previous one 1`] = `
|
|
68
|
-
|
|
68
|
+
{
|
|
69
69
|
"bar": "bar",
|
|
70
70
|
"foo": "new foo",
|
|
71
71
|
}
|
|
72
72
|
`;
|
|
73
73
|
|
|
74
74
|
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 1`] = `
|
|
75
|
-
|
|
75
|
+
{
|
|
76
76
|
"bar": "bar",
|
|
77
77
|
"foo": "foo",
|
|
78
78
|
}
|
|
79
79
|
`;
|
|
80
80
|
|
|
81
81
|
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 2`] = `
|
|
82
|
-
|
|
82
|
+
{
|
|
83
83
|
"bar": "bar",
|
|
84
84
|
"foo": "foo",
|
|
85
85
|
}
|
|
86
86
|
`;
|
|
87
87
|
|
|
88
88
|
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 3`] = `
|
|
89
|
-
|
|
89
|
+
{
|
|
90
90
|
"bar": "bar",
|
|
91
91
|
"foo": "foo",
|
|
92
92
|
}
|
|
93
93
|
`;
|
|
94
94
|
|
|
95
95
|
exports[`createContextSetters when state validator is provided skips the update if the state validator doesn't pass 4`] = `
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
[
|
|
97
|
+
[
|
|
98
98
|
"trying to invoke setFoo with invalid foo - but it was rejected by the state validator
|
|
99
99
|
skipping context update",
|
|
100
100
|
],
|
|
101
|
-
|
|
101
|
+
[
|
|
102
102
|
"trying to invoke setBar with invalid bar - but it was rejected by the state validator
|
|
103
103
|
skipping context update",
|
|
104
104
|
],
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
3
|
exports[`createContext - when React has the new context API returns the components and the decorators 1`] = `
|
|
4
|
-
|
|
4
|
+
{
|
|
5
5
|
"Consumer": [MockFunction],
|
|
6
6
|
"Provider": [MockFunction],
|
|
7
|
-
"ReactContext":
|
|
7
|
+
"ReactContext": {
|
|
8
8
|
"Consumer": [MockFunction],
|
|
9
9
|
"Provider": [MockFunction],
|
|
10
10
|
},
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
exports[`createProvider creates a context Provider component 1`] = `
|
|
4
4
|
<mockConstructor
|
|
5
5
|
value={
|
|
6
|
-
|
|
6
|
+
{
|
|
7
7
|
"context": "initialValue",
|
|
8
8
|
"otherContext": "otherValue",
|
|
9
9
|
"setContext": [Function],
|
|
@@ -18,11 +18,11 @@ exports[`createProvider creates a context Provider component 1`] = `
|
|
|
18
18
|
`;
|
|
19
19
|
|
|
20
20
|
exports[`createProvider creates a context Provider component 2`] = `
|
|
21
|
-
|
|
21
|
+
{
|
|
22
22
|
"children": <MockChild
|
|
23
23
|
context="context"
|
|
24
24
|
/>,
|
|
25
|
-
"value":
|
|
25
|
+
"value": {
|
|
26
26
|
"context": "initialValue",
|
|
27
27
|
"otherContext": "otherValue",
|
|
28
28
|
"setContext": [Function],
|