@applicaster/quick-brick-core 14.0.0-rc.9 → 15.0.0-rc.2

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 (40) hide show
  1. package/App/ActionSetters/index.ts +0 -1
  2. package/App/ActionsProvider/__tests__/__snapshots__/ActionsProvider.test.js.snap +2 -2
  3. package/App/ActionsProvider/index.js +1 -1
  4. package/App/AppStateDecorator/index.tsx +9 -4
  5. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +4 -12
  6. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/usePresentSchemeHandler.test.tsx +34 -41
  7. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.tsx +1 -1
  8. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useOpenSchemeHandler/index.ts +7 -2
  9. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/usePresentSchemeHandler.ts +6 -4
  10. package/App/DeepLinking/URLSchemeHandler/__tests__/URLSchemeHandler.test.tsx +4 -4
  11. package/App/ErrorBoundary/index.tsx +4 -0
  12. package/App/ModalProvider/ModalBottomSheet/DraggableBottomSheet/index.tsx +2 -2
  13. package/App/ModalProvider/ModalBottomSheet/ModalBottomSheetFrame.tsx +1 -1
  14. package/App/ModalProvider/ModalChildrenWrapper/index.tsx +2 -7
  15. package/App/ModalProvider/ModalPresenter.tsx +2 -1
  16. package/App/NavigationProvider/NavigationProvider.tsx +29 -9
  17. package/App/NavigationProvider/navigator/__tests__/__snapshots__/reducer.test.ts.snap +0 -177
  18. package/App/NavigationProvider/navigator/__tests__/reducer.test.ts +2 -70
  19. package/App/NavigationProvider/navigator/reducer.ts +30 -101
  20. package/App/NavigationProvider/navigator/selectors.ts +2 -1
  21. package/App/NetworkStatusProvider/__tests__/NetworkStatusProvider.test.tsx +11 -15
  22. package/App/RouterDecorator/__tests__/routerDecorator.test.js +3 -3
  23. package/App/StoreConnector/__tests__/storeConnector.test.js +6 -9
  24. package/App/StoreConnector/index.ts +1 -1
  25. package/App/ThemeManager/index.tsx +9 -1
  26. package/App/__tests__/createQuickBrickApp.test.js +13 -10
  27. package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.tsx +29 -25
  28. package/App/appLifeCycleManager/index.tsx +5 -6
  29. package/App/components/ZappAppWrapper.ts +3 -0
  30. package/App/components/ZappAppWrapper.web.ts +3 -0
  31. package/App/index.tsx +28 -22
  32. package/App/remoteContextReloader/__tests__/getRemoteContextData.test.js +11 -12
  33. package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +5 -3
  34. package/README.md +0 -4
  35. package/const/index.ts +6 -0
  36. package/createZappApp/__tests__/createZappApp.test.js +11 -0
  37. package/createZappApp/index.tsx +4 -5
  38. package/index.d.ts +0 -1
  39. package/package.json +9 -21
  40. package/renderZappApp/index.js +2 -1
@@ -12,7 +12,6 @@ const debugActions = (actions) =>
12
12
  message: `useSubscribeToActionProviders - available actions count: ${
13
13
  Object.keys(actions).length
14
14
  }`,
15
- data: { actions },
16
15
  });
17
16
 
18
17
  const warnUndefinedContext = (context) =>
