@jobber/components-native 0.82.0 → 0.82.1-JOB-131123-08080a4.35

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.
@@ -1,4 +1,4 @@
1
- import { TextAlign, TextVariation, TruncateLength, TypographyProps } from "../Typography";
1
+ import { OnTextLayoutEvent, TextAlign, TextVariation, TruncateLength, TypographyProps } from "../Typography";
2
2
  import { TypographyUnsafeStyle } from "../Typography/Typography";
3
3
  export interface TextProps extends Pick<TypographyProps<"base">, "maxFontScaleSize" | "selectable"> {
4
4
  /**
@@ -66,7 +66,11 @@ export interface TextProps extends Pick<TypographyProps<"base">, "maxFontScaleSi
66
66
  * More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
67
67
  */
68
68
  readonly UNSAFE_style?: TypographyUnsafeStyle;
69
+ /**
70
+ * Callback that is called when the text is laid out.
71
+ */
72
+ readonly onTextLayout?: OnTextLayoutEvent;
69
73
  }
70
74
  export type TextLevel = "text" | "textSupporting";
71
75
  export declare const TEXT_MAX_SCALED_FONT_SIZES: Record<TextLevel, number>;
72
- export declare function Text({ level, variation, emphasis, allowFontScaling, adjustsFontSizeToFit, maxLines, align, children, reverseTheme, strikeThrough, italic, hideFromScreenReader, maxFontScaleSize, UNSAFE_style, underline, selectable, }: TextProps): JSX.Element;
76
+ export declare function Text({ level, variation, emphasis, allowFontScaling, adjustsFontSizeToFit, maxLines, align, children, reverseTheme, strikeThrough, italic, hideFromScreenReader, maxFontScaleSize, UNSAFE_style, underline, selectable, onTextLayout, }: TextProps): JSX.Element;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { StyleProp, TextProps, TextStyle } from "react-native";
2
+ import { NativeSyntheticEvent, StyleProp, TextLayoutEventData, TextProps, TextStyle } from "react-native";
3
3
  export interface TypographyProps<T extends FontFamily> extends Pick<TextProps, "selectable"> {
4
4
  /**
5
5
  * Text capitalization
@@ -86,12 +86,13 @@ export interface TypographyProps<T extends FontFamily> extends Pick<TextProps, "
86
86
  */
87
87
  readonly strikeThrough?: boolean;
88
88
  readonly UNSAFE_style?: TypographyUnsafeStyle;
89
+ readonly onTextLayout?: OnTextLayoutEvent;
89
90
  }
90
91
  export interface TypographyUnsafeStyle {
91
92
  textStyle?: StyleProp<TextStyle>;
92
93
  }
93
94
  export declare const Typography: React.MemoExoticComponent<typeof InternalTypography>;
94
- declare function InternalTypography<T extends FontFamily = "base">({ fontFamily, fontStyle, fontWeight, transform, color, align, size, children, maxLines, allowFontScaling, maxFontScaleSize, adjustsFontSizeToFit, lineHeight, letterSpacing, reverseTheme, hideFromScreenReader, accessibilityRole, strikeThrough, underline, UNSAFE_style, selectable, }: TypographyProps<T>): JSX.Element;
95
+ declare function InternalTypography<T extends FontFamily = "base">({ fontFamily, fontStyle, fontWeight, transform, color, align, size, children, maxLines, allowFontScaling, maxFontScaleSize, adjustsFontSizeToFit, lineHeight, letterSpacing, reverseTheme, hideFromScreenReader, accessibilityRole, strikeThrough, underline, UNSAFE_style, selectable, onTextLayout, }: TypographyProps<T>): JSX.Element;
95
96
  export type FontFamily = "base" | "display";
96
97
  export type FontStyle = "regular" | "italic";
97
98
  export type FontWeight = "regular" | "medium" | "bold" | "semiBold" | "extraBold" | "black";
@@ -108,4 +109,5 @@ export type LineHeight = "extravagant" | "jumbo" | "largest" | "larger" | "large
108
109
  export type LetterSpacing = "base" | "loose";
109
110
  export type TextAccessibilityRole = "text" | "header";
110
111
  export type TruncateLength = "single" | "small" | "base" | "large" | "extraLarge" | "unlimited";
112
+ export type OnTextLayoutEvent = (event: NativeSyntheticEvent<TextLayoutEventData>) => void;
111
113
  export {};
@@ -1,5 +1,5 @@
1
1
  export { Typography } from "./Typography";
