vivaxy/react-native-auto-height-image

Web support

Closed this issue · 3 comments

Hi,

I think it would be cool if this lib had web support.
I tested and it didn't work great for me, it seems height stays at 0 and there's an uncaught promise error:

image

If this is something you want to support, I can try to make it happen

Thank you for your suggestion.
I am not sure what the web support means. Does it means to use this component with react-dom?
It would be helpful if you could provide the error messages.

Hi,

I'm using Expo for web (expo build:web) to run my RN app as a mobile website using RNW.

I actually found a solution that is good enough for me, as dom images already automatically auto height.

import React from 'react';
import { Platform, Image } from 'react-native';

import AutoHeightImage from 'react-native-auto-height-image';

const AppImage = ({ source, width }) => {
  // AutoHeightImage does not work on web, height stays at 0
  // Useful for mobile website!
  if (Platform.OS === 'web') {
    // return <Image source={source} style={{ width }} />;
    return <img src={source} style={{ maxWidth: width }} />;
  } else {
    return <AutoHeightImage source={source} style={{ width }} />;
  }
};

export default AppImage;

I couldn't use the original Image component, because RNW reproduces the RN behavior of images (no autoheight).

Just wondering, is there a way to specify a maxWidth instead of a width? I don't particularly want to "stretch" the image bigger than the source.

Thank you for your reply.

The component is designed to be used in react native, and to set the image to auto height with predefined width.