@tamagui/image 1.12.1 → 1.13.0

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.
package/dist/cjs/Image.js CHANGED
@@ -34,12 +34,23 @@ const StyledImage = (0, import_core.styled)(import_react_native.Image, {
34
34
  source: { uri: "" },
35
35
  zIndex: 1
36
36
  });
37
+ let hasWarned = false;
37
38
  const Image = StyledImage.extractable(
38
39
  (0, import_react.forwardRef)((inProps, ref) => {
39
40
  const props = (0, import_core.useMediaPropsActive)(inProps);
40
- const { src, ...rest } = props;
41
- const source = typeof src === "string" ? { uri: src, ...import_core.isWeb && { width: props.width, height: props.height } } : src;
42
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StyledImage, { ref, source, ...rest });
41
+ const { src, source, ...rest } = props;
42
+ if (process.env.NODE_ENV === "development") {
43
+ if (typeof src === "string" && (typeof props.width === "number" || typeof props.height === "number")) {
44
+ if (!hasWarned) {
45
+ hasWarned = true;
46
+ console.warn(
47
+ `React Native expects a numerical width/height. If you want to use a percent use the "source" prop instead.`
48
+ );
49
+ }
50
+ }
51
+ }
52
+ const finalSource = typeof src === "string" ? { uri: src, ...import_core.isWeb && { width: props.width, height: props.height } } : source ?? src;
53
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StyledImage, { ref, source: finalSource, ...rest });
43
54
  })
44
55
  );
45
56
  Image.getSize = import_react_native.Image.getSize;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Image.tsx"],
4
- "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n StackProps,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<\n StyledImageProps,\n 'source' | 'width' | 'height' | 'style' | 'onLayout'\n> & {\n width: number\n height: number\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, ...rest } = props\n const source =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={source} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2DW;AA3DX,kBAQO;AACP,mBAAkC;AAClC,0BAAiC;AAAA,IAEjC,8BAAiB;AAAA,EACf,OAAO,oBAAAA;AACT,CAAC;AAED,MAAM,kBAAc,oBAAO,oBAAAA,OAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA4BM,MAAM,QAAQ,YAAY;AAAA,MAC/B,yBAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,YAAQ,iCAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,GAAG,KAAK,IAAI;AACzB,UAAM,SACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,qBAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE;AAGN,WAAO,4CAAC,eAAY,KAAU,QAAiB,GAAI,MAAc;AAAA,EACnE,CAAC;AACH;AAEA,MAAM,UAAU,oBAAAA,MAAQ;AACxB,MAAM,qBAAqB,oBAAAA,MAAQ;AACnC,MAAM,WAAW,oBAAAA,MAAQ;AACzB,MAAM,uBAAuB,oBAAAA,MAAQ;AACrC,MAAM,gBAAgB,oBAAAA,MAAQ;AAC9B,MAAM,aAAa,oBAAAA,MAAQ;",
4
+ "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n SizeTokens,\n StackProps,\n ThemeValueFallback,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<StyledImageProps, 'width' | 'height' | 'style' | 'onLayout'> & {\n width: string | number | SizeTokens | ThemeValueFallback\n height: string | number | SizeTokens | ThemeValueFallback\n\n /**\n * @deprecated use `source` instead to disambiguate width/height style from width/height of the actual image\n */\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nlet hasWarned = false\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, source, ...rest } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (\n typeof src === 'string' &&\n (typeof props.width === 'number' || typeof props.height === 'number')\n ) {\n if (!hasWarned) {\n hasWarned = true\n console.warn(\n `React Native expects a numerical width/height. If you want to use a percent use the \"source\" prop instead.`\n )\n }\n }\n }\n\n const finalSource =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : source ?? src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={finalSource} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+EW;AA/EX,kBAUO;AACP,mBAAkC;AAClC,0BAAiC;AAAA,IAEjC,8BAAiB;AAAA,EACf,OAAO,oBAAAA;AACT,CAAC;AAED,MAAM,kBAAc,oBAAO,oBAAAA,OAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA6BD,IAAI,YAAY;AAET,MAAM,QAAQ,YAAY;AAAA,MAC/B,yBAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,YAAQ,iCAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,QAAQ,GAAG,KAAK,IAAI;AAEjC,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UACE,OAAO,QAAQ,aACd,OAAO,MAAM,UAAU,YAAY,OAAO,MAAM,WAAW,WAC5D;AACA,YAAI,CAAC,WAAW;AACd,sBAAY;AACZ,kBAAQ;AAAA,YACN;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,cACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,qBAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE,UAAU;AAGhB,WAAO,4CAAC,eAAY,KAAU,QAAQ,aAAc,GAAI,MAAc;AAAA,EACxE,CAAC;AACH;AAEA,MAAM,UAAU,oBAAAA,MAAQ;AACxB,MAAM,qBAAqB,oBAAAA,MAAQ;AACnC,MAAM,WAAW,oBAAAA,MAAQ;AACzB,MAAM,uBAAuB,oBAAAA,MAAQ;AACrC,MAAM,gBAAgB,oBAAAA,MAAQ;AAC9B,MAAM,aAAa,oBAAAA,MAAQ;",
6
6
  "names": ["RNImage"]