@@ -12,18 +12,18 @@ exports[`Actions Provider renders children 1`] = `
12
12
  "$$typeof": Symbol(react.context),
13
13
  "Consumer": {
14
14
  "$$typeof": Symbol(react.context),
15
- "_calculateChangedBits": null,
16
15
  "_context": [Circular],
17
16
  },
18
17
  "Provider": {
19
18
  "$$typeof": Symbol(react.provider),
20
19
  "_context": [Circular],
21
20
  },
22
- "_calculateChangedBits": null,
23
21
  "_currentRenderer": null,
24
22
  "_currentRenderer2": {},
25
23
  "_currentValue": null,
26
24
  "_currentValue2": null,
25
+ "_defaultValue": null,
26
+ "_globalName": null,
27
27
  "_threadCount": 0,
28
28
  },
29
29
  "contextProvider": [Function],
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import * as R from "ramda";
3
3
 
4
- import { connectToStore } from "@applicaster/zapp-react-native-redux";
4
+ import { connectToStore } from "@applicaster/zapp-react-native-redux/utils/connectToStore";
5
5
 
6
6
  import { ActionsProvider as ActionsProviderComponent } from "./ActionsProvider";
7
7
 
@@ -2,9 +2,9 @@ import * as React from "react";
2
2
  import { AppState, AppStateStatus } from "react-native";
3
3
  import * as R from "ramda";
4
4
 
5
- import { connectToStore } from "@applicaster/zapp-react-native-redux";
5
+ import { connectToStore } from "@applicaster/zapp-react-native-redux/utils/connectToStore";
6
6
  import { setAppState } from "@applicaster/zapp-react-native-redux/appState";
7
- import { Dispatch } from "redux";
7
+ import { Dispatch } from "@reduxjs/toolkit";
8
8
 
9
9
  type Props = {
10
10
  Component: () => React.ComponentType<any>;
@@ -19,6 +19,7 @@ function withAppManagerDecorator(
19
19
  currentState: AppStateStatus;
20
20
  isAvailable: boolean;
21
21
  plugins: QuickBrickPlugin[];
22
+ appStateListener: ReturnType<typeof AppState.addEventListener>;
22
23
 
23
24
  constructor(props: Props) {
24
25
  super(props);
@@ -30,11 +31,15 @@ function withAppManagerDecorator(
30
31
 
31
32
  componentDidMount() {
32
33
  this.plugins = this.getAppStatePlugins();
33
- AppState.addEventListener("change", this.onChange);
34
+
35
+ this.appStateListener = AppState.addEventListener(
36
+ "change",
37
+ this.onChange
38
+ );
34
39
  }
35
40
 
36
41
  componentWillUnmount() {
37
- AppState.removeEventListener("change", this.onChange);
42
+ this.appStateListener.remove();
38
43
  }
39
44
 
40
45
  dispatchAction(nextState: AppStateStatus, eventType) {
@@ -16,7 +16,7 @@ import {
16
16
  } from "../useOpenSchemeHandler/const";
17
17
  import { withInitialPlayerState } from "../useOpenSchemeHandler/utils";
18
18
 
19
- const { log_warning } = require("../../../logger");
19
+ import { log_warning } from "../../../logger";
20
20
 
21
21
  const rivers: Record<string, Partial<ZappRiver>> = {
22
22
  A1234: {
@@ -53,13 +53,10 @@ const navigator = {
53
53
  replace: jest.fn(),
54
54
  push: jest.fn(),
55
55
  goHome: jest.fn(),
56
- };
56
+ } as any;
57
57
 
58
58
  const mockStore = configureStore();
59
-
60
- jest
61
- .spyOn(useNavigationHooks, "useNavigation")
62
- .mockImplementation(() => navigator);
59
+ jest.spyOn(useNavigationHooks, "useNavigation").mockReturnValue(navigator);
63
60
 
64
61
  const helperSpy = jest.spyOn(helpers, "handlePresentNavigation");
65
62
  const feedLoaderSpy = jest.spyOn(feedLoader, "useFeedLoader");
@@ -72,7 +69,7 @@ jest.doMock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
72
69
  },
73
70
  }));
74
71
 
75
- jest.doMock("../../../logger", () => ({
72
+ jest.mock("../../../logger", () => ({
76
73
  log_info: jest.fn(),
77
74
  log_error: jest.fn(),
78
75
  log_warning: jest.fn(),
@@ -80,10 +77,6 @@ jest.doMock("../../../logger", () => ({
80
77
  log_debug: jest.fn(),
81
78
  }));
82
79
 
83
- jest.useFakeTimers({
84
- legacyFakeTimers: true,
85
- });
86
-
87
80
  // to use import instead of require it's required to use jest.mock above
88
81
  const { useOpenSchemeHandler } = require("../useOpenSchemeHandler");
89
82
 
@@ -192,7 +185,6 @@ describe("useOpenSchemeHandler", () => {
192
185
  it("doesn't log a warning", async () => {
193
186
  const tests = () => {
194
187
  expect(log_warning).not.toHaveBeenCalled();
195
- expect.assertions(1);
196
188
  };
197
189
 
198
190
  await testHook({ url, query, tests });
@@ -1,14 +1,12 @@
1
- import * as React from "react";
2
1
  import * as R from "ramda";
3
2
  import axios from "axios";
4
- import { renderHook } from "@testing-library/react-hooks";
3
+ import { renderHook } from "@testing-library/react-native";
5
4
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
6
- import * as zappRedux from "@applicaster/zapp-react-native-redux";
7
5
  import * as helpers from "../../../helpers";
8
6
  import * as feedLoader from "@applicaster/zapp-react-native-utils/reactHooks/feed/useFeedLoader";
9
- import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
7
+ import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
8
+ import { usePresentSchemeHandler } from "../usePresentSchemeHandler";
10
9
 
11
- import { Provider } from "react-redux";
12
10
  import configureStore from "redux-mock-store";
13
11
 
14
12
  const rivers = {
@@ -17,26 +15,31 @@ const rivers = {
17
15
  },
18
16
  };
19
17
 
20
- const navigator = {
18
+ const mock_navigator = {
21
19
  currentRoute: "/river/A1234",
22
20
  replace: jest.fn(),
23
- };
21
+ goHome: jest.fn(),
22
+ } as any;
24
23
 
25
- const mockStore = configureStore();
24
+ jest.mock(
25
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation",
26
+ () => ({
27
+ useNavigation: jest.fn(() => mock_navigator),
28
+ })
29
+ );
26
30
 
27
- jest
28
- .spyOn(useNavigationHooks, "useNavigation")
29
- .mockImplementation(() => navigator);
31
+ const mockStore = configureStore();
30
32
 
31
33
  const helperSpy = jest.spyOn(helpers, "handlePresentNavigation");
32
34
  const feedLoaderSpy = jest.spyOn(feedLoader, "useFeedLoader");
33
35
 
34
- const { usePresentSchemeHandler } = require("../usePresentSchemeHandler");
35
-
36
36
  const onFinish = jest.fn((cb) => {
37
37
  cb();
38
38
  });
39
39
 
40
+ const navigator = mock_navigator;
41
+ jest.useFakeTimers();
42
+
40
43
  describe("usePresentSchemeHandler", () => {
41
44
  beforeEach(() => {
42
45
  onFinish.mockClear();
@@ -44,11 +47,7 @@ describe("usePresentSchemeHandler", () => {
44
47
  navigator.replace.mockClear();
45
48
  });
46
49
 
47
- const store = mockStore({ test: "test", rivers });
48
-
49
- const wrapper: React.FC<any> = ({ children }) => (
50
- <Provider store={store}>{children}</Provider>
51
- );
50
+ const store = { test: "test", rivers };
52
51
 
53
52
  describe("loading link url", () => {
54
53
  const query = { link_url: "http://applicaster.com" };
@@ -59,10 +58,11 @@ describe("usePresentSchemeHandler", () => {
59
58
 
60
59
  it("opens the link entry", () => {
61
60
  renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
62
- wrapper,
61
+ wrapper: WrappedWithProviders,
62
+ initialProps: { store },
63
63
  });
64
64
 
65
- expect(onFinish).toBeCalled();
65
+ expect(onFinish).toHaveBeenCalled();
66
66
 
67
67
  expect(helperSpy).toBeCalledWith(
68
68
  expect.objectContaining({
@@ -96,7 +96,8 @@ describe("usePresentSchemeHandler", () => {
96
96
  onFinish,
97
97
  }),
98
98
  {
99
- wrapper,
99
+ wrapper: WrappedWithProviders,
100
+ initialProps: { store },
100
101
  }
101
102
  );
102
103
 
@@ -123,7 +124,8 @@ describe("usePresentSchemeHandler", () => {
123
124
  )}&show_nav_bar=true`;
