@applicaster/zapp-react-native-utils 12.0.0-alpha.7754333813 → 12.0.0-alpha.7855034103

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.
@@ -0,0 +1,25 @@
1
+ import * as R from "ramda";
2
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
3
+
4
+ export const getVideojsAnalyticPluginsConfig = async (entry: ZappEntry) => {
5
+ let videojsConfiguration = {};
6
+
7
+ const plugins = appStore.get("plugins");
8
+ const analyticPlugins = R.filter(R.propEq("type", "analytics"), plugins);
9
+
10
+ const configurations = await Promise.all(
11
+ analyticPlugins.map(async (plugin) => {
12
+ const { configuration, module } = plugin;
13
+
14
+ return module?.getPlayerConfiguration?.(configuration, entry);
15
+ })
16
+ );
17
+
18
+ configurations.forEach((analyticConfig) => {
19
+ if (typeof analyticConfig === "object" && analyticConfig !== null) {
20
+ videojsConfiguration = { ...videojsConfiguration, ...analyticConfig };
21
+ }
22
+ });
23
+
24
+ return videojsConfiguration;
25
+ };
@@ -461,6 +461,7 @@ export class PlayerManager {
461
461
  if (this.castingReceiver) {
462
462
  this.castingReceiver.closeNativePlayer();
463
463
  } else {
464
+ this.getActivePlayer().closeNativePlayer();
464
465
  this.invokeHandler("close");
465
466
  }
466
467
  }
@@ -221,6 +221,7 @@ export class PlayerNative extends Player {
221
221
  };
222
222
 
223
223
  closeNativePlayer = () => {
224
+ RNPlayerManager?.[this.playerPluginId]?.stopBackgroundPlayback?.();
224
225
  // TODO: Delete does not work
225
226
  this.currentPlayerComponent()?.["closeNativePlayer"]?.();
226
227
  };
@@ -4,6 +4,7 @@ import { useEffect } from "react";
4
4
  import { playerManager } from "./index";
5
5
  import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
6
6
  import { PlayerRole } from "./conts";
7
+ import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
7
8
 
8
9
  // TODO: Rename to ControllerType