7
7
  }
package/dist/esm/Image.js CHANGED
@@ -16,12 +16,23 @@ const StyledImage = styled(RNImage, {
16
16
  source: { uri: "" },
17
17
  zIndex: 1
18
18
  });
19
+ let hasWarned = false;
19
20
  const Image = StyledImage.extractable(
20
21
  forwardRef((inProps, ref) => {
21
22
  const props = useMediaPropsActive(inProps);
22
- const { src, ...rest } = props;
23
- const source = typeof src === "string" ? { uri: src, ...isWeb && { width: props.width, height: props.height } } : src;
24
- return /* @__PURE__ */ jsx(StyledImage, { ref, source, ...rest });
23
+ const { src, source, ...rest } = props;
24
+ if (process.env.NODE_ENV === "development") {
25
+ if (typeof src === "string" && (typeof props.width === "number" || typeof props.height === "number")) {
26
+ if (!hasWarned) {
27
+ hasWarned = true;
28
+ console.warn(
29
+ `React Native expects a numerical width/height. If you want to use a percent use the "source" prop instead.`
30
+ );
31
+ }
32
+ }
33
+ }
34
+ const finalSource = typeof src === "string" ? { uri: src, ...isWeb && { width: props.width, height: props.height } } : source ?? src;
35
+ return /* @__PURE__ */ jsx(StyledImage, { ref, source: finalSource, ...rest });
25
36
  })
26
37
  );
27
38
  Image.getSize = RNImage.getSize;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Image.tsx"],
4
- "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n StackProps,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<\n StyledImageProps,\n 'source' | 'width' | 'height' | 'style' | 'onLayout'\n> & {\n width: number\n height: number\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, ...rest } = props\n const source =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={source} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
- "mappings": "AA2DW;AA3DX;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,kBAAkB;AAClC,SAAS,SAAS,eAAe;AAEjC,iBAAiB;AAAA,EACf,OAAO;AACT,CAAC;AAED,MAAM,cAAc,OAAO,SAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA4BM,MAAM,QAAQ,YAAY;AAAA,EAC/B,WAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,QAAQ,oBAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,GAAG,KAAK,IAAI;AACzB,UAAM,SACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,SAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE;AAGN,WAAO,oBAAC,eAAY,KAAU,QAAiB,GAAI,MAAc;AAAA,EACnE,CAAC;AACH;AAEA,MAAM,UAAU,QAAQ;AACxB,MAAM,qBAAqB,QAAQ;AACnC,MAAM,WAAW,QAAQ;AACzB,MAAM,uBAAuB,QAAQ;AACrC,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;",
4
+ "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n SizeTokens,\n StackProps,\n ThemeValueFallback,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<StyledImageProps, 'width' | 'height' | 'style' | 'onLayout'> & {\n width: string | number | SizeTokens | ThemeValueFallback\n height: string | number | SizeTokens | ThemeValueFallback\n\n /**\n * @deprecated use `source` instead to disambiguate width/height style from width/height of the actual image\n */\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nlet hasWarned = false\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, source, ...rest } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (\n typeof src === 'string' &&\n (typeof props.width === 'number' || typeof props.height === 'number')\n ) {\n if (!hasWarned) {\n hasWarned = true\n console.warn(\n `React Native expects a numerical width/height. If you want to use a percent use the \"source\" prop instead.`\n )\n }\n }\n }\n\n const finalSource =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : source ?? src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={finalSource} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
+ "mappings": "AA+EW;AA/EX;AAAA,EAME;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,kBAAkB;AAClC,SAAS,SAAS,eAAe;AAEjC,iBAAiB;AAAA,EACf,OAAO;AACT,CAAC;AAED,MAAM,cAAc,OAAO,SAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA6BD,IAAI,YAAY;AAET,MAAM,QAAQ,YAAY;AAAA,EAC/B,WAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,QAAQ,oBAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,QAAQ,GAAG,KAAK,IAAI;AAEjC,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UACE,OAAO,QAAQ,aACd,OAAO,MAAM,UAAU,YAAY,OAAO,MAAM,WAAW,WAC5D;AACA,YAAI,CAAC,WAAW;AACd,sBAAY;AACZ,kBAAQ;AAAA,YACN;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,cACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,SAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE,UAAU;AAGhB,WAAO,oBAAC,eAAY,KAAU,QAAQ,aAAc,GAAI,MAAc;AAAA,EACxE,CAAC;AACH;AAEA,MAAM,UAAU,QAAQ;AACxB,MAAM,qBAAqB,QAAQ;AACnC,MAAM,WAAW,QAAQ;AACzB,MAAM,uBAAuB,QAAQ;AACrC,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;",
6
6
  "names": []
