@applicaster/zapp-react-native-utils 13.0.0-alpha.2635505531 → 13.0.0-alpha.2761483533

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.
Files changed (108) hide show
  1. package/actionsExecutor/ActionExecutor.ts +16 -9
  2. package/actionsExecutor/ActionExecutorContext.tsx +74 -9
  3. package/alertUtils/alert.ts +148 -0
  4. package/alertUtils/index.ts +1 -148
  5. package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
  6. package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
  7. package/analyticsUtils/helpers/hooks.ts +1 -1
  8. package/appUtils/HooksManager/{Hook.js → Hook.ts} +35 -23
  9. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +10 -8
  10. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +693 -0
  11. package/appUtils/HooksManager/__tests__/hook.test.js +196 -184
  12. package/appUtils/HooksManager/__tests__/hooksManager.test.js +96 -99
  13. package/appUtils/HooksManager/{constants.js → constants.ts} +1 -1
  14. package/appUtils/HooksManager/{index.js → index.ts} +121 -112
  15. package/appUtils/HooksManager/types.ts +119 -0
  16. package/appUtils/RiverFocusManager/index.js +17 -12
  17. package/appUtils/accessibilityManager/index.ts +42 -1
  18. package/appUtils/contextKeysManager/contextResolver.ts +73 -0
  19. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +6 -6
  20. package/appUtils/focusManager/index.ts +92 -64
  21. package/appUtils/focusManager/treeDataStructure/Tree/index.js +25 -3
  22. package/appUtils/focusManager/treeDataStructure/Utils/index.js +1 -3
  23. package/appUtils/focusManager/utils/enums.ts +4 -0
  24. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  25. package/appUtils/{index.js → index.ts} +1 -1
  26. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
  27. package/appUtils/keyCodes/__tests__/keyCodes.test.js +4 -4
  28. package/appUtils/keyCodes/{index.js → index.ts} +2 -0
  29. package/appUtils/keyCodes/keys/index.ts +3 -0
  30. package/appUtils/keyCodes/{keys.android.js → keys/keyEventMapper.ts} +0 -19
  31. package/appUtils/keyCodes/keys/keys.android.ts +18 -0
  32. package/appUtils/keyCodes/keys/keys.ios.ts +25 -0
  33. package/appUtils/keyCodes/keys/keys.ts +15 -0
  34. package/appUtils/keyCodes/{keysByPlatform.js → keys/keysByPlatform.ts} +4 -3
  35. package/appUtils/keyCodes/keysByPlatform.ts +8 -0
  36. package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
  37. package/appUtils/orientationHelper.ts +1 -1
  38. package/appUtils/platform/const.ts +14 -0
  39. package/appUtils/platform/platformUtils.ts +17 -15
  40. package/appUtils/playerManager/index.ts +6 -2
  41. package/appUtils/playerManager/player.ts +12 -8
  42. package/appUtils/playerManager/playerNative.ts +1 -1
  43. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -15
  44. package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
  45. package/domUtils/{cookieManager.js → cookieManager.ts} +1 -2
  46. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
  47. package/functionUtils/index.ts +15 -11
  48. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  49. package/idleUtils/index.ts +1 -1
  50. package/idleUtils/withTimeout.ts +15 -2
  51. package/logger/const.ts +9 -67
  52. package/manifestUtils/__tests__/createConfig.test.js +18 -16
  53. package/modalState/index.ts +1 -5
  54. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +6 -6
  55. package/navigationUtils/__tests__/itemTypes.test.js +2 -2
  56. package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
  57. package/navigationUtils/index.ts +14 -5
  58. package/package.json +3 -2
  59. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  60. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -1
  61. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  62. package/reactHooks/cell-click/index.ts +7 -1
  63. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
  64. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
  65. package/reactHooks/feed/useFeedLoader.tsx +1 -1
  66. package/reactHooks/feed/usePipesCacheReset.ts +5 -5
  67. package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
  68. package/reactHooks/layout/__tests__/index.test.tsx +10 -10
  69. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
  70. package/reactHooks/navigation/__tests__/index.test.tsx +0 -4
  71. package/reactHooks/navigation/index.ts +29 -218
  72. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
  73. package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
  74. package/reactHooks/navigation/useGetTabBarHeight.ts +12 -0
  75. package/reactHooks/navigation/useIsScreenActive.ts +17 -0
  76. package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
  77. package/reactHooks/navigation/useNavigationType.ts +15 -0
  78. package/reactHooks/navigation/usePathname.ts +4 -0
  79. package/reactHooks/navigation/useRoute.ts +100 -0
  80. package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
  81. package/reactHooks/player/TVSeekControlller/ISeekController.ts +28 -3
  82. package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +43 -96
  83. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +203 -97
  84. package/reactHooks/player/TVSeekControlller/TapSeekController.ts +35 -55
  85. package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -10
  86. package/reactHooks/player/const.ts +1 -5
  87. package/reactHooks/player/index.ts +0 -6
  88. package/reactUtils/__tests__/reactUtils.test.js +10 -28
  89. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +19 -19
  90. package/reactUtils/createContext/__tests__/__snapshots__/index.test.js.snap +2 -2
  91. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -3
  92. package/reactUtils/createContext/__tests__/helpers.test.js +8 -8
  93. package/reactUtils/index.ts +0 -14
  94. package/theme/__mocks__/index.ts +4 -0
  95. package/time/Timer.ts +1 -1
  96. package/types.ts +1 -0
  97. package/appUtils/keyCodes/keys.ios.js +0 -46
  98. package/appUtils/playerManager/DelayedSeekPlayerWrapper.tsx +0 -180
  99. package/reactHooks/player/useAutoSeek.tsx +0 -106
  100. package/reactHooks/player/useSeek.tsx +0 -17
  101. package/reactHooks/player/useTapSeek.tsx +0 -85
  102. /package/appUtils/HooksManager/{logger.js → logger.ts} +0 -0
  103. /package/appUtils/{directionHelper.js → directionHelper.ts} +0 -0
  104. /package/appUtils/keyCodes/{androidTVKeys.js → androidTVKeys.ts} +0 -0
  105. /package/appUtils/keyCodes/{keys.web.js → keys/keys.web.ts} +0 -0
  106. /package/appUtils/{localizationsHelper.js → localizationsHelper.ts} +0 -0
  107. /package/domUtils/{logger.js → logger.ts} +0 -0
  108. /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