9
10
  export const usePlayerControllerSetup = ({
@@ -34,10 +35,14 @@ export const usePlayerControllerSetup = ({
34
35
  useValidatePlayerConfig(config);
35
36
 
36
37
  useEffect(() => {
38
+ const newConfig = isAppleTV()
39
+ ? { supports_native_controls: true, ...config }
40
+ : config;
41
+
37
42
  const newPlayerController = new ControllerType({
38
43
  player: ref,
39
44
  listener: props as any,
40
- config,
45
+ config: newConfig,
41
46
  playerId,
42
47
  entry,
43
48
  playerPluginId: pluginId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-alpha.7754333813",
3
+ "version": "12.0.0-alpha.7855034103",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "12.0.0-alpha.7754333813",
31
+ "@applicaster/applicaster-types": "12.0.0-alpha.7855034103",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -6,6 +6,7 @@ import { waitFor } from "@testing-library/react-native";
6
6
  const navigator = {
7
7
  getPathname: () => "pathnameMock",
8
8
  push: jest.fn(),
9
+ data: {},
9
10
  };
10
11
 
11
12
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
@@ -28,6 +29,10 @@ jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
28
29
  },
29
30
  }));
30
31
 
32
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
33
+ useScreenContext: jest.fn(() => navigator.data),
34
+ }));
35
+
31
36
  const { useCellClick } = require("../");
32
37
 
33
38
  const mockProps = {
@@ -1,6 +1,7 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
 
3
3
  import * as React from "react";
4
+ import { useContext } from "react";
4
5
  import * as R from "ramda";
5
6
  import { handleActionSchemeUrl } from "@applicaster/quick-brick-core/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler";
6
7
  import { CellTapContext } from "@applicaster/zapp-react-native-ui-components/Contexts/CellTapContext";
@@ -12,7 +13,6 @@ import {
12
13
  import { ZappPipesEntryContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
13
14
  import { toBooleanWithDefaultTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
14
15
  import { noop } from "../../functionUtils";
15
- import { useContext } from "react";
16
16
  import { ActionExecutorContext } from "../../actionsExecutor/ActionExecutorContext";
17
17
  import { useSendAnalyticsOnPress } from "../analytics";
18
18
  import { logOnPress, warnEmptyContentType } from "./helpers";
@@ -83,7 +83,7 @@ export const useCellClick = (props: Props) => {
83
83
  if (typeof onCellTap === "function") {
84
84
  onCellTap(selectedItem, _index);
85
85
  } else {
86
- if (currentRoute === pathname || pathname === "videoModal") {
86
+ if (currentRoute === pathname || pathname.includes("video-modal")) {
87
87
  const targetScreen = component?.data?.target;
88
88
 
89
89
  push(
@@ -1,12 +1,13 @@
1
1
  import React from "react";
2
2
  import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
3
3
  import { renderHook } from "@testing-library/react-hooks";
4
- import { useRoute, isNavBarVisible } from "../";
4
+ import { isNavBarVisible, useRoute } from "../";
5
5
  import { Provider } from "react-redux";
6
6
  import configureMockStore from "redux-mock-store";
7
7
  import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
8
8
  import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
9
9
  import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
10
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
10
11
 
11
12
  const plugins = [];
12
13
 
@@ -100,13 +101,15 @@ const mainStackWrapper = ({
100
101
  pathname = homeStack.route,
101
102
  }) => (
102
103
  <Provider store={store}>
103
- <NavigationContext.Provider
104
- value={{ ...mainStackNavigator, ...navigator, currentRoute: pathname }}
105
- >
106
- <PathnameContext.Provider value={pathname}>
107
- {children}
108
- </PathnameContext.Provider>
109
- </NavigationContext.Provider>
104
+ <ScreenDataContext.Provider value={homeStack.state}>
105
+ <NavigationContext.Provider
106
+ value={{ ...mainStackNavigator, ...navigator, currentRoute: pathname }}
107
+ >
108
+ <PathnameContext.Provider value={pathname}>
109
+ {children}
110
+ </PathnameContext.Provider>
111
+ </NavigationContext.Provider>
112
+ </ScreenDataContext.Provider>
110
113
  </Provider>
111
114
  );
112
115
 
@@ -1,9 +1,10 @@
1
1
  /* eslint-disable @typescript-eslint/no-use-before-define */
2
2
  /* eslint max-len: off */
3
3
 
4
- import React, { useEffect, useMemo } from "react";
4
+ import React, { useContext, useEffect, useMemo } from "react";
5
5
  import { BackHandler, InteractionManager, NativeModules } from "react-native";
6
6
  import { useSafeAreaInsets } from "react-native-safe-area-context";
7
+ import { isEmpty } from "ramda";
7
8
 
8
9
  import {
9
10
  useContentTypes,
@@ -31,6 +32,7 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
31
32
  import { useNavbarState } from "../screen";
32
33
  import { useNavigation } from "./useNavigation";
33
34
  import { useModalStore } from "../../modalState";
35
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
34
36
 
35
37
  export { useNavigation } from "./useNavigation";
36
38
 
@@ -146,16 +148,8 @@ export const useRoute = (): {
146
148
  pathname: string;
147
149
  } => {
148
150
  const pathname = usePathname() || "";
149
-
150
- /**
151
- * compose `useRoute()` output data
152
- */
153
- const composeRouteData = (screenData: VariousScreenData) => ({
154
- screenData,
155
- pathname,
156
- });
157
-
158
151
  const navigator = useNavigation();
152
+ const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
159
153
 
160
154
  const { plugins, contentTypes, rivers } = usePickFromState([
161
155
  "plugins",
@@ -163,10 +157,11 @@ export const useRoute = (): {
163
157
  "contentTypes",
164
158
  ]);
165
159
 
166
- const currentStack = navigator.getStackForPathname(pathname);
167
160
  const { modalState } = useModalStore();
168
161
  const hookModalState = useZappHooksModalState();
162
+
169
163
  const modalScreenData = modalState.screen;
164
+
170
165
  const hookModalScreenData = hookModalState.state.screenData?.payload;
171
166
 
172
167
  const videoModalScreenData =
@@ -183,15 +178,6 @@ export const useRoute = (): {
183
178
  plugins
184
179
  );
185
180
 
186
- const currentRouteScreenData = legacyScreenData(
187
- {
188
- screen: currentStack?.state?.screen ?? navigator.data?.screen ?? {},
189
- entry: currentStack?.state?.entry ?? {},
190
- } as NavigationScreenData,
191
-
192
- plugins
193
- );
194
-
195
181
  // There are 4 route scenarios
196
182
  // For regular screens take date from navigator stack.
197
183
  // is path is model grab screenData from modal state
@@ -200,63 +186,33 @@ export const useRoute = (): {
200
186
  // if path is hook grab screenData from screenData
201
187
 
202
188
  if (isModalPathname(pathname)) {
203
- return composeRouteData(modalScreenData ?? ({} as ZappEntry));
189
+ const screenData = modalScreenData ?? ({} as ZappEntry);
190
+
191
+ return { screenData, pathname };
204
192
  }
205
193
 
206
194
  if (isVideoModalPathname(pathname)) {
207
- return composeRouteData(videoModalScreenData as LegacyNavigationScreenData);
195
+ const screenData = videoModalScreenData as LegacyNavigationScreenData;
196
+
197
+ return { screenData, pathname };
208
198
  }
209
199
 
210
200
  if (isHookModalPathname(pathname)) {
211
- return composeRouteData(hookModalScreenData);
201
+ const screenData = hookModalScreenData;
202
+
203
+ return { screenData, pathname };
212
204
  }
213
205
 
214
206
  if (isHookPathname(pathname)) {
215
- /**
216
- * HACK
217
- *
218
- * This condition relies on hacky approach to get the current hook screen data
219
- * using navigator.screenData for some cases.
220
- * This is used when hook is in sequence.
221
- */
222
-
223
- // case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
224
- if (!currentStack) {
225
- return composeRouteData(navigator.screenData);
226
- }
227
-
228
- const isValidHookInCurrentRouteScreenData =
229
- "hookPlugin" in currentRouteScreenData &&
230
- !!currentRouteScreenData.hookPlugin?.module;
231
-
232
- let screenData;
233
-
234
- // case 2: stack has valid hook data
235
- if (isValidHookInCurrentRouteScreenData) {
236
- screenData = currentRouteScreenData;
237
- }
238
-
239
- const navigatorScreenData = navigator.screenData as NavigatorEntry;
240
-
241
- // case 3: current hookPlugin is missing weight, but navigator.screenData has weight, use navigator.screenData
242
- if (
243
- screenData.hookPlugin.identifier ===
244
- navigatorScreenData?.hookPlugin?.identifier &&
245
- !screenData.hookPlugin?.weight &&
246
- navigatorScreenData?.hookPlugin?.weight
247
- ) {
248
- screenData = navigator.screenData;
249
- }
250
-
251
- return composeRouteData(screenData);
207
+ return { screenData: screenDataContext, pathname };
252
208
  }
253
209
 
254
- // case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
255
- if (!currentStack) {
256
- return composeRouteData(navigator.screenData);
257
- }
210
+ // Cover cases where screenContext is used before navigation is initialized
211
+ const screenData = isEmpty(screenDataContext)
212
+ ? navigator.screenData
213
+ : screenDataContext;
258
214
 
259
- return composeRouteData(currentRouteScreenData);
215
+ return { screenData, pathname };
260
216
  };
261
217
 
262
218
  type Callbacks = Partial<{
@@ -5,6 +5,7 @@ import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-co
5
5
  import { useNavigation } from "../navigation/useNavigation";
6
6
 
7
7
  import { ScreenContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
8
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
8
9
 
9
10
  export function useScreenContextV2() {
10
11
  return useContext(ScreenContext);
@@ -44,9 +45,9 @@ export function useSetNavbarState() {
44
45
 
45
46
  export function useScreenContext(): NavigationScreenData {
46
47
  const navigator = useNavigation();
48
+ // Cover cases where screenContext is used before navigation is initialized
49
+ const screenData = useContext(ScreenDataContext) || navigator.data;
47
50
 
48
- const screenKey = useMemo(() => navigator?.key, [navigator]);
49
- const screenData = useMemo(() => navigator?.data, [screenKey]);
50
51
  const modalScreenData = navigator?.modalData;
51
52
 
52
53
  const isModal = useModalNavigationContext();