廓形仪rn版本-技术调研
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.2 KiB

  1. 'use client';
  2. import React from 'react';
  3. import { createImage } from '@gluestack-ui/image';
  4. import { Platform, Image as RNImage } from 'react-native';
  5. import { tva } from '@gluestack-ui/nativewind-utils/tva';
  6. import type { VariantProps } from '@gluestack-ui/nativewind-utils';
  7. const imageStyle = tva({
  8. base: 'max-w-full',
  9. variants: {
  10. size: {
  11. '2xs': 'h-6 w-6',
  12. 'xs': 'h-10 w-10',
  13. 'sm': 'h-16 w-16',
  14. 'md': 'h-20 w-20',
  15. 'lg': 'h-24 w-24',
  16. 'xl': 'h-32 w-32',
  17. '2xl': 'h-64 w-64',
  18. 'full': 'h-full w-full',
  19. 'none': '',
  20. },
  21. },
  22. });
  23. const UIImage = createImage({ Root: RNImage });
  24. type ImageProps = VariantProps<typeof imageStyle> &
  25. React.ComponentProps<typeof UIImage>;
  26. const Image = React.forwardRef<
  27. React.ComponentRef<typeof UIImage>,
  28. ImageProps & { className?: string }
  29. >(function Image({ size = 'md', className, ...props }, ref) {
  30. return (
  31. <UIImage
  32. className={imageStyle({ size, class: className })}
  33. {...props}
  34. ref={ref}
  35. // @ts-expect-error : web only
  36. style={
  37. Platform.OS === 'web'
  38. ? { height: 'revert-layer', width: 'revert-layer' }
  39. : undefined
  40. }
  41. />
  42. );
  43. });
  44. Image.displayName = 'Image';
  45. export { Image };