@applicaster/zapp-react-native-utils 12.0.0-alpha.8242130253 → 12.0.0-alpha.8417280639

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.
@@ -245,6 +245,12 @@ const generalContent = () => ({
245
245
  ],
246
246
  initial_value: "reloading...",
247
247
  },
248
+ {
249
+ type: "text_input",
250
+ label: "Navigation Bar Screen Title",
251
+ key: "screen_title",
252
+ initial_value: null,
253
+ },
248
254
  ],
249
255
  },
250
256
  advertising: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-alpha.8242130253",
3
+ "version": "12.0.0-alpha.8417280639",
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.8242130253",
31
+ "@applicaster/applicaster-types": "12.0.0-alpha.8417280639",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -1,4 +1,8 @@
1
+ import React from "react";
2
+
1
3
  import { act, renderHook } from "@testing-library/react-hooks";
4
+ import { Provider } from "react-redux";
5
+ import configureStore from "redux-mock-store";
2
6
 
3
7
  const mockUpdateComponentsPositions = jest.fn();
4
8
 
@@ -19,11 +23,22 @@ jest.useFakeTimers();
19
23
 
20
24
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
21
25
 
26
+ const mockStore = configureStore();
27
+
28
+ const store = mockStore({ appData: {} });
29
+
30
+ const Wrapper = ({ children }: { children: React.ReactChild }) => (
31
+ /* @ts-ignore */
32
+ <Provider store={store}>{children}</Provider>
33
+ );
34
+
22
35
  const { useTrackedView } = require("../useTrackedView");
23
36
 
