@applicaster/zapp-react-native-ui-components 15.0.0-alpha.9361645236 → 15.0.0-alpha.9667030680

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.
@@ -208,14 +208,14 @@ export class CellComponent extends React.Component<Props, State> {
208
208
  this.accessibilityManager.readText({
209
209
  text: " ",
210
210
  });
211
- } else {
211
+ } else if (this.state.cellFocused) {
212
212
  this.accessibilityManager.readText({
213
213
  text: `${positionLabel}`,
214
214
  });
215
215
  }
216
216
  }
217
217
 
218
- componentDidUpdate(prevProps: Readonly<Props>) {
218
+ componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<State>) {
219
219
  if (prevProps.item !== this.props.item) {
220
220
  this.setState({
221
221
  hasFocusableInside: this.props.CellRenderer.hasFocusableInside?.(
@@ -224,7 +224,12 @@ export class CellComponent extends React.Component<Props, State> {
224
224
  });
225
225
  }
226
226
 
227
- this.handleAccessibilityFocus(this.props.index, this.props.dataLength);
227
+ if (
228
+ prevState.cellFocused !== this.state.cellFocused ||
229
+ this.state.hasFocusableInside
230
+ ) {
231
+ this.handleAccessibilityFocus(this.props.index, this.props.dataLength);
232
+ }
228
233
  }
229
234
 
230
235
  render() {
@@ -1,8 +1,8 @@
1
+ import * as React from "react";
1
2
  import {
2
3
  BorderContainerView,
3
4
  getBorderPadding, // Export for testing (using a double underscore prefix is a common convention)
4
5
  } from "../index";
5
- import * as React from "react";
6
6
  import { render } from "@testing-library/react-native";
7
7
  import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/numberUtils";
8
8
  import { View } from "react-native";
@@ -11,6 +11,12 @@ jest.mock("@applicaster/zapp-react-native-utils/numberUtils", () => ({
11
11
  toNumberWithDefaultZero: jest.fn((value) => Number(value) || 0),
12
12
  }));
13
13
 
14
+ jest.mock("@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/hooks", () => ({
15
+ useAccessibilityManager: jest.fn(() => ({
16
+ addHeading: jest.fn(),
17
+ })),
18
+ }));
19
+
14
20
  describe("BorderContainerView", () => {
15
21
  describe("getBorderPadding", () => {
16
22
  it("returns 0 for inside", () => {
@@ -42,6 +48,8 @@ describe("BorderContainerView", () => {
42
48
  };
43
49
 
44
50
  const borderPosition = null;
51
+ const mockEntry = { id: "test-entry" } as ZappEntry;
52
+ const mockHasFocusableInside = jest.fn(() => false);
45
53
 
46
54
  const { queryByTestId } = render(
47
55
  <BorderContainerView
@@ -52,6 +60,10 @@ describe("BorderContainerView", () => {
52
60
  borderPaddingRight={toNumberWithDefaultZero(padding.paddingRight)}
53
61
  borderPaddingBottom={toNumberWithDefaultZero(padding.paddingBottom)}
54
62
  borderPaddingLeft={toNumberWithDefaultZero(padding.paddingLeft)}
63
+ hasFocusableInside={mockHasFocusableInside}
64
+ entry={mockEntry}
65
+ state="focused"
66
+ hasTextLabels={false}
55
67
  >
56
68
  <View testID="child" />
57
69
  </BorderContainerView>
@@ -1,10 +1,16 @@
1
- import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/numberUtils";
2
- import * as React from "react";
1
+ import React, { useMemo, useContext, useEffect } from "react";
3
2
  import { ImageStyle, StyleSheet, View, ViewStyle } from "react-native";
3
+ import { useAccessibilityManager } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/hooks";
4
+ import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/numberUtils";
5
+ import { MeasurementPortalContext } from "../../../MeasurmentsPortal/MeasurementsPortal";
4
6
 
5
7
  type BorderPosition = "inside" | "outside" | "center";
6
8
 
7
9
  interface Props {
10
+ hasFocusableInside: (entry: ZappEntry) => boolean;
11
+ entry: ZappEntry;
12
+ state: CellState;
13
+ hasTextLabels: boolean;
8
14
  style: ImageStyle | ViewStyle;
9
15
  borderPosition: BorderPosition;
10
16
  borderPaddingTop: number;
@@ -118,8 +124,30 @@ export const BorderContainerView = (props: Props) => {
118
124
  borderPaddingLeft,
119
125
  style,
120
126
  children,
127
+ hasFocusableInside,
128
+ entry,
129
+ state,
130
+ hasTextLabels,
121
131
  } = props;
122
132
 
133
+ const accessibilityManager = useAccessibilityManager();
134
+ const isMeasurement = useContext(MeasurementPortalContext);
135
+
136
+ const isImageOnlyCell = useMemo(
137
+ () =>
138
+ !hasFocusableInside(entry) &&
139
+ !hasTextLabels &&
140
+ state === "focused" &&
141
+ !isMeasurement,
142
+ [hasFocusableInside, entry, hasTextLabels, state, isMeasurement]
143
+ );
144
+
145
+ useEffect(() => {
146
+ if (isImageOnlyCell && entry?.title) {
147
+ accessibilityManager.addHeading(String(entry.title));
148
+ }
149
+ }, [isImageOnlyCell, entry?.title]);
150
+
123
151
  const padding =
124
152
  borderPosition === "outside"
125
153
  ? {
@@ -52,14 +52,14 @@ const _Text = ({
52
52
  : textTransform(transformText, _label);
53
53
 
54
54
  React.useLayoutEffect(() => {
55
- // For FocusableCells with action buttons
56
- if (otherProps.state) {
57
- if (otherProps.state === "focused" && cellFocused === true) {
58
- accessibilityManager.addHeading(textLabel);
59
- }
60
- } else {
61
- if (cellFocused === true) {
62
- accessibilityManager.addHeading(textLabel);
55
+ if (cellFocused) {
56
+ switch (otherProps.state) {
57
+ case "focused":
58
+ accessibilityManager.addHeading(textLabel);
59
+ break;
60
+ case "focused_selected":
61
+ accessibilityManager.addHeading(`${textLabel}, Selected`);
62
+ break;
63
63
  }
64
64
  }
65
65
  }, [cellFocused, otherProps.state, textLabel]);
@@ -103,6 +103,8 @@ export function masterCellBuilder({
103
103
  wrapperRef,
104
104
  cellUUID,
105
105
  skipButtons,
106
+ hasFocusableInside,
107
+ entry: item,
106
108
  })
107
109
  );
108
110
 
@@ -8,6 +8,7 @@ import { isEmptyOrNil } from "@applicaster/zapp-react-native-utils/cellUtils";
8
8
  import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
9
9
  import { FocusableGroup } from "@applicaster/zapp-react-native-ui-components/Components/FocusableGroup";
10
10
  import { Focusable } from "@applicaster/zapp-react-native-ui-components/Components/Focusable";
11
+ import { useAccessibilityManager } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/hooks";
11
12
  import { Gutter } from "../Gutter";
12
13
  import Tab from "./Tab";
13
14
  import { getStyles } from "./styles";
@@ -28,11 +29,14 @@ const TabsComponent = ({
28
29
  style,
29
30
  selectedEntryIndex,
30
31
  setSelectedEntry,
32
+ accessibility,
31
33
  }: TabsProps & Partial<TabsSelectionContextType>) => {
32
34
  const configuration = useConfiguration();
33
35
  const config = applyFontConfig(configuration);
34
36
  const styles = useMemo(() => getStyles(config), [config]);
35
37
 
38
+ const accessibilityManager = useAccessibilityManager({});
39
+
36
40
  const {
37
41
  tab_bar_gutter: horizontalGutter,
38
42
  tab_bar_background_image: bgImage,
@@ -60,10 +64,20 @@ const TabsComponent = ({
60
64
  );
61
65
 
62
66
  const onListElementFocus = useCallback(
63
- (index) => {
67
+ (index, isSelected: boolean, item: ZappEntry) => {
68
+ if (isSelected) {
69
+ accessibilityManager.readText({
70
+ text: `${accessibility?.selectedHint} ${item.title}`,
71
+ });
72
+ } else {
73
+ accessibilityManager.readText({
74
+ text: `${accessibility?.hint} ${item.title}`,
75
+ });
76
+ }
77
+
64
78
  scrollToSelectedIndex(index, VIEW_POSITION);
65
79
  },
66
- [scrollToSelectedIndex]
80
+ [scrollToSelectedIndex, accessibility]
67
81
  );
68
82
 
69
83
  const renderItem = useCallback(
@@ -94,7 +108,7 @@ const TabsComponent = ({
94
108
  id={itemId}
95
109
  testID={itemId}
96
110
  preferredFocus={isSelected}
97
- onFocus={() => onListElementFocus(index)}
111
+ onFocus={() => onListElementFocus(index, isSelected, item)}
98
112
  onPress={() => setSelectedEntry && setSelectedEntry(item)}
99
113
  style={style}
100
114
  >
@@ -149,6 +163,9 @@ const TabsComponent = ({
149
163
  shouldUsePreferredFocus
150
164
  isWithMemory={false}
151
165
  nextFocusDown={parentFocus?.nextFocusDown}
166
+ onFocus={() => {
167
+ accessibilityManager.addHeading(accessibility?.announcement);
168
+ }}
152
169
  >
153
170
  <View style={tabs}>
154
171
  <ImageBackground
@@ -1,23 +1,11 @@
1
1
  import * as React from "react";
2
- import { StyleSheet, View, ViewStyle } from "react-native";
3
- import {
4
- Edge,
5
- SafeAreaView,
6
- useSafeAreaInsets,
7
- } from "react-native-safe-area-context";
2
+ import { View, ViewStyle } from "react-native";
3
+ import { Edge, SafeAreaView } from "react-native-safe-area-context";
8
4
  import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
9
5
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
10
6
  import { playerDimensionsHack } from "./utils";
11
- import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils";
12
- import {
13
- DimensionsT,
14
- Configuration,
15
- getEdges,
16
- getBaseDimensions,
17
- calculateAspectRatio,
18
- getPlayerDimensions,
19
- getContainerDimensions,
20
- } from "./playerWrapperUtils";
7
+ import { DimensionsT, Configuration, getEdges } from "./playerWrapperUtils";
8
+ import { defaultStyles, useStyle } from "./playerWrapperStyle";
21
9
 
22
10
  type Props = {
23
11
  entry: ZappEntry;
@@ -34,10 +22,6 @@ type Props = {
34
22
  playerContent: (styles: ViewStyle) => React.ReactNode;
35
23
  };
36
24
 
37
- const defaultStyles = StyleSheet.create({
38
- playerContainer: { position: "relative", alignSelf: "center", zIndex: 200 },
39
- });
40
-
41
25
  const PlayerWrapperComponent = (props: Props) => {
42
26
  const {
43
27
  entry,
@@ -51,51 +35,21 @@ const PlayerWrapperComponent = (props: Props) => {
51
35
  playerContent,
52
36
  } = props;
53
37
 
38
+ const styles = useStyle({
39
+ style,
40
+ inline,
41
+ isModal,
42
+ isTabletPortrait,
43
+ configuration,
44
+ pip,
45
+ });
46
+
54
47
  const isTablet = useIsTablet();
55
48
 
56
49
  const isInlineModal = inline && isModal;
57
50
 
58
- const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
59
-
60
- const tabletWidth = getTabletWidth(
61
- configuration.tablet_landscape_sidebar_width,
62
- style
63
- );
64
-
65
- const baseDimensions: DimensionsT = React.useMemo(
66
- () => getBaseDimensions(isInlineModal, isTabletLandscape, tabletWidth),
67
- [isInlineModal, isTabletLandscape, tabletWidth]
68
- );
69
-
70
- const insets = useSafeAreaInsets();
71
-
72
- const aspectRatio = React.useMemo(
73
- () => calculateAspectRatio(isInlineModal, pip, insets),
74
- // ignoring insets - only initial needed
75
- // eslint-disable-next-line react-hooks/exhaustive-deps
76
- [isInlineModal, pip]
77
- );
78
-
79
- const playerDimensions = React.useMemo(
80
- () => getPlayerDimensions(baseDimensions, aspectRatio),
81
- [baseDimensions, aspectRatio]
82
- );
83
-
84
- const containerDimensions: DimensionsT = React.useMemo(
85
- () => getContainerDimensions(baseDimensions, playerDimensions.aspectRatio),
86
- [baseDimensions, playerDimensions.aspectRatio]
87
- );
88
-
89
51
  const WrapperView = React.useMemo(() => (isTV() ? View : SafeAreaView), []);
90
52
 
91
- const childrenStyles = React.useMemo(
92
- () => ({
93
- ...playerDimensions,
94
- ...playerDimensionsHack,
95
- }),
96
- [playerDimensions]
97
- );
98
-
99
53
  return (
100
54
  <WrapperView
101
55
  edges={getEdges(isTablet, isInlineModal) as readonly Edge[]}
@@ -106,11 +60,11 @@ const PlayerWrapperComponent = (props: Props) => {
106
60
  style={[
107
61
  defaultStyles.playerContainer,
108
62
  playerDimensionsHack,
109
- containerDimensions,
63
+ styles.containerDimensions,
110
64
  containerStyle,
111
65
  ]}
112
66
  >
113
- {playerContent(childrenStyles)}
67
+ {playerContent(styles.childrenStyles)}
114
68
  </View>
115
69
  </WrapperView>
116
70
  );
@@ -33,8 +33,12 @@ const MODAL_SIZE_FOR_LANDSCAPE: Size = {
33
33
  height: "100%",
34
34
  };
35
35
 
36
+ const SAFE_AREA_BREAKING_API_VERSION = 35;
37
+
36
38
  const isOldAndroidDevice =
37
- isAndroidPlatform() && !isAndroidVersionAtLeast(35) && !isAndroidTablet();
39
+ isAndroidPlatform() &&
40
+ !isAndroidVersionAtLeast(SAFE_AREA_BREAKING_API_VERSION) &&
41
+ !isAndroidTablet();
38
42
 
39
43
  export const useModalSize = (): Size => {
40
44
  const frame = useSafeAreaFrame();
@@ -0,0 +1,70 @@
1
+ import * as React from "react";
2
+ import { StyleSheet, ViewStyle } from "react-native";
3
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
4
+ import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { playerDimensionsHack } from "./utils";
6
+ import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils";
7
+ import {
8
+ getBaseDimensions,
9
+ calculateAspectRatio,
10
+ getPlayerDimensions,
11
+ getContainerDimensions,
12
+ } from "./playerWrapperUtils";
13
+
14
+ export const defaultStyles = StyleSheet.create({
15
+ playerContainer: { position: "relative", alignSelf: "center", zIndex: 200 },
16
+ });
17
+
18
+ export const useStyle = ({
19
+ style,
20
+ inline,
21
+ isModal,
22
+ isTabletPortrait,
23
+ configuration,
24
+ pip,
25
+ }) => {
26
+ const isTablet = useIsTablet();
27
+
28
+ const isInlineModal = inline && isModal;
29
+
30
+ const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
31
+
32
+ const tabletWidth = getTabletWidth(
33
+ configuration.tablet_landscape_sidebar_width,
34
+ style
35
+ );
36
+
37
+ const baseDimensions: ViewStyle = React.useMemo(
38
+ () => getBaseDimensions(isInlineModal, isTabletLandscape, tabletWidth),
39
+ [isInlineModal, isTabletLandscape, tabletWidth]
40
+ );
41
+
42
+ const aspectRatio = React.useMemo(
43
+ () => calculateAspectRatio(isInlineModal, pip),
44
+ // ignoring insets - only initial needed
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ [isInlineModal, pip]
47
+ );
48
+
49
+ return React.useMemo(() => {
50
+ const playerDimensions: ViewStyle = getPlayerDimensions(
51
+ baseDimensions,
52
+ aspectRatio
53
+ );
54
+
55
+ const containerDimensions: ViewStyle = getContainerDimensions(
56
+ baseDimensions,
57
+ aspectRatio
58
+ );
59
+
60
+ const childrenStyles = {
61
+ ...playerDimensions,
62
+ ...playerDimensionsHack,
63
+ };
64
+
65
+ return StyleSheet.create({
66
+ containerDimensions,
67
+ childrenStyles,
68
+ });
69
+ }, [baseDimensions, aspectRatio]);
70
+ };
@@ -1,16 +1,6 @@
1
- import { Dimensions, Platform } from "react-native";
1
+ import { Dimensions, DimensionValue, Platform, ViewStyle } from "react-native";
2
2
  import { Edge } from "react-native-safe-area-context";
3
3
 
4
- import {
5
- isAndroidPlatform,
6
- isAndroidVersionAtLeast,
7
- } from "@applicaster/zapp-react-native-utils/reactUtils";
8
-
9
- const MIN_SUPPORTED_ANDROID_API = 34;
10
-
11
- export const isOldAndroidDevice =
12
- isAndroidPlatform() && !isAndroidVersionAtLeast(MIN_SUPPORTED_ANDROID_API);
13
-
14
4
  export type DimensionsT = {
15
5
  width: number | string;
16
6
  height: number | string | undefined;
@@ -23,6 +13,10 @@ export type Configuration = {
23
13
  tablet_landscape_player_container_background_color?: string;
24
14
  };
25
15
 
16
+ // This is safe, remembering screen dimensions once as they do not change during runtime
17
+ // TODO: consider sharing screen orientation as a shared function for the app
18
+ const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
19
+
26
20
  export const getWindowDimensions = () => {
27
21
  const { width, height } = Dimensions.get("window");
28
22
 
@@ -41,15 +35,11 @@ export const getMinWindowDimension = () => {
41
35
  return Math.min(width, height);
42
36
  };
43
37
 
44
- export const getScreenAspectRatio = (insets?: {
45
- top: number;
46
- bottom: number;
47
- }) => {
48
- const longEdge = getMaxWindowDimension();
49
- const shortEdge = getMinWindowDimension();
38
+ export const getScreenAspectRatio = () => {
39
+ const longEdge = Math.max(SCREEN_WIDTH, SCREEN_HEIGHT);
40
+ const shortEdge = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
50
41
 
51
- // subtract insets to get correct aspect ratio on devices with notches
52
- return longEdge / (shortEdge - ((insets?.top ?? 0) + (insets?.bottom ?? 0)));
42
+ return longEdge / shortEdge;
53
43
  };
54
44
 
55
45
  export const getEdges = (
@@ -70,35 +60,32 @@ export const getEdges = (
70
60
  export const getBaseDimensions = (
71
61
  isInlineModal: boolean,
72
62
  isTabletLandscape: boolean,
73
- tabletWidth: number | string
74
- ): DimensionsT => ({
63
+ tabletWidth: DimensionValue
64
+ ): ViewStyle => ({
75
65
  width: isInlineModal && isTabletLandscape ? tabletWidth : "100%",
76
66
  height: undefined,
77
67
  });
78
68
 
79
69
  export const calculateAspectRatio = (
80
70
  isInlineModal: boolean,
81
- pip?: boolean,
82
- insets?: { top: number; bottom: number }
71
+ pip?: boolean
83
72
  ): number => {
84
- return !isInlineModal && !pip
85
- ? getScreenAspectRatio(isOldAndroidDevice ? insets : undefined)
86
- : 16 / 9;
73
+ return !isInlineModal && !pip ? getScreenAspectRatio() : 16 / 9;
87
74
  };
88
75
 
89
76
  export const getPlayerDimensions = (
90
- baseDimensions: DimensionsT,
77
+ baseDimensions: ViewStyle,
91
78
  aspectRatio: number
92
- ): DimensionsT => ({
93
- ...baseDimensions,
79
+ ): ViewStyle => ({
80
+ ...(baseDimensions as any),
94
81
  width: baseDimensions.width,
95
82
  aspectRatio,
96
83
  });
97
84
 
98
85
  export const getContainerDimensions = (
99
- baseDimensions: DimensionsT,
100
- playerAspectRatio?: number
101
- ): DimensionsT => ({
86
+ baseDimensions: ViewStyle,
87
+ aspectRatio?: string | number
88
+ ): ViewStyle => ({
102
89
  ...baseDimensions,
103
- aspectRatio: playerAspectRatio,
90
+ aspectRatio,
104
91
  });
package/index.d.ts CHANGED
@@ -228,6 +228,12 @@ declare type TabsSelectionContextType = {
228
228
  selectedEntryIndex: number;
229
229
  };
230
230
 
231
+ declare type TabsAccessibility = {
232
+ announcement?: string;
233
+ selectedHint?: string;
234
+ hint?: string;
235
+ };
236
+
231
237
  declare type TabsProps = {
232
238
  entry: ZappEntry[];
233
239
  groupId: string;
@@ -235,6 +241,7 @@ declare type TabsProps = {
235
241
  focused?: boolean;
236
242
  parentFocus?: ParentFocus;
237
243
  style?: ReactViewStyle;
244
+ accessibility?: TabsAccessibility;
238
245
  };
239
246
 
240
247
  declare type TabContentProps = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "15.0.0-alpha.9361645236",
3
+ "version": "15.0.0-alpha.9667030680",
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": "15.0.0-alpha.9361645236",
32
- "@applicaster/zapp-react-native-bridge": "15.0.0-alpha.9361645236",
33
- "@applicaster/zapp-react-native-redux": "15.0.0-alpha.9361645236",
34
- "@applicaster/zapp-react-native-utils": "15.0.0-alpha.9361645236",
31
+ "@applicaster/applicaster-types": "15.0.0-alpha.9667030680",
32
+ "@applicaster/zapp-react-native-bridge": "15.0.0-alpha.9667030680",
33
+ "@applicaster/zapp-react-native-redux": "15.0.0-alpha.9667030680",
34
+ "@applicaster/zapp-react-native-utils": "15.0.0-alpha.9667030680",
35
35
  "promise": "^8.3.0",
36
36
  "url": "^0.11.0",
37
37
  "uuid": "^3.3.2"