7
7
  }
@@ -16,12 +16,23 @@ const StyledImage = styled(RNImage, {
16
16
  source: { uri: "" },
17
17
  zIndex: 1
18
18
  });
19
+ let hasWarned = false;
19
20
  const Image = StyledImage.extractable(
20
21
  forwardRef((inProps, ref) => {
21
22
  const props = useMediaPropsActive(inProps);
22
- const { src, ...rest } = props;
23
- const source = typeof src === "string" ? { uri: src, ...isWeb && { width: props.width, height: props.height } } : src;
24
- return /* @__PURE__ */ jsx(StyledImage, { ref, source, ...rest });
23
+ const { src, source, ...rest } = props;
24
+ if (process.env.NODE_ENV === "development") {
25
+ if (typeof src === "string" && (typeof props.width === "number" || typeof props.height === "number")) {
26
+ if (!hasWarned) {
27
+ hasWarned = true;
28
+ console.warn(
29
+ `React Native expects a numerical width/height. If you want to use a percent use the "source" prop instead.`
30
+ );
31
+ }
32
+ }
33
+ }
34
+ const finalSource = typeof src === "string" ? { uri: src, ...isWeb && { width: props.width, height: props.height } } : source ?? src;
35
+ return /* @__PURE__ */ jsx(StyledImage, { ref, source: finalSource, ...rest });
25
36
  })
26
37
  );
27
38
  Image.getSize = RNImage.getSize;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Image.tsx"],
