[#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
This commit is contained in:
Ulises Manuel 2024-01-26 09:52:04 -06:00 committed by GitHub
parent 1acf8f0d07
commit 550fa04e33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 97 additions and 46 deletions

View File

@ -2,7 +2,9 @@
(:require (:require
[quo.components.markdown.text :as text] [quo.components.markdown.text :as text]
[quo.components.profile.collectible.style :as style] [quo.components.profile.collectible.style :as style]
[react-native.core :as rn])) [react-native.core :as rn]
[react-native.fast-image :as fast-image]
[react-native.svg :as svg]))
(defn remaining-tiles (defn remaining-tiles
[amount] [amount]
@ -14,12 +16,21 @@
(str "+" amount)]]) (str "+" amount)]])
(defn tile (defn tile
[{:keys [style resource size]}] [{:keys [style size resource]}]
(let [source (if (string? resource) {:uri resource} resource)] (let [svg? (and (map? resource) (:svg? resource))
image-style (style/tile-style-by-size size)]
[rn/view {:style style} [rn/view {:style style}
[rn/image (if svg?
{:style (style/tile-style-by-size size) [rn/view
:source source}]])) {:style {:border-radius (:border-radius image-style)
:overflow :hidden}}
[svg/svg-uri (assoc image-style :uri (:uri resource))]]
[fast-image/fast-image
{:style image-style
:source (if (string? resource)
{:uri resource
:priority :low}
resource)}])]))
(defn two-tiles (defn two-tiles
[{:keys [images size]}] [{:keys [images size]}]

View File

@ -27,7 +27,7 @@
9.213 11.877 8.436 C 11.787 7.866 11.649 7.313 11.468 6.781 Z" 9.213 11.877 8.436 C 11.787 7.866 11.649 7.313 11.468 6.781 Z"
:clip-path "url(#clip0_5514_84289)"}] :clip-path "url(#clip0_5514_84289)"}]
[svg/defs [svg/defs
[svg/clippath {:id "clip0_5514_84289"} [svg/clip-path {:id "clip0_5514_84289"}
[svg/rect {:width width :height height :fill :none}]]]]) [svg/rect {:width width :height height :fill :none}]]]])
(defn- content (defn- content

View File

@ -20,7 +20,8 @@
(merge (merge
props props
{:source (if (string? source) {:source (if (string? source)
{:uri source} {:uri source
:priority :high}
source) source)
:on-error (fn [e] :on-error (fn [e]
(when-let [on-error (:on-error props)] (when-let [on-error (:on-error props)]

View File

@ -6,10 +6,11 @@
(def svg (reagent/adapt-react-class Svg/default)) (def svg (reagent/adapt-react-class Svg/default))
(def path (reagent/adapt-react-class Svg/Path)) (def path (reagent/adapt-react-class Svg/Path))
(def rect (reagent/adapt-react-class Svg/Rect)) (def rect (reagent/adapt-react-class Svg/Rect))
(def clippath (reagent/adapt-react-class Svg/ClipPath)) (def clip-path (reagent/adapt-react-class Svg/ClipPath))
(def defs (reagent/adapt-react-class Svg/Defs)) (def defs (reagent/adapt-react-class Svg/Defs))
(def circle (reagent/adapt-react-class Svg/Circle)) (def circle (reagent/adapt-react-class Svg/Circle))
(def svgxml (reagent/adapt-react-class Svg/SvgXml)) (def svg-xml (reagent/adapt-react-class Svg/SvgXml))
(def svg-uri (reagent/adapt-react-class Svg/SvgUri))
(def g (reagent/adapt-react-class Svg/G)) (def g (reagent/adapt-react-class Svg/G))
(def linear-gradient (reagent/adapt-react-class Svg/LinearGradient)) (def linear-gradient (reagent/adapt-react-class Svg/LinearGradient))
(def stop (reagent/adapt-react-class Svg/Stop)) (def stop (reagent/adapt-react-class Svg/Stop))

View File

@ -3,6 +3,7 @@
[quo.core :as quo] [quo.core :as quo]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[react-native.core :as rn] [react-native.core :as rn]
[react-native.svg :as svg]
[reagent.core :as reagent] [reagent.core :as reagent]
[status-im.common.scroll-page.view :as scroll-page] [status-im.common.scroll-page.view :as scroll-page]
[status-im.contexts.wallet.collectible.style :as style] [status-im.contexts.wallet.collectible.style :as style]
@ -75,14 +76,18 @@
(let [selected-tab (reagent/atom :overview) (let [selected-tab (reagent/atom :overview)
on-tab-change #(reset! selected-tab %)] on-tab-change #(reset! selected-tab %)]
(fn [] (fn []
(let [collectible (rf/sub [:wallet/last-collectible-details]) (let [collectible (rf/sub [:wallet/last-collectible-details])
animation-shared-element-id (rf/sub [:animation-shared-element-id]) animation-shared-element-id (rf/sub [:animation-shared-element-id])
{:keys [collectible-data preview-url {:keys [id
collection-data id]} collectible preview-url
token-id (:token-id id) collection-data
collectible-data]} collectible
{svg? :svg?
preview-uri :uri} preview-url
token-id (:token-id id)
{collection-image :image-url {collection-image :image-url
collection-name :name} collection-data collection-name :name} collection-data
{collectible-name :name} collectible-data] {collectible-name :name} collectible-data]
[scroll-page/scroll-page [scroll-page/scroll-page
{:navigate-back? true {:navigate-back? true
:height 148 :height 148
@ -94,29 +99,38 @@
[:show-bottom-sheet [:show-bottom-sheet
{:content collectible-actions-sheet {:content collectible-actions-sheet
:theme theme}])}] :theme theme}])}]
:picture preview-url}} :picture preview-uri}}
[rn/view {:style style/container} [rn/view {:style style/container}
[rn/view {:style style/preview-container} [rn/view {:style style/preview-container}
[rn/touchable-opacity [rn/touchable-opacity
{:active-opacity 1 {:active-opacity 1
:on-press #(rf/dispatch [:lightbox/navigate-to-lightbox :on-press (fn []
token-id (if svg?
{:images [{:image preview-url (js/alert "Can't visualize SVG images in lightbox")
:image-width 300 ; collectibles don't have (rf/dispatch [:lightbox/navigate-to-lightbox
; width/height but we need token-id
; to pass something {:images [{:image preview-uri
:image-height 300 ; without it animation :image-width 300 ; collectibles don't have
; doesn't work smoothly and ; width/height but we need
; :border-radius not ; to pass something
; applied :image-height 300 ; without it animation
:id token-id ; doesn't work smoothly and
:header collectible-name ; :border-radius not
:description collection-name}] ; applied
:index 0}])} :id token-id
[rn/image :header collectible-name
{:source preview-url :description collection-name}]
:style style/preview :index 0}])))}
:native-ID (when (= animation-shared-element-id token-id) :shared-element)}]]] (if svg?
[rn/view
{:style (assoc style/preview :overflow :hidden)
:native-ID (when (= animation-shared-element-id token-id)
:shared-element)}
[svg/svg-uri (assoc style/preview :uri preview-uri)]]
[rn/image
{:source preview-uri
:style style/preview
:native-ID (when (= animation-shared-element-id token-id) :shared-element)}])]]
[header collectible-name collection-name collection-image] [header collectible-name collection-name collection-image]
[cta-buttons] [cta-buttons]
[quo/tabs [quo/tabs

View File

@ -24,9 +24,11 @@
(defn displayable-collectible? (defn displayable-collectible?
[collectible] [collectible]
(let [{:keys [image-url animation-url]} (:collectible-data collectible)] (let [{{:keys [image-url animation-url]} :collectible-data
{collection-image-url :image-url} :collection-data} collectible]
(or (not (string/blank? animation-url)) (or (not (string/blank? animation-url))
(not (string/blank? image-url))))) (not (string/blank? image-url))
(not (string/blank? collection-image-url)))))
(defn- add-collectibles-to-accounts (defn- add-collectibles-to-accounts
[accounts collectibles] [accounts collectibles]

View File

@ -3,17 +3,39 @@
[clojure.string :as string] [clojure.string :as string]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]))
(defn- svg-animation?
[url media-type]
(and (not (string/blank? url))
(string/includes? media-type "svg")))
(defn- animation?
[url media-type]
(and (not (string/blank? url))
(not (string/blank? media-type))))
(defn- preview-url (defn- preview-url
[{:keys [image-url animation-url animation-media-type]}] [{{collectible-image-url :image-url
(if (and (not (string/blank? animation-url)) animation-url :animation-url
(not= animation-media-type "image/svg+xml")) animation-media-type :animation-media-type} :collectible-data
animation-url {collection-image-url :image-url} :collection-data}]
image-url)) (cond
(svg-animation? animation-url animation-media-type)
{:uri animation-url
:svg? true}
(animation? animation-url animation-media-type)
{:uri animation-url}
(not (string/blank? collectible-image-url))
{:uri collectible-image-url}
:else
{:uri collection-image-url}))
(defn add-collectibles-preview-url (defn add-collectibles-preview-url
[collectibles] [collectibles]
(map (fn [{:keys [collectible-data] :as collectible}] (map (fn [collectible]
(assoc collectible :preview-url (preview-url collectible-data))) (assoc collectible :preview-url (preview-url collectible)))
collectibles)) collectibles))
(re-frame/reg-sub (re-frame/reg-sub
@ -47,7 +69,7 @@
:<- [:wallet] :<- [:wallet]
(fn [wallet] (fn [wallet]
(let [last-collectible (:last-collectible-details wallet)] (let [last-collectible (:last-collectible-details wallet)]
(assoc last-collectible :preview-url (preview-url (:collectible-data last-collectible)))))) (assoc last-collectible :preview-url (preview-url last-collectible)))))
(re-frame/reg-sub (re-frame/reg-sub
:wallet/last-collectible-details-chain-id :wallet/last-collectible-details-chain-id