@applicaster/zapp-react-native-ui-components 13.0.0-rc.56 → 13.0.0-rc.57

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 = ({
@@ -2,21 +2,21 @@ import { Animated } from "react-native";
2
2
 
3
3
  import { NAV_ACTION_PUSH, NAV_ACTION_BACK } from "./Transitioner";
4
4
 
5
- type TransitionConfig = {
6
- duration: number;
7
- easing: any;
8
- from: {
9
- style: any;
10
- };
11
- to: {
12
- style: any;
13
- };
14
- };
5
+ // type TransitionConfig = {
6
+ // duration: number;
7
+ // easing: any;
8
+ // from: {
9
+ // style: any;
10
+ // };
11
+ // to: {
12
+ // style: any;
13
+ // };
14
+ // };
15
15
 
16
- type Props = {
17
- transitionConfig: TransitionConfig;
18
- contentStyle: { [string]: any };
19
- };
16
+ // type Props = {
17
+ // transitionConfig: TransitionConfig;
18
+ // contentStyle: { [string]: any };
19
+ // };
20
20
 
21
21
  /**
22
22
  * Manages animation for the Transitioner,
@@ -25,7 +25,7 @@ type Props = {
25
25
  * which must have a proper structure, see types above ^.
26
26
  */
27
27
  export class AnimationManager {
28
- constructor(props: Props) {
28
+ constructor(props) {
29
29
  this.animatedValue = new Animated.Value(0.0);
30
30
 
31
31
  this.config = props.transitionConfig(
@@ -7,17 +7,11 @@ export const withFocusableContext = (Component) => {
7
7
  { groupId, ...props }: Record<string, any>,
8
8
  ref
9
9
  ) => {
10
- return (
11
- <FocusableGroupContext.Consumer>
12
- {(groupIdContext: string) => {
13
- // eslint-disable-next-line react/display-name
14
- const propsGroupId = groupId || null;
15
- const providedGroupId = propsGroupId || groupIdContext;
10
+ const groupIdContext = React.useContext(FocusableGroupContext);
11
+ const propsGroupId = groupId || null;
12
+ const providedGroupId = propsGroupId || groupIdContext;
16
13
 
17
- return <Component {...props} groupId={providedGroupId} ref={ref} />;
18
- }}
19
- </FocusableGroupContext.Consumer>
20
- );
14
+ return <Component {...props} groupId={providedGroupId} ref={ref} />;
21
15
  };
22
16
 
23
17
  return React.forwardRef(WithFocusableContext);
@@ -13,7 +13,7 @@ type ProviderProps = {
13
13
  };
14
14
  };
15
15
 
16
- const initialHeaderOffsetContext = () => ({
16
+ const initialHeaderOffsetContext: HeaderOffsetContextType = () => ({
17
17
  headerOffset: 0,
18
18
  headersAbove: null,
19
19
  });
@@ -24,11 +24,9 @@ export const HeaderOffsetContext = React.createContext<HeaderOffsetContextType>(
24
24
 
25
25
  export function withConsumer(Component) {
26
26
  return function WithConsumer(props) {
27
- return (
28
- <HeaderOffsetContext.Consumer>
29
- {(context) => <Component getHeaderOffset={context} {...props} />}
30
- </HeaderOffsetContext.Consumer>
31
- );
27
+ const getHeaderOffset = React.useContext(HeaderOffsetContext);
28
+
29
+ return <Component getHeaderOffset={getHeaderOffset} {...props} />;
32
30
  };
33
31
  }
34
32
 
@@ -176,15 +176,8 @@ export function ScreenContextProvider({
176
176
 
177
177
  export function withScreenContext(Component: React.ComponentType<any>) {
178
178
  return function WithScreenContextWrapper(props) {
179
- return (
180
- <ScreenContext.Consumer>
181
- {useCallback(
182
- (value) => (
183
- <Component {...props} screenContext={value} />
184
- ),
185
- [Component, props]
186
- )}
187
- </ScreenContext.Consumer>
188
- );
179
+ const screenContext = React.useContext(ScreenContext);
180
+
181
+ return <Component {...props} screenContext={screenContext} />;
189
182
  };
190
183
  }
@@ -1,12 +1,10 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  /// <reference types="@applicaster/zapp-react-native-ui-components" />
3
3
  import React, { useEffect, useMemo } from "react";
4
- import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
5
4
 
6
5
  import * as R from "ramda";
7
6
  import { Platform } from "react-native";
8
7
  import Url from "url";
9
- import { ENDPOINT_TAGS } from "@applicaster/zapp-react-native-utils/types";
10
8
  import { favoritesListener } from "@applicaster/zapp-react-native-bridge/Favorites";
11
9
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
12
10
  import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
@@ -21,12 +19,7 @@ import { ZappPipesSearchContext } from "@applicaster/zapp-react-native-ui-compon
21
19
  import { useScreenContext } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
22
20
 
23
21
  import { isVerticalListOrGrid } from "./utils";
24
- import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
25
- import {
26
- findEndpointForURL,
27
- HTTP_METHODS,
28
- } from "@applicaster/zapp-pipes-v2-client";
29
- import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
22
+ import { subscribeForUrlContextKeyChanges } from "@applicaster/zapp-pipes-v2-client";
30
23
 
31
24
  type Props = {
32
25
  component: ZappUIComponent;
@@ -300,27 +293,7 @@ export function zappPipesDataConnector(
300
293
  return addListener(reloadData);
301
294
  }
302
295
  } else {
303
- const pipesEndpoints = appStore.get("pipesEndpoints");
304
-
305
- const endpointURL = findEndpointForURL(
306
- dataSourceUrl,
307
- pipesEndpoints,
308
- HTTP_METHODS.GET
309
- );
310
-
311
- const endpoint = pipesEndpoints?.[endpointURL];
312
-
313
- if (endpoint?.tags?.includes(ENDPOINT_TAGS.observe_storage)) {
314
- const subscriptions: (() => void)[] = endpoint.context_obj.map(
315
- (data: Record<string, any>) => {
316
- const { namespace, key } = getNamespaceAndKey(data.key);
317
-
318
- return localStorage.addListener({ key, namespace }, reloadData);
319
- }
320
- );
321
-
322
- return () => subscriptions.forEach((listener) => listener());
323
- }
296
+ return subscribeForUrlContextKeyChanges(dataSourceUrl, {}, reloadData);
324
297
  }
325
298
  }, [dataSourceUrl, reloadData]);
326
299
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "13.0.0-rc.56",
3
+ "version": "13.0.0-rc.57",
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",
@@ -29,15 +29,13 @@
29
29
  },
30
30
  "homepage": "https://github.com/applicaster/quickbrick#readme",
31
31
  "devDependencies": {
32
- "@types/react": "17.0.2",
33
- "@types/react-native": "0.69.6",
34
32
  "redux-mock-store": "^1.5.3"
35
33
  },
36
34
  "dependencies": {
37
- "@applicaster/applicaster-types": "13.0.0-rc.56",
38
- "@applicaster/zapp-react-native-bridge": "13.0.0-rc.56",
39
- "@applicaster/zapp-react-native-redux": "13.0.0-rc.56",
40
- "@applicaster/zapp-react-native-utils": "13.0.0-rc.56",
35
+ "@applicaster/applicaster-types": "13.0.0-rc.57",
36
+ "@applicaster/zapp-react-native-bridge": "13.0.0-rc.57",
37
+ "@applicaster/zapp-react-native-redux": "13.0.0-rc.57",
38
+ "@applicaster/zapp-react-native-utils": "13.0.0-rc.57",
41
39
  "promise": "^8.3.0",
42
40
  "react-router-native": "^5.1.2",
43
41
  "url": "^0.11.0",
@@ -46,7 +44,6 @@
46
44
  "peerDependencies": {
47
45
  "@applicaster/zapp-pipes-v2-client": "*",
48
46
  "@react-native-community/netinfo": "*",
49
- "@types/node": "*",
50
47
  "immer": "*",
51
48
  "react": "*",
52
49
  "react-native": "*",
package/tsconfig.json CHANGED
@@ -2,8 +2,7 @@
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
4
  "outDir": "./lib",
5
- "rootDir": "./src"
5
+ "rootDir": "./"
6
6
  },
7
- "exclude": ["src/**/*.test.tsx"],
8
- "include": ["src/**/*"]
7
+ "include": ["**/*"],
9
8
  }