4
- "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n StackProps,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<\n StyledImageProps,\n 'source' | 'width' | 'height' | 'style' | 'onLayout'\n> & {\n width: number\n height: number\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, ...rest } = props\n const source =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={source} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
- "mappings": "AA2DW;AA3DX;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,kBAAkB;AAClC,SAAS,SAAS,eAAe;AAEjC,iBAAiB;AAAA,EACf,OAAO;AACT,CAAC;AAED,MAAM,cAAc,OAAO,SAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA4BM,MAAM,QAAQ,YAAY;AAAA,EAC/B,WAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,QAAQ,oBAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,GAAG,KAAK,IAAI;AACzB,UAAM,SACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,SAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE;AAGN,WAAO,oBAAC,eAAY,KAAU,QAAiB,GAAI,MAAc;AAAA,EACnE,CAAC;AACH;AAEA,MAAM,UAAU,QAAQ;AACxB,MAAM,qBAAqB,QAAQ;AACnC,MAAM,WAAW,QAAQ;AACzB,MAAM,uBAAuB,QAAQ;AACrC,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;",
4
+ "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n SizeTokens,\n StackProps,\n ThemeValueFallback,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<StyledImageProps, 'width' | 'height' | 'style' | 'onLayout'> & {\n width: string | number | SizeTokens | ThemeValueFallback\n height: string | number | SizeTokens | ThemeValueFallback\n\n /**\n * @deprecated use `source` instead to disambiguate width/height style from width/height of the actual image\n */\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nlet hasWarned = false\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, source, ...rest } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (\n typeof src === 'string' &&\n (typeof props.width === 'number' || typeof props.height === 'number')\n ) {\n if (!hasWarned) {\n hasWarned = true\n console.warn(\n `React Native expects a numerical width/height. If you want to use a percent use the \"source\" prop instead.`\n )\n }\n }\n }\n\n const finalSource =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : source ?? src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={finalSource} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
+ "mappings": "AA+EW;AA/EX;AAAA,EAME;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,kBAAkB;AAClC,SAAS,SAAS,eAAe;AAEjC,iBAAiB;AAAA,EACf,OAAO;AACT,CAAC;AAED,MAAM,cAAc,OAAO,SAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA6BD,IAAI,YAAY;AAET,MAAM,QAAQ,YAAY;AAAA,EAC/B,WAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,QAAQ,oBAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,QAAQ,GAAG,KAAK,IAAI;AAEjC,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UACE,OAAO,QAAQ,aACd,OAAO,MAAM,UAAU,YAAY,OAAO,MAAM,WAAW,WAC5D;AACA,YAAI,CAAC,WAAW;AACd,sBAAY;AACZ,kBAAQ;AAAA,YACN;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,cACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,SAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE,UAAU;AAGhB,WAAO,oBAAC,eAAY,KAAU,QAAQ,aAAc,GAAI,MAAc;AAAA,EACxE,CAAC;AACH;AAEA,MAAM,UAAU,QAAQ;AACxB,MAAM,qBAAqB,QAAQ;AACnC,MAAM,WAAW,QAAQ;AACzB,MAAM,uBAAuB,QAAQ;AACrC,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;",
6
6
  "names": []
7
7
  }
package/dist/jsx/Image.js CHANGED
@@ -15,12 +15,23 @@ const StyledImage = styled(RNImage, {
15
15
  source: { uri: "" },
16
16
  zIndex: 1
17
17
  });
18
+ let hasWarned = false;
18
19
  const Image = StyledImage.extractable(
19
20
  forwardRef((inProps, ref) => {
20
21
  const props = useMediaPropsActive(inProps);
21
- const { src, ...rest } = props;
22
- const source = typeof src === "string" ? { uri: src, ...isWeb && { width: props.width, height: props.height } } : src;
23
- return <StyledImage ref={ref} source={source} {...rest} />;
22
+ const { src, source, ...rest } = props;
23
+ if (process.env.NODE_ENV === "development") {
24
+ if (typeof src === "string" && (typeof props.width === "number" || typeof props.height === "number")) {
25
+ if (!hasWarned) {
26
+ hasWarned = true;
27
+ console.warn(
28
+ `React Native expects a numerical width/height. If you want to use a percent use the "source" prop instead.`
29
+ );
30
+ }
31
+ }
32
+ }
33
+ const finalSource = typeof src === "string" ? { uri: src, ...isWeb && { width: props.width, height: props.height } } : source ?? src;
34
+ return <StyledImage ref={ref} source={finalSource} {...rest} />;
24
35
  })
25
36
  );
26
37
  Image.getSize = RNImage.getSize;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Image.tsx"],