2
- export type { FontFamily, FontStyle, FontWeight, BaseWeight, DisplayWeight, BaseStyle, DisplayStyle, TextColor, TextTransform, TextSize, TextAlign, LineHeight, LetterSpacing, TextAccessibilityRole, TextVariation, TypographyProps, TruncateLength, } from "./Typography";
2
+ export type { FontFamily, FontStyle, FontWeight, BaseWeight, DisplayWeight, BaseStyle, DisplayStyle, TextColor, TextTransform, TextSize, TextAlign, LineHeight, LetterSpacing, TextAccessibilityRole, TextVariation, TypographyProps, TruncateLength, OnTextLayoutEvent, } from "./Typography";
3
3
  export { getTypographyStyles, useTypographyStyles } from "./Typography.style";
4
4
  export { typographyStyles } from "./Typography.style";
5
5
  export { TypographyGestureDetector } from "./TypographyGestureDetector";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components-native",
3
- "version": "0.82.0",
3
+ "version": "0.82.1-JOB-131123-08080a4.35+08080a4f",
4
4
  "license": "MIT",
5
5
  "description": "React Native implementation of Atlantis",
6
6
  "repository": {
@@ -79,5 +79,5 @@
79
79
  "react-native-safe-area-context": "^5.4.0",
80
80
  "react-native-svg": ">=12.0.0"
81
81
  },
82
- "gitHead": "aeb1668b7f54843f828fbeda0c30bcc968cdfb64"
82
+ "gitHead": "08080a4f21868bdc10bb527a25f48da3ab225339"
83
83
  }
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { render } from "@testing-library/react-native";
2
+ import { fireEvent, render } from "@testing-library/react-native";
3
3
  import { Text } from ".";
4
4
  import { tokens } from "../utils/design";
5
5
 
@@ -168,3 +168,62 @@ describe("UNSAFE_style", () => {
168
168
  );
169
169
  });
170
170
  });
171
+
172
+ describe("onTextLayout", () => {
173
+ it("calls onTextLayout callback when text layout event occurs", () => {
174
+ const onTextLayoutMock = jest.fn();
175
+ const { getByRole } = render(
176
+ <Text onTextLayout={onTextLayoutMock}>Test Text</Text>,
177
+ );
178
+
179
+ const textElement = getByRole("text");
180
+ const mockEvent = {
181
+ nativeEvent: {
182
+ lines: [
183
+ {
184
+ text: "Test Text",
185
+ x: 0,
186
+ y: 0,
187
+ width: 100,
188
+ height: 20,
189
+ ascender: 15,
190
+ descender: -5,
191
+ capHeight: 14,
192
+ xHeight: 10,
193
+ },
194
+ ],
195
+ },
196
+ };
197
+ fireEvent(textElement, "onTextLayout", mockEvent);
198
+ expect(onTextLayoutMock).toHaveBeenCalledTimes(1);
199
+ expect(onTextLayoutMock).toHaveBeenCalledWith(mockEvent);
200
+ });
201
+
202
+ it("does not call onTextLayout when prop is not provided", () => {
203
+ const { getByRole } = render(<Text>Test Text</Text>);
204
+
205
+ const textElement = getByRole("text");
206
+ const mockEvent = {
207
+ nativeEvent: {
208
+ lines: [
209
+ {
210
+ text: "Test Text",
211
+ x: 0,
212
+ y: 0,
213
+ width: 100,
214
+ height: 20,
215
+ ascender: 15,
216
+ descender: -5,
217
+ capHeight: 14,
218
+ xHeight: 10,
219
+ },
220
+ ],
221
+ },
222
+ };
223
+
224
+ // This should not throw an error
225
+ expect(() => {
226
+ fireEvent(textElement, "onTextLayout", mockEvent);
227
+ }).not.toThrow();
228
+ });
229
+ });
package/src/Text/Text.tsx CHANGED
@@ -2,6 +2,7 @@ import React from "react";
2
2
  import {
3
3
  BaseWeight,
4
4
  LineHeight,
5
+ OnTextLayoutEvent,
5
6
  TextAccessibilityRole,
6
7
  TextAlign,
7
8
  TextSize,
@@ -93,6 +94,11 @@ export interface TextProps
93
94
  * More information in the [Customizing components Guide](https://atlantis.getjobber.com/guides/customizing-components).
94
95
  */
95
96
  readonly UNSAFE_style?: TypographyUnsafeStyle;
97
+
98
+ /**
99
+ * Callback that is called when the text is laid out.
100
+ */
101
+ readonly onTextLayout?: OnTextLayoutEvent;
96
102
  }
97
103
 
98
104
  export type TextLevel = "text" | "textSupporting";
@@ -136,6 +142,7 @@ export function Text({
136
142
  UNSAFE_style,
137
143
  underline,
138
144
  selectable,
145
+ onTextLayout,
139
146
  }: TextProps): JSX.Element {
140
147
  const accessibilityRole: TextAccessibilityRole = "text";
141
148
 
@@ -149,6 +156,7 @@ export function Text({
149
156
  maxFontScaleSize={maxFontScaleSize || TEXT_MAX_SCALED_FONT_SIZES[level]}
150
157
  selectable={selectable}
151
158
  underline={underline}
159
+ onTextLayout={onTextLayout}
152
160
  {...{
153
161
  ...levelStyles[level],
154
162
  allowFontScaling,
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { render } from "@testing-library/react-native";
2
+ import { fireEvent, render } from "@testing-library/react-native";
3
3
  import { I18nManager } from "react-native";
4
4
  import { Typography } from "./Typography";
5
5
 
@@ -251,3 +251,34 @@ describe("underline", () => {
251
251
  },
252
252
  );
253
253
  });
254
+
255
+ describe("onTextLayout", () => {
256
+ it("calls onTextLayout callback when text layout event occurs", () => {
257
+ const onTextLayoutMock = jest.fn();
258
+ const { getByRole } = render(
259
+ <Typography onTextLayout={onTextLayoutMock}>Test Text</Typography>,
260
+ );
261
+
262
+ const textElement = getByRole("text");
263
+ const mockEvent = {
264
+ nativeEvent: {
265
+ lines: [
266
+ {
267
+ text: "Test Text",
268
+ x: 0,
269
+ y: 0,
270
+ width: 100,
271
+ height: 20,
272
+ ascender: 15,
273
+ descender: -5,
274
+ capHeight: 14,
275
+ xHeight: 10,
276
+ },
277
+ ],
278
+ },
279
+ };
280
+ fireEvent(textElement, "onTextLayout", mockEvent);
281
+ expect(onTextLayoutMock).toHaveBeenCalledTimes(1);
282
+ expect(onTextLayoutMock).toHaveBeenCalledWith(mockEvent);
283
+ });
284
+ });
@@ -2,9 +2,11 @@ import React from "react";
2
2
  import {
3
3
  AccessibilityProps,
4
4
  I18nManager,
5
+ NativeSyntheticEvent,
5
6
  StyleProp,
6
7
  StyleSheet,
7
8
  Text,
9
+ TextLayoutEventData,
8
10
  TextProps,
9
11
  TextStyle,
10
12
  ViewStyle,
@@ -120,6 +122,8 @@ export interface TypographyProps<T extends FontFamily>
120
122
  readonly strikeThrough?: boolean;
121
123
 
122
124
  readonly UNSAFE_style?: TypographyUnsafeStyle;
125
+
126
+ readonly onTextLayout?: OnTextLayoutEvent;
123
127
  }
124
128
 
125
129
  const maxNumberOfLines = {
@@ -160,6 +164,7 @@ function InternalTypography<T extends FontFamily = "base">({
160
164
  underline,
161
165
  UNSAFE_style,
162
166
  selectable = true,
167
+ onTextLayout,
163
168
  }: TypographyProps<T>): JSX.Element {
164
169
  const styles = useTypographyStyles();
165
170
  const sizeAndHeight = getSizeAndHeightStyle(size, styles, lineHeight);
@@ -217,6 +222,7 @@ function InternalTypography<T extends FontFamily = "base">({
217
222
  )}
218
223
  selectable={selectable}
219
224
  selectionColor={tokens["color-brand--highlight"]}
225
+ onTextLayout={onTextLayout}
220
226
  >
221
227
  {text}
222
228
  </Text>
@@ -477,3 +483,7 @@ export type TruncateLength =
477
483
  | "large"
478
484
  | "extraLarge"
479
485
  | "unlimited";
486
+
487
+ export type OnTextLayoutEvent = (
488
+ event: NativeSyntheticEvent<TextLayoutEventData>,
489
+ ) => void;
@@ -17,6 +17,7 @@ export type {
17
17
  TextVariation,
18
18
  TypographyProps,
19
19
  TruncateLength,
20
+ OnTextLayoutEvent,
20
21
  } from "./Typography";
21
22
  export { getTypographyStyles, useTypographyStyles } from "./Typography.style";
22
23
  export { typographyStyles } from "./Typography.style";