124
125
 
125
126
  renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
126
- wrapper,
127
+ wrapper: WrappedWithProviders,
128
+ initialProps: { store },
127
129
  });
128
130
 
129
131
  expect(onFinish).toBeCalled();
@@ -155,22 +157,22 @@ describe("usePresentSchemeHandler", () => {
155
157
  )}&screen_id=${screen_id}`;
156
158
 
157
159
  renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
158
- wrapper,
160
+ wrapper: WrappedWithProviders,
161
+ initialProps: { store },
159
162
  });
160
163
 
161
164
  expect(onFinish).toBeCalled();
162
165
 
163
- expect(helperSpy).toBeCalledWith(
166
+ expect(helperSpy).toHaveBeenCalledWith(
164
167
  expect.objectContaining({
165
168
  data: {
166
169
  id: "url_scheme_entry",
167
170
  type: { value: "link" },
168
- screen_type: screen_id,
169
171
  link: { href: query.link_url, type: "text/html" },
170
172
  extensions: { showNavBar: false },
171
173
  },
172
- navigator,
173
- pushScreen: expect.anything(),
174
+ navigator: expect.anything(),
175
+ pushScreen: "http://applicaster.com",
174
176
  })
175
177
  );
176
178
  });
@@ -180,9 +182,7 @@ describe("usePresentSchemeHandler", () => {
180
182
  it("Re-sets app ready state and calls loadAppContextData with new river and cellStyles data", async () => {
181
183
  const store = mockStore({ test: "test" });
182
184
 
183
- const wrapper: React.FC<any> = ({ children }) => (
184
- <Provider store={store}>{children}</Provider>
185
- );
185
+ const wrapper = WrappedWithProviders;
186
186
 
187
187
  const query = {
188
188
  rivers_configuration_id: "test",
@@ -190,7 +190,6 @@ describe("usePresentSchemeHandler", () => {
190
190
 
191
191
  const storageSpy = jest.spyOn(sessionStorage, "getAllItems");
192
192
  const axiosGetSpy = jest.spyOn(axios, "get");
193
- const zappReduxSpy = jest.spyOn(zappRedux, "loadAppContextData");
194
193
 
195
194
  const getAllItems = jest.fn().mockResolvedValue({
196
195
  accountsAccountId: "accountsAccountId",
@@ -204,7 +203,6 @@ describe("usePresentSchemeHandler", () => {
204
203
 
205
204
  storageSpy.mockImplementation(getAllItems);
206
205
  axiosGetSpy.mockImplementation(get);
207
- zappReduxSpy.mockReturnValue(null);
208
206
 
209
207
  renderHook(() => usePresentSchemeHandler({ query, url: "", onFinish }), {
210
208
  wrapper,
@@ -219,11 +217,6 @@ describe("usePresentSchemeHandler", () => {
219
217
 
220
218
  expect(actions?.find(R.propEq("type", "SET_APP_READY"))).toBeDefined();
221
219
 
222
- expect(zappReduxSpy).toBeCalledWith(expect.any(Function), {
223
- cellStyles: "url",
224
- rivers: "url",
225
- });
226
-
227
220
  expect(navigator.replace).toBeCalledWith({});
228
221
  };
229
222
  });
@@ -261,7 +254,7 @@ describe("usePresentSchemeHandler", () => {
261
254
  },
262
255
  }),
263
256
  {
264
- wrapper,
257
+ wrapper: WrappedWithProviders,
265
258
  }
266
259
  );
267
260
 
@@ -293,7 +286,7 @@ describe("usePresentSchemeHandler", () => {
293
286
  },
294
287
  }),
295
288
  {
296
- wrapper,
289
+ wrapper: WrappedWithProviders,
297
290
  }
298
291
  );
299
292
 
@@ -325,7 +318,7 @@ describe("usePresentSchemeHandler", () => {
325
318
  },
326
319
  }),
327
320
  {
328
- wrapper,
321
+ wrapper: WrappedWithProviders,
329
322
  }
330
323
  );
331
324
 
@@ -357,7 +350,7 @@ describe("usePresentSchemeHandler", () => {
357
350
  },
358
351
  }),
359
352
  {
360
- wrapper,
353
+ wrapper: WrappedWithProviders,
361
354
  }
362
355
  );
363
356
 
@@ -5,7 +5,7 @@ import * as URLHandlersMap from "..";
5
5
  import { Provider } from "react-redux";
6
6
  import configureStore from "redux-mock-store";
7
7
 
8
- const { log_warning } = require("../../../logger");
8
+ import { log_warning } from "../../../logger";
9
9
 
10
10
  const mockStore = configureStore();
11
11
 
@@ -1,4 +1,8 @@
1
- import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
1
+ import {
2
+ useAppSelector,
3
+ selectContentTypes,
4
+ selectRivers,
5
+ } from "@applicaster/zapp-react-native-redux";
2
6
  import { ZappPipesEntryContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
3
7
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
4
8
  import { useEffect } from "react";
@@ -97,7 +101,8 @@ async function handleQuery({
97
101
  }
98
102
 
99
103
  export function useOpenSchemeHandler({ query, url, onFinish }) {
100
- const { rivers, contentTypes } = usePickFromState(["rivers", "contentTypes"]);
104
+ const rivers = useAppSelector(selectRivers);
105
+ const contentTypes = useAppSelector(selectContentTypes);
101
106
  const navigator = useNavigation();
102
107
  const homeId = getHomeScreenId(rivers);
103
108
  const homeRoute = `/river/${homeId}`;
@@ -1,15 +1,17 @@
1
- import { useActions } from "@applicaster/zapp-react-native-redux/hooks";
1
+ import {
2
+ loadAppContextData,
3
+ useAppDispatch,
4
+ useActions,
5
+ } from "@applicaster/zapp-react-native-redux";
2
6
  import * as R from "ramda";
3
7
  import * as React from "react";
4
8
  import axios from "axios";
5
- import { useDispatch } from "react-redux";
6
9
 
7
10
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
8
11
 
9
12
  import { useFeedLoader } from "@applicaster/zapp-react-native-utils/reactHooks/feed/useFeedLoader";
10
13
 
11
14
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
12
- import { loadAppContextData } from "@applicaster/zapp-react-native-redux";
13
15
  import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
14
16
 
15
17
  import {
@@ -60,7 +62,7 @@ export function usePresentSchemeHandler({
60
62
 
61
63
  const rivers = useRivers();
62
64
  const screenRiver = findRiver({ screen_id, rivers });
63
- const dispatch = useDispatch();
65
+ const dispatch = useAppDispatch();
64
66
 
65
67
  const actions = useActions({
66
68
  setAppReady,
@@ -6,16 +6,16 @@ const theme = {
6
6
  app_background_color: "white",
7
7
  };
8
8
 
9
- const plugins = [];
10
-
11
- jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
9
+ jest.mock(
10
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation"
11
+ );
12
12
 
13
13
  jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
14
14
  useTheme: jest.fn(() => theme),
15
15
  }));
16
16
 
17
17
  jest.mock("@applicaster/zapp-react-native-redux/hooks", () => ({
18
- usePickFromState: jest.fn(() => plugins),
18
+ usePickFromState: jest.fn(() => ({})),
19
19
  }));
20
20
 
21
21
  const { URLSchemeHandler } = require("../URLSchemeHandler");
@@ -60,6 +60,10 @@ export class ErrorBoundary extends React.Component<Props> {
60
60
  useErrorStore.getState().setError(error, info, recoverable);
61
61
  }
62
62
 
63
+ static getDerivedStateFromError(_error) {
64
+ return { hasError: true };
65
+ }
66
+
63
67
  render() {
64
68
  return <ErrorBoundaryContent>{this.props.children}</ErrorBoundaryContent>;
65
69
  }
@@ -52,9 +52,9 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
52
52
  _lastScrollYValue: number;
53
53
  _lastScrollY: Animated.Value;
54
54
  _dragY: Animated.Value;
55
- _reverseLastScrollY: Animated.AnimatedMultiplication;
55
+ _reverseLastScrollY: Animated.AnimatedInterpolation<number>;
56
56
  _translateYOffset: Animated.Value;
57
- _translateY: Animated.AnimatedAddition;
57
+ _translateY: Animated.AnimatedInterpolation<number>;
58
58
  _snapPoints: SnapPoints;
59
59
  _prevContentHeight = 0;
60
60
 
@@ -47,7 +47,7 @@ const getSheetHeight = ({ height, bottomOffset, maxHeight }) => {
47
47
  ios: height - bottomOffset,
48
48
  default:
49
49
  (height || maxHeight) -
50
- (!isAndroidVersionAtLeast(35) && isAndroidPlatform() ? bottomOffset : 0),
50
+ (isAndroidPlatform() && !isAndroidVersionAtLeast(35) ? bottomOffset : 0),
51
51
  });
52
52
  };
53
53
 
@@ -1,13 +1,8 @@
1
1
  import React, { ReactChild } from "react";
2
- import { StyleSheet, ViewProps } from "react-native";
3
- import { GestureHandlerRootView } from "react-native-gesture-handler";
2
+ import { View, StyleSheet, ViewProps } from "react-native";
4
3
 
5
4
  type Props = ViewProps & { children: ReactChild };
6
5
 
7
6
  export function ModalChildrenWrapper({ children }: Props) {
8
- return (
9
- <GestureHandlerRootView style={StyleSheet.absoluteFill}>
10
- {children}
11
- </GestureHandlerRootView>
12
- );
7
+ return <View style={StyleSheet.absoluteFill}>{children}</View>;
13
8
  }
@@ -1,5 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { Modal, ModalProps } from "react-native";
3
+ import { GestureHandlerRootView } from "react-native-gesture-handler";
3
4
 
4
5
  type Props = ModalProps & {
5
6
  children: React.ReactChild;
@@ -13,7 +14,7 @@ export function ModalPresenter(props: Props) {
13
14
 
14
15
  return (
15
16
  <Presenter visible={visible} {...presenterOptions}>
16
- {children}
17
+ <GestureHandlerRootView>{children}</GestureHandlerRootView>
17
18
  </Presenter>
18
19
  );
19
20
  }
@@ -7,6 +7,7 @@ import {
7
7
  getTargetRoute,
8
8
  usesVideoModal,
9
9
  } from "@applicaster/zapp-react-native-utils/navigationUtils";
10
+ import { last } from "@applicaster/zapp-react-native-utils/utils";
10
11
  import {
11
12
  allowedOrientationsForScreen,
12
13
  useGetScreenOrientation,
@@ -121,8 +122,20 @@ export function NavigationProvider({ children }: Props) {
121
122
  NavigationReducerState
122
123
  >(reducer, initialState, (x) => x);
123
124
 
125
+ const topStackRoute = last(state?.stack?.mainStack);
126
+
127
+ /** TODO: temporary variable, before we remove need for a "current".
128
+ There is no current as we are using stack navigator. Route data should be contextualised per screen
129
+ There are some cases to use a route data from top of the stack but it should be separate method.
130
+ */
131
+
132
+ const currentLocation = {
133
+ ...topStackRoute,
134
+ route: topStackRoute?.route || "/", // Fallback for initial state.
135
+ };
136
+
124
137
  const stateRef = React.useRef<NavigationReducerState>(state);
125
- const pathname = state?.location?.pathname;
138
+ const pathname = currentLocation?.route; // TODO: remove. Pathname is part of the route, not a global.
126
139
  const pathnameRef = React.useRef(pathname);
127
140
 
128
141
  const { context } = React.useContext(ZappPipesEntryContext.Context);
@@ -146,6 +159,8 @@ export function NavigationProvider({ children }: Props) {
146
159
  }
147
160
  }, [pathname]);
148
161
 
162
+ // TODO remove.
163
+ // There is no concept of active river. Multiple rivers can be rendered at the same time.
149
164
  const activeRiver = React.useMemo(
150
165
  () => activeRiverSelector({ pathname, rivers }),
151
166
  [pathname, rivers]
@@ -186,6 +201,7 @@ export function NavigationProvider({ children }: Props) {
186
201
  // TODO: Move in proper place
187
202
  const modalPresenterScreenOrientation = useGetScreenOrientation(activeRiver);
188
203
 
204
+ // TODO: Move modal state to separate store
189
205
  const closeVideoModal = () => {
190
206
  if (navigator.modalData) {
191
207
  allowedOrientationsForScreen(modalPresenterScreenOrientation);
@@ -213,13 +229,15 @@ export function NavigationProvider({ children }: Props) {
213
229
  const isVideoModalDocked = () =>
214
230
  state?.options.videoModal.mode === "MINIMIZED";
215
231
 
232
+ // TODO: Remove as it's using a concept of "current" route.
233
+ // Route is contextualised and shouldn't be used this way.
216
234
  const routeData = () => {
217
235
  // eslint-disable-next-line no-console
218
236
  console.warn(`you are retrieving screen data from navigator.routeData()
