index.tsx 975 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { Image as NutImage } from "@nutui/nutui-react-taro";
  2. import { View } from "@tarojs/components";
  3. import { useEffect, useRef } from "react";
  4. import "./index.scss";
  5. interface CustomImageProps {
  6. src: string;
  7. width?: string | number;
  8. height?: string | number;
  9. mode?: string;
  10. onClick?: (e: any) => void;
  11. style?: any;
  12. className?: string;
  13. }
  14. const CustomImage = (props: CustomImageProps) => {
  15. const imageRef = useRef<any>(null);
  16. useEffect(() => {
  17. // 在组件挂载后,移除可能存在的 webkit-mask 样式
  18. if (imageRef.current) {
  19. const element = imageRef.current;
  20. if (element.style) {
  21. element.style.webkitMask = "none";
  22. element.style.mask = "none";
  23. element.style.webkitMaskImage = "none";
  24. element.style.maskImage = "none";
  25. }
  26. }
  27. }, []);
  28. return (
  29. <View ref={imageRef} className="custom-image-wrapper">
  30. <NutImage {...props} />
  31. </View>
  32. );
  33. };
  34. export default CustomImage;