brisk icon indicating copy to clipboard operation
brisk copied to clipboard

Fetching remote images

Open rauanmayemir opened this issue 5 years ago • 4 comments

Currently, <Image> only allows showing local files, bundle assets, and system images.

We need a hook that allows fetching remote images with approximately this API:

let make = (~profile, children) => component(hooks => {
  let (image, _hooks) = Image.fetch(~url=profile.imageUrl, hooks);
  <Image source=image />
});

The hook could optionally provide a fallback image and other stuff (like caching policy.)

It would work nicely because behind the scenes it could use an effect hook to free the memory used by the image it downloaded (and obviously state for some stuff) but the returned image would be simply a path to a file, probably in the tmp directory.

rauanmayemir avatar Jan 15 '19 22:01 rauanmayemir

An alternative would be a simple Hook that fetches the image and either puts it in temp or in cache. A bonus point of this solution is that it plays beautifully with the hook model. The image could be freed from the cache after unmount 😄

wokalski avatar Jan 15 '19 22:01 wokalski

@wokalski don't you mind if I take this? working on this seems to be a good way to find out how hooks and components work in brisk 😊

mobily avatar Feb 05 '19 19:02 mobily

@mobily we'd have to ask @czystyl since he was interested in this one, too!

wokalski avatar Feb 05 '19 19:02 wokalski

@mobily I had the same idea to get know how hooks work. We can chat about it on Discord 😃

czystyl avatar Feb 05 '19 21:02 czystyl