@artsy/palette-mobile 14.0.21 → 14.0.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.
@@ -7,6 +7,7 @@ import { config } from "react-spring";
7
7
  import { animated, Spring } from "react-spring/renderprops-native";
8
8
  import styled from "styled-components/native";
9
9
  import { useColor } from "../../utils/hooks";
10
+ import { isTestEnvironment } from "../../utils/tests/isTestEnvironment";
10
11
  import { Box } from "../Box";
11
12
  import { Flex } from "../Flex/Flex";
12
13
  import { MeasuredView } from "../MeasuredView";
@@ -82,7 +83,7 @@ export const Button = ({ children, disabled, haptic, icon, iconPosition = "left"
82
83
  backgroundColor: springProps.backgroundColor,
83
84
  borderColor: springProps.borderColor,
84
85
  height: containerSize.height,
85
- }, children: _jsxs(Flex, { mx: containerSize.mx, children: [_jsxs(Flex, { height: "100%", flexDirection: "row", alignItems: "center", justifyContent: "center", children: [iconPosition === "left-start" && !!icon ? (_jsxs(Box, { position: "absolute", left: 0, children: [icon, _jsx(Spacer, { x: 0.5 })] })) : null, iconPosition === "left" && !!icon ? (_jsxs(_Fragment, { children: [icon, _jsx(Spacer, { x: 0.5 })] })) : null, !__TEST__ && longestText && (_jsx(MeasuredView, { setMeasuredState: setLongestTextMeasurements, children: _jsx(Text, { color: "red", style: textStyle, children: longestText ? longestText : children }) })), _jsx(AnimatedText, { style: [
86
+ }, children: _jsxs(Flex, { mx: containerSize.mx, children: [_jsxs(Flex, { height: "100%", flexDirection: "row", alignItems: "center", justifyContent: "center", children: [iconPosition === "left-start" && !!icon ? (_jsxs(Box, { position: "absolute", left: 0, children: [icon, _jsx(Spacer, { x: 0.5 })] })) : null, iconPosition === "left" && !!icon ? (_jsxs(_Fragment, { children: [icon, _jsx(Spacer, { x: 0.5 })] })) : null, !isTestEnvironment() && longestText && (_jsx(MeasuredView, { setMeasuredState: setLongestTextMeasurements, children: _jsx(Text, { color: "red", style: textStyle, children: longestText ? longestText : children }) })), _jsx(AnimatedText, { style: [
86
87
  {
87
88
  width: longestText ? Math.ceil(longestTextMeasurements.width) : "auto",
88
89
  color: springProps.textColor,
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { useCallback } from "react";
3
3
  import { useWindowDimensions } from "react-native";
4
+ import { isTestEnvironment } from "../../utils/tests/isTestEnvironment";
4
5
  import { Box } from "../Box";
5
6
  /**
6
7
  * A view that renders off-screen, measures the width and height of the view, and reports it back.
@@ -11,7 +12,7 @@ export const MeasuredView = ({ children, setMeasuredState, show }) => {
11
12
  const onLayout = useCallback((event) => {
12
13
  setMeasuredState(event.nativeEvent.layout);
13
14
  }, []);
14
- if (__TEST__)
15
+ if (isTestEnvironment())
15
16
  return null;
16
17
  return (_jsx(Box, { style: offscreenStyle, backgroundColor: "pink", onLayout: onLayout, accessibilityElementsHidden: true, children: children }));
17
18
  };
package/dist/setupJest.js CHANGED
@@ -1,5 +1,3 @@
1
- // @ts-expect-error
2
- global.__TEST__ = true;
3
1
  import "@testing-library/react-native/extend-expect";
4
2
  import mockSafeAreaContext from "react-native-safe-area-context/jest/mock";
5
3
  jest.mock("react-native-safe-area-context", () => mockSafeAreaContext);
@@ -1,12 +1,13 @@
1
1
  import { useContext } from "react";
2
2
  import { ThemeContext } from "styled-components/native";
3
3
  import { THEMES } from "../../tokens";
4
+ import { isTestEnvironment } from "../tests/isTestEnvironment";
4
5
  export const useTheme = () => {
5
6
  const maybeTheme = useContext(ThemeContext);
6
7
  // if we are not wrapped in `<Theme>`, if we dev, throw error.
7
8
  // if we are in prod, we will default to v2 to avoid a crash.
8
9
  // if we are wrapped, then all good.
9
- if ((__DEV__ || __TEST__) && maybeTheme === undefined) {
10
+ if ((__DEV__ || isTestEnvironment()) && maybeTheme === undefined) {
10
11
  console.error("You are trying to use the `Theme` context but you have not wrapped your component/screen with `<Theme>`. Please wrap and try again.");
11
12
  throw new Error("ThemeContext is not defined. Wrap your component with `<Theme>` and try again.");
12
13
  }
@@ -0,0 +1 @@
1
+ export declare const isTestEnvironment: () => boolean;
@@ -0,0 +1,3 @@
1
+ export const isTestEnvironment = () => {
2
+ return !!process.env.JEST_WORKER_ID;
3
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@artsy/palette-mobile",
3
- "version": "14.0.21",
3
+ "version": "14.0.22",
4
4
  "description": "Artsy's design system for React Native",
5
5
  "scripts": {
6
6
  "android": "RCT_METRO_PORT=8082 react-native run-android --port 8082 --terminal terminal",