mirror of
https://github.com/status-im/status-react.git
synced 2025-02-22 07:38:34 +00:00
* 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
41 lines
1.3 KiB
Clojure
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}]))])])))
|