candlefinance / faster-image

Fast image loading for React Native backed by performant native libraries.
https://candle.fi/discord
MIT License
479 stars 21 forks source link

[Request feature] Preload images #44

Open ng-ha opened 1 week ago

ng-ha commented 1 week ago

Does this library support to preload images or plan to support this feature in the future?

gtokman commented 6 days ago

@ng-ha yes, it's pretty trivial to add. I'll have more time next week to do it.

// ios/FasterImageViewManager.swift
@objc
  func prefetch(_ sources: [String],
                resolve: @escaping RCTPromiseResolveBlock,
                reject: @escaping RCTPromiseRejectBlock) {
                do {
    let prefetcher = ImagePrefetcher()
    let urls = sources.map { url in URL(string: url )}.compactMap{ $0 }
    prefetcher.startPrefetching(with: urls)
    resolve(true)
    } catch { reject() }
  }