@applicaster/zapp-react-native-ui-components 16.0.0-rc.20 → 16.0.0-rc.22

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.
@@ -9,7 +9,7 @@ import { useScreenConfiguration } from "../useScreenConfiguration";
9
9
  import { RefreshControl } from "../RefreshControl";
10
10
  import { ifEmptyUseFallback } from "@applicaster/zapp-react-native-utils/cellUtils";
11
11
  import {
12
- usePipesCacheReset,
12
+ useMarkPipesDataStale,
13
13
  useProfilerLogging,
14
14
  } from "@applicaster/zapp-react-native-utils/reactHooks";
15
15
  import { useLoadingState } from "./hooks/useLoadingState";
@@ -154,7 +154,7 @@ function ComponentsMapComponent(props: Props) {
154
154
  [flatListHeight]
155
155
  );
156
156
 
157
- usePipesCacheReset(riverId, riverComponents);
157
+ useMarkPipesDataStale(riverId, riverComponents);
158
158
 
159
159
  const refreshControl = React.useMemo(
160
160
  () => (pullToRefreshEnabled ? <RefreshControl /> : null),
@@ -1,10 +1,11 @@
1
1
  import React from "react";
2
- import { StyleSheet, View } from "react-native";
3
-
2
+ import { StyleSheet, SafeAreaView as RNSafeAreaView } from "react-native";
3
+ import { SafeAreaView } from "react-native-safe-area-context";
4
4
  import { useIsRTL } from "@applicaster/zapp-react-native-utils/localizationUtils";
5
5
  import CloseButton from "./Buttons/CloseButton";
6
6
  import BackButton from "./Buttons/BackButton";
7
7
  import BarTitle from "./BarTitle";
8
+ import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
8
9
 
9
10
  type Props = {
10
11
  screenStyles: {
@@ -23,6 +24,11 @@ const defaultState: NavBarState = {
23
24
  title: "",
24
25
  };
25
26
 
27
+ const SafeAreaViewPlatform = platformSelect({
28
+ ios: RNSafeAreaView,
29
+ android: SafeAreaView,
30
+ });
31
+
26
32
  const BarView = ({ screenStyles, barState = defaultState }: Props) => {
27
33
  const isRTL = useIsRTL();
28
34
 
@@ -44,14 +50,15 @@ const BarView = ({ screenStyles, barState = defaultState }: Props) => {
44
50
  );
45
51
 
46
52
  return (
47
- <View
53
+ <SafeAreaViewPlatform
54
+ edges={["top", "left", "right"]}
48
55
  style={[style.view, isRTL ? style.rtlStyle : {}]}
49
- testID="BarView-Container"
56
+ testID="BarView-safeAreaView"
50
57
  >
51
58
  {backButton}
52
59
  <BarTitle title={barState.title} screenStyles={screenStyles} />
53
60
  {closeButton}
54
- </View>
61
+ </SafeAreaViewPlatform>
55
62
  );
56
63
  };
57
64
 
@@ -46,7 +46,7 @@ describe("BarView", () => {
46
46
  <BarView screenStyles={screenStyles} barState={barState} />
47
47
  );
48
48
 
49
- expect(getByTestId("BarView-Container").props.style).toContainEqual({
49
+ expect(getByTestId("BarView-safeAreaView").props.style).toContainEqual({
50
50
  transform: [{ scaleX: -1 }],
51
51
  });
52
52
  });
@@ -58,7 +58,7 @@ describe("BarView", () => {
58
58
  <BarView screenStyles={screenStyles} barState={barState} />
59
59
  );
60
60
 
61
- expect(getByTestId("BarView-Container").props.style).not.toContainEqual({
61
+ expect(getByTestId("BarView-safeAreaView").props.style).not.toContainEqual({
62
62
  transform: [{ scaleX: -1 }],
63
63
  });
64
64
  });
@@ -0,0 +1,154 @@
1
+ import { renderHook, act } from "@testing-library/react-native";
2
+
3
+ type DimensionsStore = {
4
+ setState: (
5
+ partial: { dimensions: Record<string, unknown>; ids: string[] },
6
+ replace?: boolean
7
+ ) => void;
8
+ };
9
+
10
+ const createdStores: DimensionsStore[] = [];
11
+
12
+ jest.mock("zustand", () => {
13
+ const actual = jest.requireActual<typeof import("zustand")>("zustand");
14
+
15
+ return {
16
+ ...actual,
17
+ create: ((initializer: Parameters<typeof actual.create>[0]) => {
18
+ const store = actual.create(initializer);
19
+ createdStores.push(store);
20
+
21
+ return store;
22
+ }) as typeof actual.create,
23
+ };
24
+ });
25
+
26
+ import { useCachedDimensions } from "../index";
27
+
28
+ const resetStore = () => {
29
+ const store = createdStores[createdStores.length - 1];
30
+
31
+ act(() => {
32
+ store?.setState({ dimensions: {}, ids: [] });
33
+ });
34
+ };
35
+
36
+ describe("useCachedDimensions", () => {
37
+ beforeEach(() => {
38
+ resetStore();
39
+ });
40
+
41
+ describe("getCachedDimensions", () => {
42
+ it("returns default dimensions when id has no cached value", () => {
43
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
44
+
45
+ expect(result.current.getCachedDimensions()).toEqual({
46
+ width: undefined,
47
+ height: undefined,
48
+ });
49
+ });
50
+
51
+ it("returns cached dimensions after setCachedDimensions", () => {
52
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
53
+ const dimensions = { width: 100, height: 200 };
54
+
55
+ act(() => {
56
+ result.current.setCachedDimensions(dimensions);
57
+ });
58
+
59
+ expect(result.current.getCachedDimensions()).toEqual(dimensions);
60
+ });
61
+ });
62
+
63
+ describe("setCachedDimensions", () => {
64
+ it("updates dimensions for the hook id", () => {
65
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
66
+
67
+ act(() => {
68
+ result.current.setCachedDimensions({ width: 50, height: 75 });
69
+ });
70
+
71
+ expect(result.current.getCachedDimensions()).toEqual({
72
+ width: 50,
73
+ height: 75,
74
+ });
75
+ });
76
+
77
+ it("shares cached dimensions between hook instances with the same id", () => {
78
+ const { result: first } = renderHook(() =>
79
+ useCachedDimensions("shared-id")
80
+ );
81
+
82
+ const { result: second } = renderHook(() =>
83
+ useCachedDimensions("shared-id")
84
+ );
85
+
86
+ act(() => {
87
+ first.current.setCachedDimensions({ width: 10, height: 20 });
88
+ });
89
+
90
+ expect(second.current.getCachedDimensions()).toEqual({
91
+ width: 10,
92
+ height: 20,
93
+ });
94
+ });
95
+ });
96
+
97
+ describe("getLastCachedDimensions", () => {
98
+ it("returns undefined when no dimensions have been cached", () => {
99
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
100
+
101
+ expect(result.current.getLastCachedDimensions()).toBeUndefined();
102
+ });
103
+
104
+ it("returns the most recently cached dimensions across ids", () => {
105
+ const { result: first } = renderHook(() => useCachedDimensions("first"));
106
+
107
+ const { result: second } = renderHook(() =>
108
+ useCachedDimensions("second")
109
+ );
110
+
111
+ act(() => {
112
+ first.current.setCachedDimensions({ width: 100, height: 100 });
113
+ });
114
+
115
+ act(() => {
116
+ second.current.setCachedDimensions({ width: 200, height: 200 });
117
+ });
118
+
119
+ expect(first.current.getLastCachedDimensions()).toEqual({
120
+ width: 200,
121
+ height: 200,
122
+ });
123
+ });
124
+
125
+ it("returns the latest dimensions when the same id is updated multiple times", () => {
126
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
127
+
128
+ act(() => {
129
+ result.current.setCachedDimensions({ width: 100, height: 100 });
130
+ });
131
+
132
+ act(() => {
133
+ result.current.setCachedDimensions({ width: 300, height: 400 });
134
+ });
135
+
136
+ expect(result.current.getLastCachedDimensions()).toEqual({
137
+ width: 300,
138
+ height: 400,
139
+ });
140
+ });
141
+ });
142
+
143
+ describe("return value", () => {
144
+ it("exposes getCachedDimensions, setCachedDimensions, and getLastCachedDimensions", () => {
145
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
146
+
147
+ expect(result.current).toEqual({
148
+ getCachedDimensions: expect.any(Function),
149
+ setCachedDimensions: expect.any(Function),
150
+ getLastCachedDimensions: expect.any(Function),
151
+ });
152
+ });
153
+ });
154
+ });
@@ -1,6 +1,7 @@
1
1
  import { create, useStore } from "zustand";
2
2
  import { produce } from "immer";
3
3
  import { useCallback, useMemo } from "react";
4
+ import { last } from "@applicaster/zapp-react-native-utils/utils";
4
5
 
5
6
  type Dimensions = {
6
7
  width: Option<number>;
@@ -10,14 +11,17 @@ type Dimensions = {
10
11
  type DimensionsState = {
11
12
  dimensions: Record<string, Dimensions>;
12
13
  setCachedDimensions: (id: string, dimensions: Dimensions) => void;
14
+ ids: string[];
13
15
  };
14
16
 
15
17
  const dimensionsStore = create<DimensionsState>((set) => ({
16
18
  dimensions: {},
19
+ ids: [],
17
20
  setCachedDimensions: (id, dimensions) =>
18
21
  set(
19
22
  produce((draft) => {
20
23
  draft.dimensions[id] = dimensions;
24
+ draft.ids.push(id);
21
25
  })
22
26
  ),
23
27
  }));
@@ -28,7 +32,7 @@ const initialDimensions = () => ({
28
32
  });
29
33
 
30
34
  export const useCachedDimensions = (id: string) => {
31
- const { dimensions, setCachedDimensions } = useStore(
35
+ const { dimensions, setCachedDimensions, ids } = useStore(
32
36
  dimensionsStore
33
37
  ) as DimensionsState;
34
38
 
@@ -40,11 +44,22 @@ export const useCachedDimensions = (id: string) => {
40
44
  setCachedDimensions(id, newDimensions);
41
45
  }, []);
42
46
 
47
+ const getLastCachedDimensions = useCallback(() => {
48
+ const previousId = last(ids);
49
+
50
+ if (!previousId) {
51
+ return undefined;
52
+ }
53
+
54
+ return dimensions[previousId];
55
+ }, [dimensions, ids]);
56
+
43
57
  return useMemo(
44
58
  () => ({
45
59
  getCachedDimensions,
46
60
  setCachedDimensions: handleSetCachedDimensions,
61
+ getLastCachedDimensions,
47
62
  }),
48
- [getCachedDimensions, handleSetCachedDimensions]
63
+ [getCachedDimensions, handleSetCachedDimensions, getLastCachedDimensions]
49
64
  );
50
65
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "16.0.0-rc.20",
3
+ "version": "16.0.0-rc.22",
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",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "16.0.0-rc.20",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.20",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.20",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.20",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.22",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.22",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.22",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.22",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",