4
- "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n StackProps,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<\n StyledImageProps,\n 'source' | 'width' | 'height' | 'style' | 'onLayout'\n> & {\n width: number\n height: number\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, ...rest } = props\n const source =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={source} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
- "mappings": "AAAA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,kBAAkB;AAClC,SAAS,SAAS,eAAe;AAEjC,iBAAiB;AAAA,EACf,OAAO;AACT,CAAC;AAED,MAAM,cAAc,OAAO,SAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA4BM,MAAM,QAAQ,YAAY;AAAA,EAC/B,WAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,QAAQ,oBAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,GAAG,KAAK,IAAI;AACzB,UAAM,SACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,SAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE;AAGN,WAAO,CAAC,YAAY,KAAK,KAAK,QAAQ,YAAa,MAAc;AAAA,EACnE,CAAC;AACH;AAEA,MAAM,UAAU,QAAQ;AACxB,MAAM,qBAAqB,QAAQ;AACnC,MAAM,WAAW,QAAQ;AACzB,MAAM,uBAAuB,QAAQ;AACrC,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;",
4
+ "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n SizeTokens,\n StackProps,\n ThemeValueFallback,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<StyledImageProps, 'width' | 'height' | 'style' | 'onLayout'> & {\n width: string | number | SizeTokens | ThemeValueFallback\n height: string | number | SizeTokens | ThemeValueFallback\n\n /**\n * @deprecated use `source` instead to disambiguate width/height style from width/height of the actual image\n */\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nlet hasWarned = false\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, source, ...rest } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (\n typeof src === 'string' &&\n (typeof props.width === 'number' || typeof props.height === 'number')\n ) {\n if (!hasWarned) {\n hasWarned = true\n console.warn(\n `React Native expects a numerical width/height. If you want to use a percent use the \"source\" prop instead.`\n )\n }\n }\n }\n\n const finalSource =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : source ?? src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={finalSource} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
+ "mappings": "AAAA;AAAA,EAME;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,kBAAkB;AAClC,SAAS,SAAS,eAAe;AAEjC,iBAAiB;AAAA,EACf,OAAO;AACT,CAAC;AAED,MAAM,cAAc,OAAO,SAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA6BD,IAAI,YAAY;AAET,MAAM,QAAQ,YAAY;AAAA,EAC/B,WAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,QAAQ,oBAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,QAAQ,GAAG,KAAK,IAAI;AAEjC,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UACE,OAAO,QAAQ,aACd,OAAO,MAAM,UAAU,YAAY,OAAO,MAAM,WAAW,WAC5D;AACA,YAAI,CAAC,WAAW;AACd,sBAAY;AACZ,kBAAQ;AAAA,YACN;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,cACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,SAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE,UAAU;AAGhB,WAAO,CAAC,YAAY,KAAK,KAAK,QAAQ,iBAAkB,MAAc;AAAA,EACxE,CAAC;AACH;AAEA,MAAM,UAAU,QAAQ;AACxB,MAAM,qBAAqB,QAAQ;AACnC,MAAM,WAAW,QAAQ;AACzB,MAAM,uBAAuB,QAAQ;AACrC,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;",
6
6
  "names": []
7
7
  }
@@ -15,12 +15,23 @@ const StyledImage = styled(RNImage, {
15
15
  source: { uri: "" },
16
16
  zIndex: 1
17
17
  });
18
+ let hasWarned = false;
18
19
  const Image = StyledImage.extractable(
19
20
  forwardRef((inProps, ref) => {
20
21
  const props = useMediaPropsActive(inProps);
21
- const { src, ...rest } = props;
22
- const source = typeof src === "string" ? { uri: src, ...isWeb && { width: props.width, height: props.height } } : src;
23
- return <StyledImage ref={ref} source={source} {...rest} />;
22
+ const { src, source, ...rest } = props;
23
+ if (process.env.NODE_ENV === "development") {
24
+ if (typeof src === "string" && (typeof props.width === "number" || typeof props.height === "number")) {
25
+ if (!hasWarned) {
26
+ hasWarned = true;
27
+ console.warn(
28
+ `React Native expects a numerical width/height. If you want to use a percent use the "source" prop instead.`
29
+ );
30
+ }
31
+ }
32
+ }
33
+ const finalSource = typeof src === "string" ? { uri: src, ...isWeb && { width: props.width, height: props.height } } : source ?? src;
34
+ return <StyledImage ref={ref} source={finalSource} {...rest} />;
24
35
  })
25
36
  );
26
37
  Image.getSize = RNImage.getSize;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/Image.tsx"],
