Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use preview with a local file? #160

Open
oporter1 opened this issue May 3, 2021 · 2 comments
Open

How to use preview with a local file? #160

oporter1 opened this issue May 3, 2021 · 2 comments

Comments

@oporter1
Copy link

oporter1 commented May 3, 2021

Hello,

I am looking to use the preview or remove the preview loading feature with local files. Is this possible?
looking to do something like this:

    return images.map((src, index) => {
      let previewSrc = src;
      if (src.startsWith("file")) {
        // previewSrc = require(src);
        previewSrc = src;
      } else {
        previewSrc = { src: "data:image/png;base64," + src + '"' };
      }
      return (
        <Image
          key={`image_${index}`}
          style={styles.slideImage}
          resizeMethod="resize"
          {...{
            preview: previewSrc,
            uri: src,
          }}
        />
@adamzolyak
Copy link

@oporter1 did you ever figure this out? I'm running into the same issue.

@oporter1
Copy link
Author

@adamzolyak I wasn't, I did a work around that checks if it's a file and, if so, then we just display a regular image.

return images.map((src, index) => {
      if (!src.startsWith("file")) {
        return (
          <ImageCached
            key={`image_${index}`}
            style={styles.slideImage}
            resizeMethod="resize"
            {...{
              preview: { src: "data:image/png;base64," + src + '"' },
              uri: src,
            }}
          />
        );
      } else {
        return (
          <Image
            source={{ uri: src }}
            style={styles.slideImage}
            key={`image_${index}`}
          />
        );
      }
    });
  }, [images]);



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants