@applicaster/zapp-react-native-ui-components 12.0.12 → 12.0.13-rc.0

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,133 @@
1
+ import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
2
+ import { StorageSingleValueProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageSingleSelectProvider";
3
+ import { PushTopicManager } from "@applicaster/zapp-react-native-bridge/PushNotifications/PushTopicManager";
4
+ import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
5
+ import React, { useEffect } from "react";
6
+ import { usePlayer } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer";
7
+ import { BehaviorSubject } from "rxjs";
8
+ import { masterCellLogger } from "../logger";
9
+
10
+ const parseContextKey = (key: string): string | null => {
11
+ if (!key?.startsWith("@{ctx/")) return null;
12
+
13
+ return key.substring("@{ctx/".length, key.length - 1);
14
+ };
15
+
16
+ const getDataSourceProvider = (
17
+ behavior: Behavior
18
+ ): BehaviorSubject<string[] | string> | null => {
19
+ if (!behavior) return null;
20
+
21
+ const selection = String(behavior.current_selection);
22
+ const contextKey = parseContextKey(selection);
23
+
24
+ if (contextKey) {
25
+ if (behavior.select_mode === "multi") {
26
+ return StorageMultiSelectProvider.getProvider(contextKey).getObservable();
27
+ }
28
+
29
+ if (behavior.select_mode === "single") {
30
+ return StorageSingleValueProvider.getProvider(contextKey).getObservable();
31
+ }
32
+ }
33
+
34
+ if (behavior.selection_source === "@{push/topics}") {
35
+ return PushTopicManager.getInstance().getEntryObservable();
36
+ }
37
+
38
+ return null;
39
+ };
40
+
41
+ export const useBehaviorUpdate = (behavior: Behavior) => {
42
+ const [lastUpdate, setLastUpdate] = React.useState<number | null>(null);
43
+ const player = usePlayer();
44
+
45
+ const triggerUpdate = () => setLastUpdate(Date.now());
46
+
47
+ useEffect(() => {
48
+ if (!behavior) return;
49
+
50
+ const dataSource = getDataSourceProvider(behavior);
51
+
52
+ if (dataSource) {
53
+ const subscription = dataSource.subscribe(triggerUpdate);
54
+
55
+ return () => subscription.unsubscribe();
56
+ }
57
+ }, [behavior]);
58
+
59
+ useEffect(() => {
60
+ if (!behavior || !player || behavior.selection_source !== "now_playing") {
61
+ return;
62
+ }
63
+
64
+ const subscription = player.getEntryObservable().subscribe(triggerUpdate);
65
+
66
+ return () => subscription.unsubscribe();
67
+ }, [behavior, player]);
68
+
69
+ return lastUpdate;
70
+ };
71
+
72
+ // We cant use async in this function (its inside render),
73
+ // so we rely on useBehaviorUpdate to update current value and trigger re-render
74
+ export const isCellSelected = (
75
+ id: string | number,
76
+ behavior?: Behavior
77
+ ): boolean => {
78
+ if (!behavior) return false;
79
+
80
+ if (behavior.selection_source === "now_playing") {
81
+ const player = playerManager.getActivePlayer();
82
+
83
+ return player?.entry?.id === id;
84
+ }
85
+
86
+ if (behavior.selection_source === "@{push/topics}") {
87
+ if (behavior.select_mode === "single") {
88
+ masterCellLogger.warning(
89
+ "Unexpected single selection mode for push topics"
90
+ );
91
+ }
92
+
93
+ const tags = PushTopicManager.getInstance().getRegisteredTags();
94
+
95
+ return tags.includes(String(id));
96
+ }
97
+
98
+ const selection = String(behavior.current_selection);
99
+ const contextKey = parseContextKey(selection);
100
+
101
+ if (contextKey) {
102
+ if (behavior.select_mode === "single") {
103
+ const selectedItem =
104
+ StorageSingleValueProvider.getProvider(contextKey)?.getValue();
105
+
106
+ return selectedItem === String(id);
107
+ }
108
+
109
+ if (behavior.select_mode === "multi") {
110
+ const selectedItems =
111
+ StorageMultiSelectProvider.getProvider(contextKey)?.getSelectedItems();
112
+
113
+ return selectedItems?.includes(String(id));
114
+ }
115
+ }
116
+
117
+ if (behavior.select_mode === "single") {
118
+ return behavior.current_selection === id;
119
+ }
120
+
121
+ if (
122
+ behavior.select_mode === "multi" &&
123
+ Array.isArray(behavior.current_selection)
124
+ ) {
125
+ const currentSelection: string[] = behavior.current_selection.map(
126
+ (item): string => String(item)
127
+ );
128
+
129
+ return currentSelection.includes(String(id));
130
+ }
131
+
132
+ return false;
133
+ };
@@ -1,16 +1,13 @@
1
- import React, { useEffect, useMemo } from "react";
1
+ import React, { useMemo } from "react";
2
2
  import * as R from "ramda";
3
3
  import validateColor from "validate-color";
4
4
  import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
5
5
  import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
6
6
 
7
7
  import { masterCellLogger } from "../logger";
8
- import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
9
- import { usePlayer } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer";
10
- import { PushTopicManager } from "@applicaster/zapp-react-native-bridge/PushNotifications/PushTopicManager";
11
- import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
12
8
  import { getCellState } from "../../Cell/utils";
13
9
  import { getColorFromData } from "@applicaster/zapp-react-native-utils/cellUtils";
10
+ import { isCellSelected, useBehaviorUpdate } from "./behaviorProvider";
14
11
 
15
12
  const hasElementSpecificViewType = (viewType) => (element) => {
16
13
  if (R.isNil(element)) {
@@ -194,130 +191,7 @@ export const getFocusedButtonId = (focusable) => {
194
191
  };
195
192
 
196
193
  export const isSelected = (id: string | number, behavior?: Behavior) => {
197
- if (!behavior) {
198
- return false;
199
- }
200
-
201
- if (behavior?.selection_source === "now_playing") {
202
- const player = playerManager.getActivePlayer();
203
-
204
- if (player?.entry?.id === id) {
205
- return true;
206
- }
207
- }
208
-
209
- if (behavior?.select_mode === "single") {
210
- return behavior.current_selection === id;
211
- }
212
-
213
- if (behavior?.select_mode === "multi") {
214
- // TODO: Use generic resolver source
215
-
216
- if (behavior.selection_source === "@{push/topics}") {
217
- const tags = PushTopicManager.getInstance().getRegisteredTags();
218
-
219
- return tags.includes(String(id));
220
- }
221
-
222
- if (Array.isArray(behavior.current_selection)) {
223
- return behavior.current_selection.includes(id);
224
- }
225
-
226
- const currentSelection = String(behavior.current_selection);
227
-
228
- if (currentSelection?.startsWith("@{ctx/")) {
229
- const keyWithoutCtx = currentSelection.substring(
230
- "@{ctx/".length,
231
- currentSelection.length - 1
232
- );
233
-
234
- const selectedItems =
235
- StorageMultiSelectProvider.getProvider(
236
- keyWithoutCtx
237
- )?.getSelectedItems();
238
-
239
- return selectedItems?.includes(String(id));
240
- }
241
- }
242
-
243
- return false;
244
- };
245
-
246
- export const useBehaviorUpdate = (behavior: Behavior) => {
247
- const [lastUpdate, setLastUpdate] = React.useState(null);
248
-
249
- const player = usePlayer();
250
-
251
- const triggerUpdate = () => {
252
- setLastUpdate(Date.now());
253
- };
254
-
255
- // TODO: Create generic RX to state update
256
- useEffect(() => {
257
- // TODO: Use generic resolver source
258
- if (!behavior) {
259
- return;
260
- }
261
-
262
- const currentSelection = String(behavior.current_selection);
263
-
264
- if (currentSelection?.startsWith("@{ctx/")) {
265
- const keyWithoutCtx = currentSelection.substring(
266
- "@{ctx/".length,
267
- currentSelection.length - 1
268
- );
269
-
270
- if (keyWithoutCtx) {
271
- const subscription = StorageMultiSelectProvider.getProvider(
272
- keyWithoutCtx
273
- )
274
- .getObservable()
275
- .subscribe(() => {
276
- triggerUpdate();
277
- });
278
-
279
- return () => {
280
- subscription.unsubscribe();
281
- };
282
- }
283
- }
284
- }, [behavior]);
285
-
286
- useEffect(() => {
287
- if (!behavior) {
288
- return;
289
- }
290
-
291
- if (behavior?.selection_source === "@{push/topics}") {
292
- const subscription = PushTopicManager.getInstance()
293
- .getEntryObservable()
294
- .subscribe(() => {
295
- triggerUpdate();
296
- });
297
-
298
- return () => {
299
- subscription.unsubscribe();
300
- };
301
- }
302
- }, [behavior]);
303
-
304
- useEffect(() => {
305
- if (!behavior) {
306
- return;
307
- }
308
-
309
- if (behavior?.selection_source === "now_playing" && player) {
310
- const subscription = player.getEntryObservable().subscribe(() => {
311
- triggerUpdate();
312
- });
313
-
314
- return () => {
315
- subscription.unsubscribe();
316
- };
317
- }
318
- }, [behavior, player]);
319
-
320
- return lastUpdate;
194
+ return isCellSelected(id, behavior);
321
195
  };
322
196
 
323
197
  export const useCellState = ({
@@ -34,6 +34,7 @@ type Props = {
34
34
  getStaticComponentFeed: any;
35
35
  pullToRefreshPipesV1RefreshingStateUpdater: () => boolean;
36
36
  refreshingPipesV1?: boolean;
37
+ stickyHeaderIndices?: number[];
37
38
  };
38
39
 
39
40
  const styles = StyleSheet.create({
@@ -61,6 +62,7 @@ function ComponentsMapComponent(props: Props) {
61
62
  // TODO: Remove when pipes v1 is deprecated.
62
63
  pullToRefreshPipesV1RefreshingStateUpdater,
63
64
  refreshingPipesV1,
65
+ stickyHeaderIndices,
64
66
  } = props;
65
67
 
66
68
  const flatListRef = React.useRef<FlatList | null>(null);
@@ -303,6 +305,7 @@ function ComponentsMapComponent(props: Props) {
303
305
  overScrollMode={Platform.OS === "android" ? "never" : "auto"}
304
306
  scrollIndicatorInsets={scrollIndicatorInsets}
305
307
  extraData={feed}
308
+ stickyHeaderIndices={stickyHeaderIndices}
306
309
  onLayout={handleOnLayout}
307
310
  removeClippedSubviews
308
311
  initialNumToRender={3}
@@ -16,6 +16,13 @@ jest.mock("react-native-safe-area-context", () => ({
16
16
  useSafeAreaInsets: () => ({ top: 50 }),
17
17
  }));
18
18
 
19
+ jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
20
+ appStore: {
21
+ get: jest.fn((prop) => mockStore[prop]),
22
+ getState: jest.fn(),
23
+ },
24
+ }));
25
+
19
26
  jest.mock("react-native", () => {
20
27
  const RN = jest.genMockFromModule("react-native");
21
28
  const actualRN = jest.requireActual("react-native");
@@ -4,7 +4,6 @@ import React, { useEffect, useMemo } from "react";
4
4
  import * as R from "ramda";
5
5
  import { Platform } from "react-native";
6
6
  import Url from "url";
7
-
8
7
  import { favoritesListener } from "@applicaster/zapp-react-native-bridge/Favorites";
9
8
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
10
9
  import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
@@ -19,6 +18,7 @@ import { ZappPipesSearchContext } from "@applicaster/zapp-react-native-ui-compon
19
18
  import { useScreenContext } from "@applicaster/zapp-react-native-utils/reactHooks/screen";
20
19
 
21
20
  import { isVerticalListOrGrid } from "./utils";
21
+ import { subscribeForUrlContextKeyChanges } from "@applicaster/zapp-pipes-v2-client";
22
22
 
23
23
  type Props = {
24
24
  component: ZappUIComponent;
@@ -291,6 +291,8 @@ export function zappPipesDataConnector(
291
291
  if (addListener) {
292
292
  return addListener(reloadData);
293
293
  }
294
+ } else {
295
+ return subscribeForUrlContextKeyChanges(dataSourceUrl, {}, reloadData);
294
296
  }
295
297
  }, [dataSourceUrl, reloadData]);
296
298
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "12.0.12",
3
+ "version": "12.0.13-rc.0",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -34,10 +34,10 @@
34
34
  "redux-mock-store": "^1.5.3"
35
35
  },
36
36
  "dependencies": {
37
- "@applicaster/applicaster-types": "12.0.12",
38
- "@applicaster/zapp-react-native-bridge": "12.0.12",
39
- "@applicaster/zapp-react-native-redux": "12.0.12",
40
- "@applicaster/zapp-react-native-utils": "12.0.12",
37
+ "@applicaster/applicaster-types": "12.0.13-rc.0",
38
+ "@applicaster/zapp-react-native-bridge": "12.0.13-rc.0",
39
+ "@applicaster/zapp-react-native-redux": "12.0.13-rc.0",
40
+ "@applicaster/zapp-react-native-utils": "12.0.13-rc.0",
41
41
  "promise": "^8.3.0",
42
42
  "react-router-native": "^5.1.2",
43
43
  "url": "^0.11.0",