4
- "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n StackProps,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<\n StyledImageProps,\n 'source' | 'width' | 'height' | 'style' | 'onLayout'\n> & {\n width: number\n height: number\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, ...rest } = props\n const source =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={source} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
- "mappings": "AAAA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,kBAAkB;AAClC,SAAS,SAAS,eAAe;AAEjC,iBAAiB;AAAA,EACf,OAAO;AACT,CAAC;AAED,MAAM,cAAc,OAAO,SAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA4BM,MAAM,QAAQ,YAAY;AAAA,EAC/B,WAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,QAAQ,oBAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,GAAG,KAAK,IAAI;AACzB,UAAM,SACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,SAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE;AAGN,WAAO,CAAC,YAAY,KAAK,KAAK,QAAQ,YAAa,MAAc;AAAA,EACnE,CAAC;AACH;AAEA,MAAM,UAAU,QAAQ;AACxB,MAAM,qBAAqB,QAAQ;AACnC,MAAM,WAAW,QAAQ;AACzB,MAAM,uBAAuB,QAAQ;AACrC,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;",
4
+ "sourcesContent": ["import {\n GetProps,\n RadiusTokens,\n SizeTokens,\n StackProps,\n ThemeValueFallback,\n isWeb,\n setupReactNative,\n styled,\n useMediaPropsActive,\n} from '@tamagui/core'\nimport React, { forwardRef } from 'react'\nimport { Image as RNImage } from 'react-native'\n\nsetupReactNative({\n Image: RNImage,\n})\n\nconst StyledImage = styled(RNImage, {\n name: 'Image',\n position: 'relative',\n source: { uri: '' },\n zIndex: 1,\n})\n\ntype StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {\n borderRadius?: RadiusTokens\n}\n\ntype BaseProps = Omit<StyledImageProps, 'width' | 'height' | 'style' | 'onLayout'> & {\n width: string | number | SizeTokens | ThemeValueFallback\n height: string | number | SizeTokens | ThemeValueFallback\n\n /**\n * @deprecated use `source` instead to disambiguate width/height style from width/height of the actual image\n */\n src: string | StyledImageProps['source']\n}\n\nexport type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>\n\ntype RNImageType = typeof RNImage\n\ntype ImageType = React.FC<ImageProps> & {\n getSize: RNImageType['getSize']\n getSizeWithHeaders: RNImageType['getSizeWithHeaders']\n prefetch: RNImageType['prefetch']\n prefetchWithMetadata: RNImageType['prefetchWithMetadata']\n abortPrefetch: RNImageType['abortPrefetch']\n queryCache: RNImageType['queryCache']\n}\n\nlet hasWarned = false\n\nexport const Image = StyledImage.extractable(\n forwardRef((inProps: ImageProps, ref) => {\n const props = useMediaPropsActive(inProps)\n const { src, source, ...rest } = props\n\n if (process.env.NODE_ENV === 'development') {\n if (\n typeof src === 'string' &&\n (typeof props.width === 'number' || typeof props.height === 'number')\n ) {\n if (!hasWarned) {\n hasWarned = true\n console.warn(\n `React Native expects a numerical width/height. If you want to use a percent use the \"source\" prop instead.`\n )\n }\n }\n }\n\n const finalSource =\n typeof src === 'string'\n ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }\n : source ?? src\n\n // must set defaultSource to allow SSR, default it to the same as src\n return <StyledImage ref={ref} source={finalSource} {...(rest as any)} />\n })\n) as any as ImageType\n\nImage.getSize = RNImage.getSize\nImage.getSizeWithHeaders = RNImage.getSizeWithHeaders\nImage.prefetch = RNImage.prefetch\nImage.prefetchWithMetadata = RNImage.prefetchWithMetadata\nImage.abortPrefetch = RNImage.abortPrefetch\nImage.queryCache = RNImage.queryCache\n"],
5
+ "mappings": "AAAA;AAAA,EAME;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,kBAAkB;AAClC,SAAS,SAAS,eAAe;AAEjC,iBAAiB;AAAA,EACf,OAAO;AACT,CAAC;AAED,MAAM,cAAc,OAAO,SAAS;AAAA,EAClC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,QAAQ,EAAE,KAAK,GAAG;AAAA,EAClB,QAAQ;AACV,CAAC;AA6BD,IAAI,YAAY;AAET,MAAM,QAAQ,YAAY;AAAA,EAC/B,WAAW,CAAC,SAAqB,QAAQ;AACvC,UAAM,QAAQ,oBAAoB,OAAO;AACzC,UAAM,EAAE,KAAK,QAAQ,GAAG,KAAK,IAAI;AAEjC,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,UACE,OAAO,QAAQ,aACd,OAAO,MAAM,UAAU,YAAY,OAAO,MAAM,WAAW,WAC5D;AACA,YAAI,CAAC,WAAW;AACd,sBAAY;AACZ,kBAAQ;AAAA,YACN;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,UAAM,cACJ,OAAO,QAAQ,WACX,EAAE,KAAK,KAAK,GAAI,SAAS,EAAE,OAAO,MAAM,OAAO,QAAQ,MAAM,OAAO,EAAG,IACvE,UAAU;AAGhB,WAAO,CAAC,YAAY,KAAK,KAAK,QAAQ,iBAAkB,MAAc;AAAA,EACxE,CAAC;AACH;AAEA,MAAM,UAAU,QAAQ;AACxB,MAAM,qBAAqB,QAAQ;AACnC,MAAM,WAAW,QAAQ;AACzB,MAAM,uBAAuB,QAAQ;AACrC,MAAM,gBAAgB,QAAQ;AAC9B,MAAM,aAAa,QAAQ;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/image",
3
- "version": "1.12.1",
3
+ "version": "1.13.0",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -23,14 +23,14 @@
23
23
  "clean:build": "tamagui-build clean:build"
