brisk
brisk copied to clipboard
Fetching remote images
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.
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 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 we'd have to ask @czystyl since he was interested in this one, too!
@mobily I had the same idea to get know how hooks work. We can chat about it on Discord 😃