24
37
  describe("useTrackCurrentAutoScrollingElement", () => {
25
38
  it("should update position for selected component", async () => {
26
- const { result } = renderHook(() => useTrackedView("123"));
39
+ const { result } = renderHook(() => useTrackedView("123"), {
40
+ wrapper: Wrapper,
41
+ });
27
42
 
28
43
  // Fast-forward until all timers have been executed
29
44
  jest.advanceTimersByTime(3000);
@@ -1,4 +1,8 @@
1
+ import React from "react";
2
+
1
3
  import { cleanup, renderHook } from "@testing-library/react-hooks";
4
+ import { Provider } from "react-redux";
5
+ import configureStore from "redux-mock-store";
2
6
 
3
7
  import * as ReactNative from "react-native";
4
8
 
@@ -48,19 +52,43 @@ jest.mock("../../navigation", () => ({
48
52
  }));
49
53
 
50
54
  const { Dimensions } = require("react-native");
51
- const { useDimensions } = require("../");
55
+ const { useDimensions } = require("..");
56
+
57
+ const mockStore = configureStore();
58
+
59
+ const getWrapper = () => {
60
+ const store = mockStore({ appData: {} });
61
+
62
+ const Wrapper = ({ children }: { children: React.ReactChild }) => (
63
+ /* @ts-ignore */
64
+ <Provider store={store}>{children}</Provider>
65
+ );
66
+
67
+ return Wrapper;
68
+ };
69
+
70
+ const testHook = (context, params?) => {
71
+ const wrapper = getWrapper();
72
+
73
+ const {
74
+ result,
75
+ result: { current: dimensions },
76
+ } = renderHook(() => useDimensions(context, params), {
77
+ wrapper,
78
+ });
79
+
80
+ return { result, dimensions };
81
+ };
52
82
 
53
83
  describe("useDimensions", () => {
54
84
  it("renders", () => {
55
- const { result } = renderHook(() =>
56
- useDimensions("window", { fullDimensions: true })
57
- );
85
+ const { result } = testHook("window", { fullDimensions: true });
58
86
 
59
87
  expect(result).toBeDefined();
60
88
  });
61
89
 
62
90
  it("sets event listener", () => {
63
- renderHook(() => useDimensions("window", { fullDimensions: true }));
91
+ testHook("window", { fullDimensions: true });
64
92
 
65
93
  expect(Dimensions.addEventListener).toBeCalledWith(
66
94
  "change",
@@ -69,16 +97,14 @@ describe("useDimensions", () => {
69
97
  });
70
98
 
71
99
  it("removes event listener", () => {
72
- renderHook(() => useDimensions("window", { fullDimensions: true }));
100
+ testHook("window", { fullDimensions: true });
73
101
  cleanup();
74
102
 
75
103
  expect(mockRemoveFn).toBeCalled();
76
104
  });
77
105
 
78
106
  it("Returns full dimensions object", () => {
79
- const {
80
- result: { current: dimensions },
81
- } = renderHook(() => useDimensions("window", { fullDimensions: true }));
107
+ const { dimensions } = testHook("window", { fullDimensions: true });
82
108
 
83
109
  expect(dimensions).toHaveProperty("height");
84
110
  expect(dimensions).toHaveProperty("width");
@@ -87,20 +113,17 @@ describe("useDimensions", () => {
87
113
  });
88
114
 
89
115
  it("Returns shorthand dimensions object", () => {
90
- const {
91
- result: { current: dimensions },
92
- } = renderHook(() => useDimensions("window"));
116
+ const { dimensions } = testHook("window");
93
117
 
94
118
  expect(dimensions).toHaveProperty("height");
95
119
  expect(dimensions).toHaveProperty("width");
96
120
  });
97
121
 
98
122
  it("Returns the device info object", () => {
99
- const {
100
- result: { current: dimensions },
101
- } = renderHook(() =>
102
- useDimensions("window", { fullDimensions: true, deviceInfo: true })
103
- );
123
+ const { dimensions } = testHook("window", {
124
+ fullDimensions: true,
125
+ deviceInfo: true,
126
+ });
104
127
 
105
128
  expect(dimensions).toHaveProperty("height");
106
129
  expect(dimensions).toHaveProperty("width");
@@ -113,10 +136,7 @@ describe("useDimensions", () => {
113
136
  it("applies the scale on TV, and screen context", () => {
114
137
  tv_flag = true;
115
138
  const { screen } = mocked_return_value(tv_flag);
116
-
117
- const {
118
- result: { current: dimensions },
119
- } = renderHook(() => useDimensions("screen"));
139
+ const { dimensions } = testHook("screen");
120
140
 
121
141
  expect(dimensions).toHaveProperty("height", screen.height * screen.scale);
122
142
  expect(dimensions).toHaveProperty("width", screen.width * screen.scale);
@@ -128,10 +148,7 @@ describe("useDimensions", () => {
128
148
  it("doesn't apply the scale on mobile with screen context", () => {
129
149
  tv_flag = false;
130
150
  const { screen } = mocked_return_value(tv_flag);
131
-
132
- const {
133
- result: { current: dimensions },
134
- } = renderHook(() => useDimensions("screen"));
151
+ const { dimensions } = testHook("screen");
135
152
 
136
153
  expect(dimensions).toHaveProperty("height", screen.height);
137
154
  expect(dimensions).toHaveProperty("width", screen.width);
@@ -141,10 +158,7 @@ describe("useDimensions", () => {
141
158
  it("doesn't apply the scale on TV with window context", () => {
142
159
  tv_flag = true;
143
160
  const { window } = mocked_return_value(tv_flag);
144
-
145
- const {
146
- result: { current: dimensions },
147
- } = renderHook(() => useDimensions("window"));
161
+ const { dimensions } = testHook("window");
148
162
 
149
163
  expect(dimensions).toHaveProperty("height", window.height);
150
164
  expect(dimensions).toHaveProperty("width", window.width);
@@ -3,13 +3,15 @@ import { isTablet } from "../isTablet";
3
3
  /**
4
4
  * Returns an object with additional device info that can be used to determine if tablet
5
5
  * @param {Number} dimensions - Dimensions object passed to the function
6
+ * @param {Object} appData - application data object passed to the function
6
7
  * @returns {DeviceInfo} deviceInfo - returns an object with scale, isTablet, and orientation
7
8
  */
8
- export const getDeviceInfo = (dimensions) => {
9
+ export const getDeviceInfo = (dimensions, appData) => {
9
10
  const scale = dimensions?.scale;
10
11
  const isLandscape = dimensions?.width > dimensions?.height;
11
12
  const orientation = isLandscape ? "landscape" : "portrait";
12
13
  const tablet = isTablet(dimensions, orientation) || false;
14
+ const isTabletLandscape = tablet && !appData?.isTabletPortrait;
13
15
 
14
- return { scale, isTablet: tablet, orientation };
16
+ return { scale, isTablet: tablet, orientation, isTabletLandscape };
15
17
  };
@@ -2,6 +2,7 @@ type DeviceInfo = {
2
2
  isTablet: boolean;
3
3
  scale: number;
4
4
  orientation: string;
5
+ isTabletLandscape: boolean;
5
6
  };
6
7
 
7
8
  type RNDimensions = {
@@ -3,6 +3,8 @@ import { useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import * as R from "ramda";
4
4
 
5
5
  import { Dimensions, Platform, StatusBar } from "react-native";
6
+ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
+
6
8
  import { isTV } from "../../../reactUtils";
7
9
 
8
10
  import { Options, UseDimensions } from "../types";
@@ -36,6 +38,7 @@ export const useDimensions: UseDimensions = (
36
38
  fullDimensions = { fullDimensions: false, updateForInactiveScreens: true }
37
39
  ) => {
38
40
  const isActive = useIsScreenActive();
41
+ const { appData } = usePickFromState(["appData"]);
39
42
 
40
43
  if (typeof fullDimensions === "boolean") {
41
44
  // eslint-disable-next-line no-console
@@ -50,7 +53,7 @@ export const useDimensions: UseDimensions = (
50
53
  : { ...fullDimensions };
51
54
 
52
55
  const [dimensions, setDimensions] = useState(getInitialDimensions(context));
53
- const deviceInfo = useRef(getDeviceInfo(dimensions));
56
+ const deviceInfo = useRef(getDeviceInfo(dimensions, appData));
54
57
 
55
58
  const applyOptions = R.compose(
56
59
  R.when(() => options.deviceInfo, R.assoc("deviceInfo", deviceInfo.current)),
@@ -85,7 +88,7 @@ export const useDimensions: UseDimensions = (
85
88
  // eslint-disable-next-line no-console
86
89
  console.log("change: wrong values - width equal to height, ignoring");
87
90
  } else if (isActive || options.updateForInactiveScreens) {
88
- deviceInfo.current = getDeviceInfo(newDimensions);
91
+ deviceInfo.current = getDeviceInfo(newDimensions, appData);
89
92
  setDimensions(newDimensions);
90
93
  }
91
94
  };
@@ -251,6 +251,11 @@ export const useRoute = (): {
251
251
  return composeRouteData(screenData);
252
252
  }
253
253
 
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
+ }
258
+
254
259
  return composeRouteData(currentRouteScreenData);
255
260
  };
256
261