24
24
  },
25
25
  "dependencies": {
26
- "@tamagui/core": "1.12.1"
26
+ "@tamagui/core": "1.13.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": "*",
30
30
  "react-native": "*"
31
31
  },
32
32
  "devDependencies": {
33
- "@tamagui/build": "1.12.1",
33
+ "@tamagui/build": "1.13.0",
34
34
  "react": "^18.2.0",
35
35
  "react-native": "^0.71.4"
36
36
  },
package/src/Image.tsx CHANGED
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  GetProps,
3
3
  RadiusTokens,
4
+ SizeTokens,
4
5
  StackProps,
6
+ ThemeValueFallback,
5
7
  isWeb,
6
8
  setupReactNative,
7
9
  styled,
@@ -25,12 +27,13 @@ type StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {
25
27
  borderRadius?: RadiusTokens
26
28
  }
27
29
 
28
- type BaseProps = Omit<
29
- StyledImageProps,
30
- 'source' | 'width' | 'height' | 'style' | 'onLayout'
31
- > & {
32
- width: number
33
- height: number
30
+ type BaseProps = Omit<StyledImageProps, 'width' | 'height' | 'style' | 'onLayout'> & {
31
+ width: string | number | SizeTokens | ThemeValueFallback
32
+ height: string | number | SizeTokens | ThemeValueFallback
33
+
34
+ /**
35
+ * @deprecated use `source` instead to disambiguate width/height style from width/height of the actual image
36
+ */
34
37
  src: string | StyledImageProps['source']
35
38
  }
36
39
 
@@ -47,17 +50,34 @@ type ImageType = React.FC<ImageProps> & {
47
50
  queryCache: RNImageType['queryCache']
48
51
  }
49
52
 
53
+ let hasWarned = false
54
+
50
55
  export const Image = StyledImage.extractable(
51
56
  forwardRef((inProps: ImageProps, ref) => {
52
57
  const props = useMediaPropsActive(inProps)
53
- const { src, ...rest } = props
54
- const source =
58
+ const { src, source, ...rest } = props
59
+
60
+ if (process.env.NODE_ENV === 'development') {
61
+ if (
62
+ typeof src === 'string' &&
63
+ (typeof props.width === 'number' || typeof props.height === 'number')
64
+ ) {
65
+ if (!hasWarned) {
66
+ hasWarned = true
67
+ console.warn(
68
+ `React Native expects a numerical width/height. If you want to use a percent use the "source" prop instead.`
69
+ )
70
+ }
71
+ }
72
+ }
73
+
74
+ const finalSource =
55
75
  typeof src === 'string'
56
76
  ? { uri: src, ...(isWeb && { width: props.width, height: props.height }) }
57
- : src
77
+ : source ?? src
58
78
 
59
79
  // must set defaultSource to allow SSR, default it to the same as src
60
- return <StyledImage ref={ref} source={source} {...(rest as any)} />
80
+ return <StyledImage ref={ref} source={finalSource} {...(rest as any)} />
61
81
  })
62
82
  ) as any as ImageType
63
83
 
package/types/Image.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { GetProps, RadiusTokens, StackProps } from '@tamagui/core';
1
+ import { GetProps, RadiusTokens, SizeTokens, StackProps, ThemeValueFallback } from '@tamagui/core';
2
2
  import React from 'react';
3
3
  import { Image as RNImage } from 'react-native';
4
4
  declare const StyledImage: import("@tamagui/core").TamaguiComponent<(import("react-native").ImageProps & Omit<StackProps, keyof import("react-native").ImageProps>) | (import("react-native").ImageProps & Omit<StackProps, keyof import("react-native").ImageProps> & Omit<{}, string | number> & {
@@ -13,9 +13,12 @@ declare const StyledImage: import("@tamagui/core").TamaguiComponent<(import("rea
13
13
  type StyledImageProps = Omit<GetProps<typeof StyledImage>, 'borderRadius'> & {
14
14
  borderRadius?: RadiusTokens;
15
15
  };
16
- type BaseProps = Omit<StyledImageProps, 'source' | 'width' | 'height' | 'style' | 'onLayout'> & {
17
- width: number;
18
- height: number;
16
+ type BaseProps = Omit<StyledImageProps, 'width' | 'height' | 'style' | 'onLayout'> & {
17
+ width: string | number | SizeTokens | ThemeValueFallback;
18
+ height: string | number | SizeTokens | ThemeValueFallback;
19
+ /**
20
+ * @deprecated use `source` instead to disambiguate width/height style from width/height of the actual image
21
+ */
19
22
  src: string | StyledImageProps['source'];
20
23
  };
21
24
  export type ImageProps = BaseProps & Omit<StackProps, keyof BaseProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../src/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,UAAU,EAKX,MAAM,eAAe,CAAA;AACtB,OAAO,KAAqB,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA;AAM/C,QAAA,MAAM,WAAW;;;;;;;;EAKf,CAAA;AAEF,KAAK,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,WAAW,CAAC,EAAE,cAAc,CAAC,GAAG;IAC3E,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAED,KAAK,SAAS,GAAG,IAAI,CACnB,gBAAgB,EAChB,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CACrD,GAAG;IACF,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;CACzC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,SAAS,CAAC,CAAA;AAEtE,KAAK,WAAW,GAAG,OAAO,OAAO,CAAA;AAEjC,KAAK,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG;IACtC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAA;IAC/B,kBAAkB,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAA;IACrD,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,CAAA;IACjC,oBAAoB,EAAE,WAAW,CAAC,sBAAsB,CAAC,CAAA;IACzD,aAAa,EAAE,WAAW,CAAC,eAAe,CAAC,CAAA;IAC3C,UAAU,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;CACtC,CAAA;AAED,eAAO,MAAM,KAAK,WAYG,CAAA"}
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../src/Image.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,kBAAkB,EAKnB,MAAM,eAAe,CAAA;AACtB,OAAO,KAAqB,MAAM,OAAO,CAAA;AACzC,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA;AAM/C,QAAA,MAAM,WAAW;;;;;;;;EAKf,CAAA;AAEF,KAAK,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,WAAW,CAAC,EAAE,cAAc,CAAC,GAAG;IAC3E,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAED,KAAK,SAAS,GAAG,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAC,GAAG;IACnF,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,kBAAkB,CAAA;IACxD,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG,kBAAkB,CAAA;IAEzD;;OAEG;IACH,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAA;CACzC,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,IAAI,CAAC,UAAU,EAAE,MAAM,SAAS,CAAC,CAAA;AAEtE,KAAK,WAAW,GAAG,OAAO,OAAO,CAAA;AAEjC,KAAK,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG;IACtC,OAAO,EAAE,WAAW,CAAC,SAAS,CAAC,CAAA;IAC/B,kBAAkB,EAAE,WAAW,CAAC,oBAAoB,CAAC,CAAA;IACrD,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,CAAA;IACjC,oBAAoB,EAAE,WAAW,CAAC,sBAAsB,CAAC,CAAA;IACzD,aAAa,EAAE,WAAW,CAAC,eAAe,CAAC,CAAA;IAC3C,UAAU,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;CACtC,CAAA;AAID,eAAO,MAAM,KAAK,WA2BG,CAAA"}