react-native-awesome-gallery icon indicating copy to clipboard operation
react-native-awesome-gallery copied to clipboard

Web compatibility

Open JPFrancoia opened this issue 9 months ago • 1 comments

Hi 👋

I'm trying to make this package work with web. I checked the issues, an old one here mentioned that this package isn't compatible with web: https://github.com/pavelbabenko/react-native-awesome-gallery/issues/42

I actually believe it's 99% compatible with web. I use this package with an expo app, on web. I'm getting an error, but it still works. The error is basically saying e.nativeEvent.source isn't valid on web.

By quickly commenting a few lines of node_modules/react-native-awesome-gallery/lib/module/index.js, I got rid of the error:

const defaultRenderImage = ({
  item,
  setImageDimensions
}) => {
  return /*#__PURE__*/React.createElement(Image, {
    onLoad: e => {
      // const {
      //   height: h,
      //   width: w
      // } = e.nativeEvent.source;
      const h = 800;
      const w = 500;
      setImageDimensions({
        height: h,
        width: w
      });
    },
    source: {
      uri: item
    },
    resizeMode: "contain",
    style: StyleSheet.absoluteFillObject
  });
};

it's rough, it's just to prove that we could make this package work with web without too much trouble. I think this line needs to be changed:

https://github.com/pavelbabenko/react-native-awesome-gallery/blob/5ab264db201379a3b6aa2e7b65c8018dc46b05bd/src/index.tsx#L80

It's responsible for getting the size of the image being clicked. If I get around to it I'll make a PR, but I thought I'd just let people know.

JPFrancoia avatar Jan 20 '25 15:01 JPFrancoia