@applicaster/quick-brick-core 15.1.4-rc.0 → 15.1.5-alpha.7597480209

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.
@@ -20,10 +20,6 @@ const warnUndefinedContext = (context) =>
20
20
  data: { context },
21
21
  });
22
22
 
23
- type Subscription = {
24
- [x: string]: () => any;
25
- };
26
-
27
23
  const getModuleContext = R.path(["module", "context"]);
28
24
 
29
25
  const getContexts = R.compose(
@@ -63,24 +59,40 @@ const useSubscribeToActionProviders = () => {
63
59
  export const useRiverInitialState = () => {
64
60
  const key = "getRiverInitialState";
65
61
  const actionProvidersSubscriptions = useSubscribeToActionProviders();
62
+ // Capture river-init promises once. Re-calling getRiverInitialState() on every
63
+ // context re-render causes thrash and can drop already-completed observables.
64
+ // Plugins should return Promise.resolve() when already initialized (not undefined).
65
+ const capturedPromisesRef = React.useRef<Promise<unknown>[] | null>(null);
66
+
67
+ if (
68
+ capturedPromisesRef.current === null &&
69
+ actionProvidersSubscriptions.length > 0
70
+ ) {
71
+ const providersWithMethod = actionProvidersSubscriptions.filter(
72
+ (item) => item?.[key]
73
+ );
74
+
75
+ const promises = providersWithMethod
76
+ .map((item) => item[key]())
77
+ .filter(Boolean) as Promise<unknown>[];
78
+
79
+ // Lock when every river-init provider returned a promise, or none expose it.
80
+ // Retry while a provider still returns undefined (getInitialState not started).
81
+ if (
82
+ providersWithMethod.length === 0 ||
83
+ promises.length === providersWithMethod.length
84
+ ) {
85
+ capturedPromisesRef.current = promises;
86
+ }
87
+ }
66
88
 
67
- const subscriptions = React.useMemo(() => {
68
- if (!actionProvidersSubscriptions.length) return undefined;
69
-
70
- return actionProvidersSubscriptions.reduce((acc, item) => {
71
- const riverInitialStatePromise = item[key]?.();
72
-
73
- if (riverInitialStatePromise) {
74
- acc.push(riverInitialStatePromise);
75
- }
76
-
77
- return acc;
78
- }, [] as Subscription[]);
79
- }, [actionProvidersSubscriptions]);
89
+ if (!actionProvidersSubscriptions.length) {
90
+ return undefined;
91
+ }
80
92
 
81
- if (!actionProvidersSubscriptions.length) return undefined;
82
-
83
- return subscriptions;
93
+ return capturedPromisesRef.current === null
94
+ ? undefined
95
+ : capturedPromisesRef.current;
84
96
  };
85
97
 
86
98
  const getActionInitialStateSetters = (key) => {
@@ -0,0 +1,88 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+ import { State } from "react-native-gesture-handler";
5
+ import { DraggableBottomSheet } from "../index";
6
+
7
+ // Render the gesture handlers as passthrough Views so we can mount the sheet
8
+ // and drive its release handler directly. State stays real (we need ACTIVE).
9
+ jest.mock("react-native-gesture-handler", () => {
10
+ const RN = require("react-native");
11
+ const ReactActual = require("react");
12
+ const actual = jest.requireActual("react-native-gesture-handler");
13
+
14
+ const Passthrough = ReactActual.forwardRef(({ children }: any, _ref: any) => (
15
+ <RN.View>{children}</RN.View>
16
+ ));
17
+
18
+ return {
19
+ __esModule: true,
20
+ ...actual,
21
+ PanGestureHandler: Passthrough,
22
+ TapGestureHandler: Passthrough,
23
+ };
24
+ });
25
+
26
+ // height 800, sheetHeight 400, no header:
27
+ // SnapPoints.top = 800 - 400 = 400 (lastSnap after mount)
28
+ // SnapPoints.threshold = max(800 - 400 / 2, 100) = 600
29
+ // Release dismisses when lastSnap + translationY + 0.05 * velocityY > 600,
30
+ // i.e. once the drag+toss pushes past 200px.
31
+ const mountSheet = () => {
32
+ const dismiss = jest.fn();
33
+ const ref = React.createRef<DraggableBottomSheet>();
34
+
35
+ render(
36
+ <DraggableBottomSheet
37
+ ref={ref}
38
+ header={() => null}
39
+ dismiss={dismiss}
40
+ visible={true}
41
+ sheetHeight={400}
42
+ width={320}
43
+ height={800}
44
+ hasHeader={false}
45
+ maxWidth={320}
46
+ >
47
+ <View testID="child" />
48
+ </DraggableBottomSheet>
49
+ );
50
+
51
+ return { instance: ref.current as DraggableBottomSheet, dismiss };
52
+ };
53
+
54
+ const release = (
55
+ instance: DraggableBottomSheet,
56
+ translationY: number,
57
+ velocityY = 0
58
+ ) =>
59
+ instance._onHandlerStateChange({
60
+ nativeEvent: { oldState: State.ACTIVE, translationY, velocityY },
61
+ });
62
+
63
+ describe("DraggableBottomSheet release", () => {
64
+ // Mounting an open sheet schedules a deferred animateIn via setTimeout. Keep
65
+ // it on fake timers so it never fires into a torn-down Jest environment.
66
+ beforeEach(() => jest.useFakeTimers());
67
+
68
+ afterEach(() => {
69
+ jest.clearAllTimers();
70
+ jest.useRealTimers();
71
+ });
72
+
73
+ it("dismisses when the release lands past the threshold", () => {
74
+ const { instance, dismiss } = mountSheet();
75
+
76
+ release(instance, 300);
77
+
78
+ expect(dismiss).toHaveBeenCalledTimes(1);
79
+ });
80
+
81
+ it("springs back (does not dismiss) when the release is below the threshold", () => {
82
+ const { instance, dismiss } = mountSheet();
83
+
84
+ release(instance, 50);
85
+
86
+ expect(dismiss).not.toHaveBeenCalled();
87
+ });
88
+ });
@@ -1,15 +1,24 @@
1
- import React, { Component, ReactChild, ReactElement } from "react";
1
+ import React, { Component, ReactElement } from "react";
2
2
  import { Animated, StyleSheet, View, Easing } from "react-native";
3
3
  import {
4
4
  PanGestureHandler,
5
- NativeViewGestureHandler,
6
5
  State,
7
6
  TapGestureHandler,
8
7
  } from "react-native-gesture-handler";
9
8
 
10
9
  import { SnapPoints } from "./SnapPoints";
11
-
12
- const USE_NATIVE_DRIVER = true;
10
+ import {
11
+ BottomSheetContext,
12
+ BottomSheetContextValue,
13
+ } from "@applicaster/zapp-react-native-utils/bottomSheet";
14
+
15
+ // Must stay false: the sheet drives _dragY from old-API PanGestureHandler
16
+ // onGestureEvent props via RN Animated.event. This RNGH version cannot attach
17
+ // a native (useNativeDriver: true) Animated.event to those handlers — it leaks
18
+ // the AnimatedEvent object into the JS event path and throws "Expected
19
+ // onGestureHandlerEvent listener to be a function". Native-threaded dragging
20
+ // needs the full reanimated + Gesture-API migration (tracked separately).
21
+ const USE_NATIVE_DRIVER = false;
13
22
  const HEADER_HEIGHT = 44;
14
23
 
15
24
  const ANIMATION_DURATION = 400;
@@ -24,7 +33,7 @@ const styles = StyleSheet.create({
24
33
  });
25
34
 
26
35
  type Props = {
27
- children: ReactChild;
36
+ children: ReactElement;
28
37
  header: (boolean) => ReactElement;
29
38
  dismiss: () => void;
30
39
  visible: boolean;
@@ -49,35 +58,24 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
49
58
  _isMounted = false;
50
59
  _animatedIn = false;
51
60
  _animating = false;
52
- _lastScrollYValue: number;
53
- _lastScrollY: Animated.Value;
54
61
  _dragY: Animated.Value;
55
- _reverseLastScrollY: Animated.AnimatedInterpolation<number>;
56
62
  _translateYOffset: Animated.Value;
57
63
  _translateY: Animated.AnimatedInterpolation<number>;
58
64
  _snapPoints: SnapPoints;
59
65
  _prevContentHeight = 0;
66
+ _bottomSheetContextValue: BottomSheetContextValue;
60
67
 
61
68
  _callWhenMounted: () => void | null;
62
69
 
63
- _onRegisterLastScroll: (...args: any[]) => void;
70
+ // One shared JS Animated.event feeds _dragY for every drag handler (top
71
+ // handle, header drag-area, body). Safe because useNativeDriver is false — the
72
+ // event is a plain JS listener that setValue's _dragY for whichever handler
73
+ // is active, and only one gesture is ever active at a time.
64
74
  _onGestureEvent: (...args: any[]) => void;
65
75
 
66
76
  constructor(props) {
67
77
  super(props);
68
78
 
69
- this._lastScrollYValue = 0;
70
- this._lastScrollY = new Animated.Value(0);
71
-
72
- this._onRegisterLastScroll = Animated.event(
73
- [{ nativeEvent: { contentOffset: { y: this._lastScrollY } } }],
74
- { useNativeDriver: USE_NATIVE_DRIVER }
75
- );
76
-
77
- this._lastScrollY.addListener(({ value }) => {
78
- this._lastScrollYValue = value;
79
- });
80
-
81
79
  this._dragY = new Animated.Value(0);
82
80
 
83
81
  this._onGestureEvent = Animated.event(
@@ -85,10 +83,11 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
85
83
  { useNativeDriver: USE_NATIVE_DRIVER }
86
84
  );
87
85
 
88
- this._reverseLastScrollY = Animated.multiply(
89
- new Animated.Value(-1),
90
- this._lastScrollY
91
- );
86
+ this._bottomSheetContextValue = {
87
+ masterDrawerRef: this.masterdrawer,
88
+ onDragGestureEvent: this._onGestureEvent,
89
+ onDragStateChange: this._onHeaderHandlerStateChange,
90
+ };
92
91
 
93
92
  const initialSnapPoints = new SnapPoints(props.height, props.sheetHeight);
94
93
 
@@ -181,7 +180,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
181
180
 
182
181
  this._translateY = Animated.add(
183
182
  this._translateYOffset,
184
- Animated.add(this._dragY, this._reverseLastScrollY)
183
+ this._dragY
185
184
  ).interpolate({
186
185
  inputRange: [this._snapPoints.top, this._snapPoints.bottom],
187
186
  outputRange: [this._snapPoints.top, this._snapPoints.bottom],
@@ -226,10 +225,6 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
226
225
  return;
227
226
  }
228
227
 
229
- if (nativeEvent.oldState === State.BEGAN) {
230
- this._lastScrollY.setValue(0);
231
- }
232
-
233
228
  this._onHandlerStateChange({ nativeEvent });
234
229
  };
235
230
 
@@ -240,8 +235,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
240
235
 
241
236
  if (nativeEvent.oldState === State.ACTIVE) {
242
237
  const { velocityY } = nativeEvent;
243
- let { translationY } = nativeEvent;
244
- translationY -= this._lastScrollYValue;
238
+ const { translationY } = nativeEvent;
245
239
  const dragToss = 0.05;
246
240
 
247
241
  const endOffsetY =
@@ -300,7 +294,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
300
294
  >
301
295
  <PanGestureHandler
302
296
  ref={this.drawerheader}
303
- simultaneousHandlers={[this.scroll, this.masterdrawer]}
297
+ simultaneousHandlers={[this.masterdrawer]}
304
298
  shouldCancelWhenOutside={false}
305
299
  onGestureEvent={this._onGestureEvent}
306
300
  onHandlerStateChange={this._onHeaderHandlerStateChange}
@@ -309,31 +303,11 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
309
303
  {this.props?.header(this.state.dragging)}
310
304
  </Animated.View>
311
305
  </PanGestureHandler>
312
- <PanGestureHandler
313
- ref={this.drawer}
314
- simultaneousHandlers={[this.scroll, this.masterdrawer]}
315
- shouldCancelWhenOutside={false}
316
- onGestureEvent={this._onGestureEvent}
317
- onHandlerStateChange={this._onHandlerStateChange}
318
- >
306
+ <BottomSheetContext.Provider value={this._bottomSheetContextValue}>
319
307
  <Animated.View style={styles.container}>
320
- <NativeViewGestureHandler
321
- ref={this.scroll}
322
- waitFor={this.masterdrawer}
323
- simultaneousHandlers={this.drawer}
324
- >
325
- <Animated.ScrollView
326
- bounces={false}
327
- onScrollBeginDrag={this._onRegisterLastScroll}
328
- scrollEventThrottle={1}
329
- scrollEnabled={false}
330
- showsVerticalScrollIndicator={false}
331
- >
332
- {this.props.children}
333
- </Animated.ScrollView>
334
- </NativeViewGestureHandler>
308
+ {this.props.children}
335
309
  </Animated.View>
336
- </PanGestureHandler>
310
+ </BottomSheetContext.Provider>
337
311
  </Animated.View>
338
312
  </View>
339
313
  </TapGestureHandler>
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Boot-time dedupe for remote JSON GETs.
3
+ * Shared across packages via globalThis so layout-manager + core
4
+ * don't double-fetch the same URL during startup.
5
+ */
6
+ declare global {
7
+ // eslint-disable-next-line no-var
8
+ var __QB_REMOTE_JSON_INFLIGHT__: Map<string, Promise<unknown>> | undefined;
9
+ }
10
+
11
+ export function cachedRemoteJson<T>(
12
+ url: string,
13
+ fetcher: () => Promise<T>
14
+ ): Promise<T> {
15
+ if (!url) {
16
+ return fetcher();
17
+ }
18
+
19
+ if (!globalThis.__QB_REMOTE_JSON_INFLIGHT__) {
20
+ globalThis.__QB_REMOTE_JSON_INFLIGHT__ = new Map();
21
+ }
22
+
23
+ const cache = globalThis.__QB_REMOTE_JSON_INFLIGHT__;
24
+
25
+ if (!cache.has(url)) {
26
+ cache.set(
27
+ url,
28
+ fetcher().catch((error) => {
29
+ cache.delete(url);
30
+
31
+ throw error;
32
+ })
33
+ );
34
+ }
35
+
36
+ return cache.get(url) as Promise<T>;
37
+ }
@@ -1,15 +1,14 @@
1
1
  import * as R from "ramda";
2
2
  import { loadAppContextData } from "@applicaster/zapp-react-native-redux";
3
3
 
4
- import { URL_KEYS } from "../consts";
5
4
  import {
6
5
  fetchPluginConfiguration,
7
- getPromiseForKey,
8
- prepareRuntimeConfigurationUrls,
6
+ fetchAllRemoteConfigurations,
9
7
  } from "../helpers";
10
8
  import { isTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
11
9
  import { Dimensions } from "react-native";
12
10
  import { cacheAssets } from "../../AssetCache";
11
+ import { logger } from "@applicaster/zapp-react-native-utils/logger";
13
12
 
14
13
  const buildContextData = (remoteData) => {
15
14
  const { width, height } = Dimensions.get("window");
@@ -33,6 +32,18 @@ export async function getLegacyRemoteContextData(
33
32
  runtimeConfigurationUrls,
34
33
  plugins
35
34
  ) {
35
+ const t0 = performance.now();
36
+
37
+ const mark = (label: string) => {
38
+ logger.log({
39
+ message: `[PERF][remote] ${label} +${Math.round(
40
+ performance.now() - t0
41
+ )}ms`,
42
+ });
43
+ };
44
+
45
+ mark("start");
46
+
36
47
  const layoutManagerPlugin = R.find(
37
48
  R.pathSatisfies(R.is(Function), ["module", "selectLayout"])
38
49
  )(plugins);
@@ -50,25 +61,16 @@ export async function getLegacyRemoteContextData(
50
61
  isTablet: isTabletDevice,
51
62
  });
52
63
 
53
- const { preparedRuntimeConfigurationUrls, layoutData = [] } =
54
- await prepareRuntimeConfigurationUrls(
55
- configurationUrls || runtimeConfigurationUrls,
56
- isTabletDevice
57
- );
64
+ mark("selectLayout done");
58
65
 
59
- const promises = R.compose(
60
- R.map(getPromiseForKey(preparedRuntimeConfigurationUrls)),
61
- R.reject(R.isNil),
62
- R.keys,
63
- R.pick(URL_KEYS)
64
- )(preparedRuntimeConfigurationUrls);
66
+ const remoteDataRaw = await fetchAllRemoteConfigurations(
67
+ configurationUrls || runtimeConfigurationUrls,
68
+ isTabletDevice
69
+ );
65
70
 
66
- const resolvedPromises = await Promise.all(promises);
71
+ mark("fetchAllRemoteConfigurations done");
67
72
 
68
- const remoteData = R.compose(
69
- buildContextData,
70
- R.mergeAll
71
- )([...layoutData, ...resolvedPromises]);
73
+ const remoteData = buildContextData(remoteDataRaw);
72
74
 
73
75
  const useTabletLayout =
74
76
  isTabletDevice &&
@@ -83,6 +85,8 @@ export async function getLegacyRemoteContextData(
83
85
  : remoteData.cellStyles,
84
86
  });
85
87
 
88
+ mark("cacheAssets done");
89
+
86
90
  const { pluginConfigurations } = cachedRemoteData;
87
91
 
88
92
  const updatedPlugins = R.map(
@@ -105,4 +109,6 @@ export async function getLegacyRemoteContextData(
105
109
  ...appProperties,
106
110
  plugins: updatedPlugins,
107
111
  });
112
+
113
+ mark("loadAppContextData done");
108
114
  }
@@ -20,6 +20,18 @@ export async function getNativeRemoteContextData(
20
20
  runtimeConfigurationUrls,
21
21
  plugins
22
22
  ) {
23
+ const t0 = performance.now();
24
+
25
+ const mark = (label: string) => {
26
+ logger.log({
27
+ message: `[PERF][remote-native] ${label} +${Math.round(
28
+ performance.now() - t0
29
+ )}ms`,
30
+ });
31
+ };
32
+
33
+ mark("start");
34
+
23
35
  const { width, height } = Dimensions.get("window");
24
36
 
25
37
  const isTabletDevice = isTablet(
@@ -33,6 +45,8 @@ export async function getNativeRemoteContextData(
33
45
  "pipesEndpoints",
34
46
  ]);
35
47
 
48
+ mark("generalConfiguration done");
49
+
36
50
  loadAppContextData(dispatch, R.mergeAll([...generalConfiguration]));
37
51
 
38
52
  try {
@@ -60,7 +74,10 @@ export async function getNativeRemoteContextData(
60
74
  });
61
75
  }
62
76
 
77
+ mark("selectLayout done");
78
+
63
79
  const layout = await getPromiseForType("layout");
80
+ mark("layout done");
64
81
 
65
82
  const layoutLoadingErrorMessage = "Failed to load layout data";
66
83
 
@@ -79,6 +96,7 @@ export async function getNativeRemoteContextData(
79
96
  dispatch(AppData.actions.merge({ layoutVersion: apiVersion || "v1" }));
80
97
 
81
98
  const resolvedPromises = await mapPromises(getPromiseForType, ["cellStyles"]);
99
+ mark("cellStyles done");
82
100
 
83
101
  let optionalResolvedPromise;
84
102
 
@@ -102,6 +120,8 @@ export async function getNativeRemoteContextData(
102
120
  cellStyles: remoteData.cellStyles,
103
121
  });
104
122
 
123
+ mark("cacheAssets done");
124
+
105
125
  const { pluginConfigurations } = cachedRemoteData;
106
126
 
107
127
  const updatedPlugins = R.map(
@@ -126,4 +146,6 @@ export async function getNativeRemoteContextData(
126
146
  ...appProperties,
127
147
  plugins: updatedPlugins,
128
148
  });
149
+
150
+ mark("loadAppContextData done");
129
151
  }
@@ -2,8 +2,9 @@ import axios from "axios";
2
2
  import camelize from "camelize";
3
3
  import * as R from "ramda";
4
4
  import { NativeModules } from "react-native";
5
- import { URL_KEY_SUFFIX } from "./consts";
5
+ import { URL_KEY_SUFFIX, URL_KEYS } from "./consts";
6
6
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
7
+ import { cachedRemoteJson } from "./cachedRemoteJson";
7
8
 
8
9
  const { AppLoaderBridge } = NativeModules;
9
10
 
@@ -27,25 +28,127 @@ export const urlKeyToContext = R.compose(
27
28
  R.replace(URL_KEY_SUFFIX, "")
28
29
  );
29
30
 
30
- export function getPromiseForKey(runtimeConfigurationUrls) {
31
- return async function (urlKey) {
32
- const context = urlKeyToContext(urlKey);
33
- const url = R.prop(urlKey, runtimeConfigurationUrls);
31
+ function stripOppositePlatformUrls(runtimeConfigurationUrls, isTablet) {
32
+ const preparedRuntimeConfigurationUrls = { ...runtimeConfigurationUrls };
33
+
34
+ if (isTablet) {
35
+ if (preparedRuntimeConfigurationUrls[REMOTE_CONFIG_KEYS.TABLET.LAYOUT]) {
36
+ delete preparedRuntimeConfigurationUrls[REMOTE_CONFIG_KEYS.MOBILE.LAYOUT];
37
+ }
38
+
39
+ if (
40
+ preparedRuntimeConfigurationUrls[REMOTE_CONFIG_KEYS.TABLET.CELL_STYLES]
41
+ ) {
42
+ delete preparedRuntimeConfigurationUrls[
43
+ REMOTE_CONFIG_KEYS.MOBILE.CELL_STYLES
44
+ ];
45
+ }
46
+ } else {
47
+ delete preparedRuntimeConfigurationUrls[REMOTE_CONFIG_KEYS.TABLET.LAYOUT];
34
48
 
35
- try {
49
+ delete preparedRuntimeConfigurationUrls[
50
+ REMOTE_CONFIG_KEYS.TABLET.CELL_STYLES
51
+ ];
52
+ }
53
+
54
+ return preparedRuntimeConfigurationUrls;
55
+ }
56
+
57
+ async function fetchJsonByUrlKey(runtimeConfigurationUrls, urlKey) {
58
+ const context = urlKeyToContext(urlKey);
59
+ const url = R.prop(urlKey, runtimeConfigurationUrls);
60
+
61
+ try {
62
+ const data = await cachedRemoteJson(url, async () => {
36
63
  const response = await axios.get(url);
37
64
 
38
- const { data } = response;
65
+ return response.data;
66
+ });
39
67
 
40
- return {
41
- [context]: data,
42
- };
43
- } catch (e) {
44
- throw new Error("cannot retrieve configuration data for " + urlKey);
45
- }
68
+ return {
69
+ [context]: data,
70
+ };
71
+ } catch (e) {
72
+ throw new Error("cannot retrieve configuration data for " + urlKey);
73
+ }
74
+ }
75
+
76
+ export function getPromiseForKey(runtimeConfigurationUrls) {
77
+ return async function (urlKey) {
78
+ return fetchJsonByUrlKey(runtimeConfigurationUrls, urlKey);
46
79
  };
47
80
  }
48
81
 
82
+ /**
83
+ * Fetches layout + remaining remote JSON in parallel.
84
+ * If cell_styles URL is out of sync with layout.id, refetches cells only.
85
+ */
86
+ export async function fetchAllRemoteConfigurations(
87
+ runtimeConfigurationUrls,
88
+ isTablet
89
+ ) {
90
+ const layoutUrlKey = isTablet
91
+ ? REMOTE_CONFIG_KEYS.TABLET.LAYOUT
92
+ : REMOTE_CONFIG_KEYS.MOBILE.LAYOUT;
93
+
94
+ const cellStylesUrlKey = isTablet
95
+ ? REMOTE_CONFIG_KEYS.TABLET.CELL_STYLES
96
+ : REMOTE_CONFIG_KEYS.MOBILE.CELL_STYLES;
97
+
98
+ const layoutUrl = R.prop(layoutUrlKey, runtimeConfigurationUrls);
99
+ const cellStylesUrl = R.prop(cellStylesUrlKey, runtimeConfigurationUrls);
100
+ const layoutContext = urlKeyToContext(layoutUrlKey);
101
+ const cellStylesContext = urlKeyToContext(cellStylesUrlKey);
102
+
103
+ const preparedRuntimeConfigurationUrls = stripOppositePlatformUrls(
104
+ runtimeConfigurationUrls,
105
+ isTablet
106
+ );
107
+
108
+ const keys = R.compose(
109
+ R.reject(R.isNil),
110
+ R.keys,
111
+ R.pick(URL_KEYS)
112
+ )(preparedRuntimeConfigurationUrls);
113
+
114
+ if (!layoutUrl) {
115
+ const resolvedPromises = await Promise.all(
116
+ keys.map(getPromiseForKey(preparedRuntimeConfigurationUrls))
117
+ );
118
+
119
+ return R.mergeAll(resolvedPromises);
120
+ }
121
+
122
+ const resolvedPromises = await Promise.all(
123
+ keys.map(getPromiseForKey(preparedRuntimeConfigurationUrls))
124
+ );
125
+
126
+ const remoteData = R.mergeAll(resolvedPromises);
127
+ const layout = remoteData[layoutContext];
128
+ const layoutId = layout?.id;
129
+
130
+ if (cellStylesUrl && layoutId && !cellStylesUrl.includes(layoutId)) {
131
+ const splitedUrl = cellStylesUrl.split("/");
132
+ const oldLayoutId = splitedUrl[splitedUrl.length - 2];
133
+ const correctedUrl = cellStylesUrl.replace(oldLayoutId, layoutId);
134
+
135
+ await sessionStorage.setItem("rivers_configuration_id", layoutId);
136
+
137
+ const cellStyles = await cachedRemoteJson(correctedUrl, async () => {
138
+ const response = await axios.get(correctedUrl);
139
+
140
+ return response.data;
141
+ });
142
+
143
+ return {
144
+ ...remoteData,
145
+ [cellStylesContext]: cellStyles,
146
+ };
147
+ }
148
+
149
+ return remoteData;
150
+ }
151
+
49
152
  export async function prepareRuntimeConfigurationUrls(
50
153
  runtimeConfigurationUrls,
51
154
  isTablet
@@ -64,31 +167,21 @@ export async function prepareRuntimeConfigurationUrls(
64
167
  const context = urlKeyToContext(layoutUrlKey);
65
168
 
66
169
  try {
67
- const response = await axios.get(layoutUrl);
68
- const { data } = response;
69
- const layoutData = [{ [context]: data }];
70
- const { id: layoutId } = data;
170
+ const data = await cachedRemoteJson(layoutUrl, async () => {
171
+ const response = await axios.get(layoutUrl);
71
172
 
72
- const preparedRuntimeConfigurationUrls = { ...runtimeConfigurationUrls };
73
- delete preparedRuntimeConfigurationUrls[layoutUrlKey];
173
+ return response.data;
174
+ });
74
175
 
75
- if (isTablet) {
76
- preparedRuntimeConfigurationUrls[REMOTE_CONFIG_KEYS.TABLET.LAYOUT] &&
77
- delete preparedRuntimeConfigurationUrls[
78
- REMOTE_CONFIG_KEYS.MOBILE.LAYOUT
79
- ];
176
+ const layoutData = [{ [context]: data }];
177
+ const { id: layoutId } = data;
80
178
 
81
- preparedRuntimeConfigurationUrls[REMOTE_CONFIG_KEYS.TABLET.CELL_STYLES] &&
82
- delete preparedRuntimeConfigurationUrls[
83
- REMOTE_CONFIG_KEYS.MOBILE.CELL_STYLES
84
- ];
85
- } else {
86
- delete preparedRuntimeConfigurationUrls[REMOTE_CONFIG_KEYS.TABLET.LAYOUT];
179
+ const preparedRuntimeConfigurationUrls = stripOppositePlatformUrls(
180
+ runtimeConfigurationUrls,
181
+ isTablet
182
+ );
87
183
 
88
- delete preparedRuntimeConfigurationUrls[
89
- REMOTE_CONFIG_KEYS.TABLET.CELL_STYLES
90
- ];
91
- }
184
+ delete preparedRuntimeConfigurationUrls[layoutUrlKey];
92
185
 
93
186
  if (cellStylesUrl && !cellStylesUrl.includes(layoutId)) {
94
187
  const splitedUrl = cellStylesUrl.split("/");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-core",
3
- "version": "15.1.4-rc.0",
3
+ "version": "15.1.5-alpha.7597480209",
4
4
  "description": "Core package for Applicaster's Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,13 +28,13 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "15.1.4-rc.0",
32
- "@applicaster/quick-brick-core-plugins": "15.1.4-rc.0",
33
- "@applicaster/zapp-pipes-v2-client": "15.1.4-rc.0",
34
- "@applicaster/zapp-react-native-bridge": "15.1.4-rc.0",
35
- "@applicaster/zapp-react-native-redux": "15.1.4-rc.0",
36
- "@applicaster/zapp-react-native-ui-components": "15.1.4-rc.0",
37
- "@applicaster/zapp-react-native-utils": "15.1.4-rc.0",
31
+ "@applicaster/applicaster-types": "15.1.5-alpha.7597480209",
32
+ "@applicaster/quick-brick-core-plugins": "15.1.5-alpha.7597480209",
33
+ "@applicaster/zapp-pipes-v2-client": "15.1.5-alpha.7597480209",
34
+ "@applicaster/zapp-react-native-bridge": "15.1.5-alpha.7597480209",
35
+ "@applicaster/zapp-react-native-redux": "15.1.5-alpha.7597480209",
36
+ "@applicaster/zapp-react-native-ui-components": "15.1.5-alpha.7597480209",
37
+ "@applicaster/zapp-react-native-utils": "15.1.5-alpha.7597480209",
38
38
  "atob": "^2.1.2",
39
39
  "axios": "^0.28.0",
40
40
  "btoa": "^1.2.1",