219
237
  This function will be removed in a later version of quick brick.
220
238
  You can retrieve this data from navigator.screenData`);
221
239
 
222
- return legacyScreenData(state?.location?.state as NavigationScreenData);
240
+ return legacyScreenData(currentLocation?.state as NavigationScreenData);
223
241
  };
224
242
 
225
243
  // TODO: remove it by refactoring back buttons handlers
@@ -262,7 +280,7 @@ export function NavigationProvider({ children }: Props) {
262
280
  if (
263
281
  targetRoute !== pathnameRef.current ||
264
282
  item?.id !==
265
- legacyScreenData(state?.location?.state as NavigationScreenData)?.id
283
+ legacyScreenData(currentLocation?.state as NavigationScreenData)?.id
266
284
  ) {
267
285
  replaceEvent();
268
286
  navigateTo(item, ACTIONS.REPLACE, options);
@@ -688,7 +706,8 @@ export function NavigationProvider({ children }: Props) {
688
706
  }
689
707
  }, [state?.options?.videoModal?.previousMode]);
690
708
 
691
- const getNestedEntry = () => state?.location?.state?.nested?.entry ?? null;
709
+ // TODO: remove. This shouldn't be part of navigator
710
+ const getNestedEntry = () => currentLocation?.state?.nested?.entry ?? null;
692
711
 
693
712
  // It will only work for the regular stack and pathname, It won't work for modals
694
713
  // TODO: integrate video/hook and regular modal into stack.
@@ -706,7 +725,7 @@ export function NavigationProvider({ children }: Props) {
706
725
  () => ({
707
726
  activeRiver,
708
727
  getPathname: () => pathnameRef.current, // hack use to fix issue causing broken navigation as currentRoute is unreliable
709
- currentRoute: pathname,
728
+ currentRoute: pathname, // TODO: remove. Current route shouldn't be needed
710
729
  previousAction: lastEntrySelector(state)
711
730
  ?.action as QuickBrickNavigationActionType,
712
731
  push: pushItem,
@@ -716,14 +735,15 @@ export function NavigationProvider({ children }: Props) {
716
735
  goHome,
717
736
  canGoBack,
718
737
  goBack,
719
- routeData,
738
+ routeData, // TODO: remove
720
739
  screenData: legacyScreenData(
721
- state?.location?.state as NavigationScreenData,
740
+ // TODO: remove
741
+ currentLocation?.state as NavigationScreenData,
722
742
  plugins
723
743
  ),
724
- data: state?.location?.state as NavigationScreenData,
744
+ data: currentLocation?.state as NavigationScreenData,
725
745
  getNestedEntry,
726
- key: state?.location?.key,
746
+ key: currentLocation?.key, // TODO: remove
727
747
  modalData: state.stack.modal?.state ?? null,
728
748
  openModal,
729
749
  dismissModal,