status-react/src/react_native/fast_image.cljs
Ulises Manuel 550fa04e33
[#18512] incomplete list of collectibles (#18577)
* Fix var naming react-native-svg namespace

* Update collectible components to show SVGs

* Display collectibles containing collection images

* Show collectibles containing SVG animations as static images

* Reduce collectibles fetching priority

* Add support to visualize SVGs in collectible detail screen
2024-01-26 09:52:04 -06:00

41 lines
1.3 KiB
Clojure

(ns react-native.fast-image
(:require
["react-native-fast-image" :as FastImage]
[react-native.core :as rn]
[reagent.core :as reagent]))
(def fast-image-class (reagent/adapt-react-class ^js FastImage))
(defn placeholder
[style child]
[rn/view {:style (merge style {:flex 1 :justify-content :center :align-items :center})}
child])
(defn fast-image
[_]
(let [loaded? (reagent/atom false)
error? (reagent/atom false)]
(fn [{:keys [source] :as props}]
[fast-image-class
(merge
props
{:source (if (string? source)
{:uri source
:priority :high}
source)
:on-error (fn [e]
(when-let [on-error (:on-error props)]
(on-error e))
(reset! error? true))
:on-load (fn [e]
(when-let [on-load (:on-load props)]
(on-load e))
(reset! loaded? true)
(reset! error? false))})
(when (or @error? (not @loaded?))
[placeholder (:style props)
(if @error?
[rn/text "X"]
(when-not @loaded?
[rn/activity-indicator {:animating true}]))])])))