@@ -1,10 +1,6 @@
1
1
  export const SKIP_TIME_BASE = 10;
2
2
 
3
- export const ON_PRESS_RESET_DURATION = 2000;
4
-
5
- export const ON_HOLD_INTERVAL = 500;
6
-
7
- export const MAX_SEEK_TIME = 60;
3
+ export const MAX_SEEK_TIME = 600;
8
4
 
9
5
  export enum SEEK_TYPE {
10
6
  FORWARD = "forward",
@@ -1,7 +1 @@
1
1
  export { useLanguageData } from "./useLanguageData";
2
-
3
- export { useAutoSeek } from "./useAutoSeek";
4
-
5
- export { useTapSeek } from "./useTapSeek";
6
-
7
- export { useSeek, withUseSeek } from "./useSeek";
@@ -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
- const {
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.resetModules();
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(React.createRef).toHaveBeenCalled();
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.resetModules();
69
-
70
- jest.doMock("react", () => ({
71
- ...jest.requireActual("react"),
72
- createRef: undefined,
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
- Object {
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
- Object {
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
- Object {
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
- Array [
26
- Array [
25
+ [
26
+ [
27
27
  [Function],
28
28
  ],
29
- Array [
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
- Object {
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
- Object {
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
- Object {
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
- Array [
58
- Array [
57
+ [
58
+ [
59
59
  [Function],
60
60
  ],
61
- Array [
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
- Object {
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
- Object {
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
- Object {
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
- Object {
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
- Array [
97
- Array [
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
- Array [
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
- Object {
4
+ {
5
5
  "Consumer": [MockFunction],
6
6
  "Provider": [MockFunction],
7
- "ReactContext": Object {
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
- Object {
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
- Object {
21
+ {
22
22
  "children": <MockChild
23
23
  context="context"
24
24
  />,
25
- "value": Object {
25
+ "value": {
26
26
  "context": "initialValue",
27
27
  "otherContext": "otherValue",
28
28
  "setContext": [Function],
@@ -9,13 +9,13 @@ function stateValidator({ property, value }) {
9
9
  );
10
10
  }
11
11
 
12
- const logger = {
12
+ const mockLogger = {
13
13
  warning: jest.fn(),
14
14
  };
15
15
 
16
16
  jest.mock("../../logger", () => ({
17
17
  reactUtilsLogger: {
18
- addSubsystem: jest.fn(() => logger),
18
+ addSubsystem: jest.fn(() => mockLogger),
19
19
  },
20
20
  }));
21
21
 
@@ -62,7 +62,7 @@ describe("createContextSetters", () => {
62
62
  beforeEach(() => {
63
63
  instance.resetInitialState();
64
64
  setStateSpy.mockClear();
65
- logger.warning.mockClear();
65
+ mockLogger.warning.mockClear();
66
66
  });
67
67
 
68
68
  it("adds all properties and setters to the component", () => {
@@ -83,7 +83,7 @@ describe("createContextSetters", () => {
83
83
 
84
84
  expect(setStateSpy).toHaveBeenCalledTimes(2);
85
85
  expect(setStateSpy.mock.calls).toMatchSnapshot();
86
- expect(logger.warning).not.toHaveBeenCalled();
86
+ expect(mockLogger.warning).not.toHaveBeenCalled();
87
87
  });
88
88
 
89
89
  it("skips the update if the state validator doesn't pass", () => {
@@ -96,8 +96,8 @@ describe("createContextSetters", () => {
96
96
  expect(instance.state).toMatchSnapshot();
97
97
 
98
98
  expect(setStateSpy).not.toHaveBeenCalled();
99
- expect(logger.warning).toHaveBeenCalledTimes(2);
100
- expect(logger.warning.mock.calls).toMatchSnapshot();
99
+ expect(mockLogger.warning).toHaveBeenCalledTimes(2);
100
+ expect(mockLogger.warning.mock.calls).toMatchSnapshot();
101
101
  });
102
102
 
103
103
  it("skips the update if the new value is the same as the previous one", () => {
@@ -131,7 +131,7 @@ describe("createContextSetters", () => {
131
131
 
132
132
  afterEach(() => {
133
133
  setStateSpy.mockClear();
134
- logger.warning.mockClear();
134
+ mockLogger.warning.mockClear();
135
135
  });
136
136
 
137
137
  it("adds all properties and setters to the component", () => {
@@ -152,7 +152,7 @@ describe("createContextSetters", () => {
152
152
 
153
153
  expect(setStateSpy).toHaveBeenCalledTimes(2);
154
154
  expect(setStateSpy.mock.calls).toMatchSnapshot();
155
- expect(logger.warning).not.toHaveBeenCalled();
155
+ expect(mockLogger.warning).not.toHaveBeenCalled();
156
156
  });
157
157
  });
158
158
  });
@@ -109,20 +109,6 @@ export const isTvOSPlatform = () => getPlatform() === "tvos";
109
109
 
110
110
  export const isAndroidTVPlatform = () => getPlatform() === "android_tv";
111
111
 
112
- declare global {
113
- interface Window {
114
- VIZIO?: {
115
- Chromevox: {
116
- play: (text: string) => void;
117
- };
118
- exitApplication: () => void;
119
- setClosedCaptionHandler: (
120
- callback: (isCCEnabled: boolean) => void
121
- ) => void;
122
- };
123
- }
124
- }
125
-
126
112
  /**
127
113
  * Platforms found in userAgent string, please note that simulators
128
114
  * might not have the same agents that the devices have
@@ -1,3 +1,5 @@
1
+ import React from "react";
2
+
1
3
  export const themeMock = {
2
4
  screen_padding_top: 20,
3
5
  screen_padding_bottom: 48,
@@ -17,3 +19,5 @@ export const themeMock = {
17
19
  };
18
20
 
19
21
  export const useTheme = jest.fn().mockReturnValue(themeMock);
22
+
23
+ export const ThemeContext = React.createContext(themeMock);
package/time/Timer.ts CHANGED
@@ -4,7 +4,7 @@ export class Timer {
4
4
  private timeoutId: NodeJS.Timeout | null;
5
5
 
6
6
  constructor(private callback: () => void, private duration: number) {
7
- this.remaining = duration;
7
+ this.remaining = this.duration;
8
8
  this.timeoutId = null;
9
9
  }
10
10
 
package/types.ts CHANGED
@@ -8,4 +8,5 @@ export type ManifestField<T> = {
8
8
 
9
9
  export enum ENDPOINT_TAGS {
10
10
  allow_missing_keys = "allow_missing_keys",
11
+ observe_storage = "observe_storage",
11
12
  }
@@ -1,46 +0,0 @@
1
- /* global tizen */
2
- const isTizen = typeof tizen !== "undefined";
3
-
4
- export const KEYS = {
5
- Enter: { code: "Enter", keyCode: 13 },
6
- Space: { code: "Space", keyCode: 32 },
7
- m: { code: "m", keyCode: 77 },
8
- ArrowLeft: { code: "ArrowLeft", keyCode: 37 },
9
- ArrowUp: { code: "ArrowUp", keyCode: 38 },
10
- ArrowRight: { code: "ArrowRight", keyCode: 39 },
11
- ArrowDown: { code: "ArrowDown", keyCode: 40 },
12
- Back: isTizen
13
- ? { code: "Back", keyCode: 10009 }
14
- : { code: "Backspace", keyCode: 8 },
15
- Play: isTizen
16
- ? { code: "MediaPlay", keyCode: 10252 }
17
- : { code: "PlayPause", keyCode: 179 },
18
- Pause: isTizen
19
- ? { code: "MediaPause", keyCode: 19 }
20
- : { code: "Pause", keyCode: 179 },
21
- Forward: isTizen
22
- ? { code: "MediaFastForward", keyCode: 417 }
23
- : { code: "Forward", keyCode: 176 },
24
- Rewind: isTizen
25
- ? { code: "MediaRewind", keyCode: 412 }
26
- : { code: "Rewind", keyCode: 177 },
27
- VolumeUp: isTizen
28
- ? { code: "VolumeUp", keyCode: 447 }
29
- : { code: "VolumeUp", keyCode: 175 },
30
- VolumeDown: isTizen
31
- ? { code: "VolumeDown", keyCode: 448 }
32
- : { code: "VolumeDown", keyCode: 174 },
33
- ToggleMute: isTizen
34
- ? { code: "VolumeMute", keyCode: 449 }
35
- : { code: "VolumeMute", keyCode: 173 },
36
- Stop: isTizen
37
- ? { code: "MediaStop", keyCode: 413 }
38
- : { code: "Q", keyCode: 81 },
39
- };
40
-
41
- export const ARROW_KEYS = [
42
- KEYS.ArrowUp,
43
- KEYS.ArrowLeft,
44
- KEYS.ArrowDown,
45
- KEYS.ArrowRight,
46
- ];
@@ -1,180 +0,0 @@
1
- import { Player } from "./player";
2
- import { BehaviorSubject } from "rxjs";
3
-
4
- export class DelayedSeekPlayerWrapper extends Player {
5
- private wrappedPlayer: Player;
6
- private delayedSeekPosition: number;
7
- private wasPlaying: boolean;
8
-
9
- constructor(props, player: Player) {
10
- super(props);
11
- this.wrappedPlayer = player;
12
- this.delayedSeekPosition = null;
13
-
14
- this.wrappedPlayer.addListener({
15
- id: "Master-Wrapper-Listener",
16
- listener: this,
17
- });
18
-
19
- this.onPlayerSeekComplete = this.onPlayerSeekComplete.bind(this);
20
- }
21
-
22
- getOverlayObservable = () => {
23
- return this.wrappedPlayer.getOverlayObservable();
24
- };
25
-
26
- getEntryObservable = (): BehaviorSubject<ZappEntry | null> => {
27
- return this.wrappedPlayer.getEntryObservable();
28
- };
29
-
30
- getEntry = (): ZappEntry | null => this.wrappedPlayer.getEntry();
31
-
32
- getListener = (): QuickBrickPlayer.SharedPlayerCallBacks => {
33
- return this.wrappedPlayer.getListener();
34
- };
35
-
36
- togglePlayPause = () => {
37
- this.wrappedPlayer.togglePlayPause();
38
- };
39
-
40
- selectTrack = (_track) => this.wrappedPlayer.selectTrack(_track);
41
-
42
- // Implement all default methods by delegating them to wrapped player
43
- public seekTo = (position: number) => {
44
- this.wrappedPlayer.seekTo(position);
45
- };
46
-
47
- public isPlaying = () => {
48
- return this.wrappedPlayer.isPlaying();
49
- };
50
-
51
- public isPaused = () => {
52
- return this.wrappedPlayer.isPaused();
53
- };
54
-
55
- public play = () => {
56
- this.wrappedPlayer.play();
57
- };
58
-
59
- public pause = () => {
60
- this.wrappedPlayer.pause();
61
- };
62
-
63
- getState = () => {
64
- const currentState = this.wrappedPlayer.getState();
65
-
66
- if (this.delayedSeekPosition === null) {
67
- return currentState;
68
- }
69
-
70
- return {
71
- ...currentState,
72
- contentPosition: this.delayedSeekPosition,
73
- isPaused: false,
74
- seekPosition: this.delayedSeekPosition,
75
- };
76
- };
77
-
78
- forward = (deltaTime: number) => {
79
- if (this.delayedSeekPosition !== null) {
80
- this.delayedSeekPosition += deltaTime;
81
- this.playerState.seekPosition = this.delayedSeekPosition;
82
-
83
- this.onVideoProgress({
84
- currentTime: this.playerState.seekPosition,
85
- duration: this.getDuration(),
86
- seekableDuration: this.playerState.seekableDuration,
87
- isLive: this.playerState.isLive,
88
- });
89
-
90
- // this.scheduleResumePlayback(DELAYED_SEEK_DELAY, this.delayedSeekPosition);
91
-
92
- return;
93
- }
94
-
95
- if (this.playerState.seekPosition == null) {
96
- this.playerState.seekPosition = this.playerState.contentPosition;
97
- }
98
-
99
- this.playerState.seekPosition += deltaTime;
100
-
101
- this.wrappedPlayer.forward(deltaTime);
102
- };
103
-
104
- rewind = (deltaTime: number) => {
105
- if (this.delayedSeekPosition !== null) {
106
- this.delayedSeekPosition -= deltaTime;
107
-
108
- if (this.delayedSeekPosition < 0) {
109
- this.delayedSeekPosition = 0;
110
- }
111
-
112
- this.playerState.seekPosition = this.delayedSeekPosition;
113
-
114
- this.onVideoProgress({
115
- currentTime: this.playerState.seekPosition,
116
- duration: this.getDuration(),
117
- seekableDuration: this.playerState.seekableDuration,
118
- isLive: this.playerState.isLive,
119
- });
120
-
121
- // this.scheduleResumePlayback(DELAYED_SEEK_DELAY, this.delayedSeekPosition);
122
-
123
- return;
124
- }
125
-
126
- if (this.playerState.seekPosition == null) {
127
- this.playerState.seekPosition = this.playerState.contentPosition;
128
- }
129
-
130
- this.playerState.seekPosition -= deltaTime;
131
- this.wrappedPlayer.rewind(deltaTime);
132
- };
133
-
134
- public getConfig = () => this.wrappedPlayer.getConfig();
135
-
136
- // TODO: replace with enum of supported orientations
137
- isFullScreenSupported(): boolean {
138
- return this.wrappedPlayer.isFullScreenSupported();
139
- }
140
-
141
- public supportsNativeControls = (): boolean =>
142
- this.wrappedPlayer.supportsNativeControls();
143
-
144
- public supportNativeCast = (): boolean =>
145
- this.wrappedPlayer.supportNativeCast();
146
-
147
- public isInDelayedSeek = () => this.delayedSeekPosition !== null;
148
-
149
- public enterDelayedSeek() {
150
- if (this.delayedSeekPosition !== null) {
151
- return;
152
- }
153
-
154
- if (this.playerState.seekPosition === null) {
155
- this.playerState.seekPosition = this.playerState.contentPosition;
156
- }
157
-
158
- this.delayedSeekPosition = this.playerState.seekPosition;
159
-
160
- if (!this.isPaused()) {
161
- this.wasPlaying = true;
162
- this.wrappedPlayer.pause();
163
- }
164
- }
165
-
166
- public exitDelayedSeek() {
167
- if (this.delayedSeekPosition === null) {
168
- return;
169
- }
170
-
171
- this.wrappedPlayer.seekTo(this.delayedSeekPosition);
172
-
173
- if (this.wasPlaying) {
174
- this.wasPlaying = false;
175
- this.wrappedPlayer.play();
176
- }
177
-
178
- this.delayedSeekPosition = null;
179
- }
180
- }
@@ -1,106 +0,0 @@
1
- import React, { useEffect, useState } from "react";
2
- import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
3
- import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
4
- import {
5
- MAX_SEEK_TIME,
6
- ON_HOLD_INTERVAL,
7
- SEEK_TYPE,
8
- SKIP_TIME_BASE,
9
- } from "./const";
10
- import { noop } from "../../functionUtils";
11
-
12
- export const useAutoSeek = (resetHUDTimer = noop) => {
13
- const [isRunning, setIsRunning] = useState<boolean>(false);
14
- const [direction, setDirection] = useState<Nullable<SEEK_TYPE>>(null);
15
- const [multiplier, setMultiplier] = useState(1);
16
-
17
- const intervalTimer = React.useRef(null);
18
- const prevRunning = usePrevious(isRunning);
19
-
20
- const setIntervalTimer = (cb) => {
21
- if (intervalTimer.current) {
22
- return;
23
- }
24
-
25
- intervalTimer.current = setInterval(() => {
26
- intervalTimer.current = null;
27
- cb();
28
- }, ON_HOLD_INTERVAL);
29
- };
30
-
31
- const clearIntervalTimer = () => {
32
- clearInterval(intervalTimer.current);
33
- intervalTimer.current = null;
34
- };
35
-
36
- const resetState = () => {
37
- setIsRunning(false);
38
- setDirection(null);
39
- setMultiplier(1);
40
- clearIntervalTimer();
41
- };
42
-
43
- useEffect(() => {
44
- const player = playerManager.getInstanceController();
45
- if (!player) return;
46
-
47
- if (isRunning) {
48
- player?.enterDelayedSeek();
49
- } else if (!isRunning) {
50
- player.exitDelayedSeek();
51
- }
52
- }, [isRunning]);
53
-
54
- useEffect(() => {
55
- if (!isRunning) {
56
- return;
57
- }
58
-
59
- const player = playerManager.getInstanceController();
60
-
61
- if (!player) return;
62
-
63
- if (direction) {
64
- player[direction](Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier));
65
- resetHUDTimer();
66
- }
67
- }, [multiplier, direction, isRunning]);
68
-
69
- useEffect(() => {
70
- if (isRunning && isRunning !== prevRunning) {
71
- setIntervalTimer(() => {
72
- setMultiplier((prev) => {
73
- return prev + 1;
74
- });
75
- });
76
- } else if (!isRunning && isRunning !== prevRunning) {
77
- resetState();
78
- }
79
-
80
- return () => {
81
- clearIntervalTimer();
82
- };
83
- }, [isRunning, direction]);
84
-
85
- const autoSeekStop = React.useCallback(() => {
86
- resetState();
87
- }, []);
88
-
89
- const autoSeekStart = React.useCallback(
90
- (eventType: SEEK_TYPE) => {
91
- // Check if there is another session running
92
- if (isRunning) {
93
- autoSeekStop();
94
- }
95
-
96
- setDirection(eventType);
97
- setIsRunning(true);
98
- },
99
- [isRunning, autoSeekStop]
100
- );
101
-
102
- return React.useMemo(
103
- () => ({ autoSeekStart, autoSeekStop }),
104
- [autoSeekStart, autoSeekStop]
105
- );
106
- };