Skip to content

Commit

Permalink
Merge branch 'develop' into qr-scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx authored Feb 15, 2024
2 parents 8a9c004 + dc53bdd commit f4aa4af
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 87 deletions.
52 changes: 52 additions & 0 deletions src/quo/components/tags/collectible_tag/component_spec.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(ns quo.components.tags.collectible-tag.component-spec
(:require
[quo.components.tags.collectible-tag.view :as collectible-tag]
[test-helpers.component :as h]))

(def collectible-name "Collectible")
(def collectible-id "#123")

(defn get-test-data
[{:keys [options blur? size]}]
{:collectible-name collectible-name
:collectible-id collectible-id
:collectible-img-src {:uri "https://example.com/image.jpg"}
:options options
:blur? (or blur? false)
:size (or size :size-24)})

(h/describe "Collectible_tag tests"
(h/test "Renders Default option"
(let [data (get-test-data {})]
(h/render-with-theme-provider [collectible-tag/view data])
(h/is-truthy (h/get-by-text collectible-name))))

(h/test "Renders Add option"
(let [data (get-test-data {:options :add})]
(h/render-with-theme-provider [collectible-tag/view data])
(h/is-truthy (h/get-by-text collectible-name))))

(h/test "Renders Hold option"
(let [data (get-test-data {:options :hold})]
(h/render-with-theme-provider [collectible-tag/view data])
(h/is-truthy (h/get-by-text collectible-name))))

(h/test "Renders with Blur"
(let [data (get-test-data {:blur? true})]
(h/render-with-theme-provider [collectible-tag/view data])
(h/is-truthy (h/get-by-text collectible-name))))

(h/test "Renders without Blur"
(let [data (get-test-data {:blur? false})]
(h/render-with-theme-provider [collectible-tag/view data])
(h/is-truthy (h/get-by-text collectible-name))))

(h/test "Renders with Size 24"
(let [data (get-test-data {:size :size-24})]
(h/render-with-theme-provider [collectible-tag/view data])
(h/is-truthy (h/get-by-text collectible-name))))

(h/test "Renders with Size 32"
(let [data (get-test-data {:size :size-32})]
(h/render-with-theme-provider [collectible-tag/view data])
(h/is-truthy (h/get-by-text collectible-name)))))
15 changes: 15 additions & 0 deletions src/quo/components/tags/collectible_tag/schema.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns quo.components.tags.collectible-tag.schema)

(def ?schema
[:=>
[:catn
[:props
[:map
[:options {:optional true} [:maybe [:enum :add :hold]]]
[:size {:optional true} [:maybe [:enum :size-24 :size-32]]]
[:blur? {:optional true} [:maybe :boolean]]
[:theme :schema.common/theme]
[:collectible-img-src :schema.common/image-source]
[:collectible-name :string]
[:collectible-id :string]]]]
:any])
99 changes: 44 additions & 55 deletions src/quo/components/tags/collectible_tag/view.cljs
Original file line number Diff line number Diff line change
@@ -1,70 +1,59 @@
(ns quo.components.tags.collectible-tag.view
(:require
[oops.core :as oops]
[quo.components.icon :as icons]
[quo.components.markdown.text :as text]
[quo.components.tags.collectible-tag.schema :as component-schema]
[quo.components.tags.collectible-tag.style :as style]
[quo.theme]
[react-native.core :as rn]
[react-native.hole-view :as hole-view]
[reagent.core :as reagent]
[schema.core :as schema]))

(def ?schema
[:=>
[:catn
[:props
[:map {:closed true}
[:options {:optional true} [:maybe [:enum false :add :hold]]]
[:size {:optional true} [:enum :size-24 :size-32]]
[:blur? {:optional true} :boolean]
[:theme :schema.common/theme]
[:collectible-img-src [:or :int :string]]
[:collectible-name :string]
[:collectible-id :string]
[:container-width :number]
[:on-layout {:optional true} [:maybe fn?]]]]]
:any])

(defn- view-internal
[]
(fn [{:keys [options size blur? theme collectible-img-src collectible-name collectible-id
container-width on-layout]
:or {size :size-24}}]
[rn/view
{:on-layout on-layout}
[hole-view/hole-view
{:holes (if options
[{:x (- container-width
(case size
:size-24 10
:size-32 12
nil))
:y (case size
:size-24 -6
:size-32 -4
nil)
:width 16
:height 16
:borderRadius 8}]
[])}
[rn/view {:style (style/container size options blur? theme)}
[rn/image {:style (style/collectible-img size) :source collectible-img-src}]
[text/text
{:size :paragraph-2
:weight :medium
:style (style/label theme)}
collectible-name]
[text/text
{:size :paragraph-2
:weight :medium
:margin-left 5
:style (style/label theme)}
collectible-id]]]
(when options
[rn/view {:style (style/options-icon size)}
[icons/icon (if (= options :hold) :i/hold :i/add-token)
{:size 20
:no-color true}]])]))
(let [container-width (reagent/atom 0)
on-layout #(->> (oops/oget % :nativeEvent :layout :width)
(reset! container-width))]
(fn [{:keys [options blur? theme collectible-img-src collectible-name collectible-id] :as props}]
(let [size (or (:size props) :size-24)]
[rn/view
{:on-layout on-layout}
[hole-view/hole-view
{:holes (if options
[{:x (- @container-width
(case size
:size-24 10
:size-32 12
nil))
:y (case size
:size-24 -6
:size-32 -4
nil)
:width 16
:height 16
:borderRadius 8}]
[])}
[rn/view {:style (style/container size options blur? theme)}
[rn/image {:style (style/collectible-img size) :source collectible-img-src}]
[text/text
{:size :paragraph-2
:weight :medium
:style (style/label theme)}
collectible-name]
[text/text
{:size :paragraph-2
:weight :medium
:margin-left 5
:style (style/label theme)}
collectible-id]]]
(when options
[rn/view {:style (style/options-icon size)}
[icons/icon (if (= options :hold) :i/hold :i/add-token)
{:size 20
:no-color true}]])]))))

(def view
(quo.theme/with-theme
(schema/instrument #'view-internal ?schema)))
(schema/instrument #'view-internal component-schema/?schema)))
1 change: 1 addition & 0 deletions src/quo/core_spec.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
quo.components.share.share-qr-code.component-spec
quo.components.switchers.base-card.component-spec
quo.components.switchers.group-messaging-card.component-spec
quo.components.tags.collectible-tag.component-spec
quo.components.tags.network-tags.component-spec
quo.components.tags.status-tags-component-spec
quo.components.tags.summary-tag.component-spec
Expand Down
14 changes: 7 additions & 7 deletions src/status_im/common/bottom_sheet_screen/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
(def ^:const drag-threshold 200)

(defn drag-gesture
[{:keys [translate-y opacity scroll-enabled curr-scroll close reset-open-sheet set-animating-true]}]
[{:keys [translate-y opacity scroll-enabled? curr-scroll close reset-open-sheet set-animating-true]}]
(-> (gesture/gesture-pan)
(gesture/on-start (fn [e]
(set-animating-true)
(when (< (oops/oget e "velocityY") 0)
(reset! scroll-enabled true))))
(reset! scroll-enabled? true))))
(gesture/on-update (fn [e]
(let [translation (oops/oget e "translationY")
progress (Math/abs (/ translation drag-threshold))]
Expand All @@ -34,7 +34,7 @@
(gesture/on-finalize (fn [e]
(when (and (>= (oops/oget e "velocityY") 0)
(<= @curr-scroll (if platform/ios? -1 0)))
(reset! scroll-enabled false))))))
(reset! scroll-enabled? false))))))

(defn on-scroll
[e curr-scroll]
Expand All @@ -43,7 +43,7 @@

(defn- f-view
[_]
(let [scroll-enabled (reagent/atom true)
(let [scroll-enabled? (reagent/atom true)
curr-scroll (reagent/atom 0)
animating? (reagent/atom true)
set-animating-true #(reset! animating? true)
Expand All @@ -63,7 +63,7 @@
(reanimated/animate translate-y 0 300)
(reanimated/animate opacity 1 300)
(set-animating-false 300)
(reset! scroll-enabled true))]
(reset! scroll-enabled? true))]
(rn/use-effect
(fn []
(reanimated/animate translate-y 0 300)
Expand All @@ -76,7 +76,7 @@
[gesture/gesture-detector
{:gesture (drag-gesture {:translate-y translate-y
:opacity opacity
:scroll-enabled scroll-enabled
:scroll-enabled? scroll-enabled?
:curr-scroll curr-scroll
:close close
:reset-open-sheet reset-open-sheet
Expand All @@ -87,7 +87,7 @@
[content
{:insets insets
:close close
:scroll-enabled scroll-enabled
:scroll-enabled? @scroll-enabled?
:current-scroll curr-scroll
:on-scroll #(on-scroll % curr-scroll)
:sheet-animating? animating?}]]]]))))
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/common/emoji_picker/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@
:container-style style/empty-results}])

(defn- render-list
[{:keys [theme filtered-data on-viewable-items-changed scroll-enabled on-scroll
[{:keys [theme filtered-data on-viewable-items-changed scroll-enabled? on-scroll
on-select set-scroll-ref close sheet-animating?]}]
[gesture/flat-list
{:ref set-scroll-ref
:scroll-enabled @scroll-enabled
:scroll-enabled scroll-enabled?
:data (or filtered-data emoji-picker.data/flatten-data)
:initial-num-to-render 14
:max-to-render-per-batch 10
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/contexts/chat/home/new_chat/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
item])))

(defn- view-internal
[{:keys [scroll-enabled on-scroll close theme]}]
[{:keys [scroll-enabled? on-scroll close theme]}]
(let [contacts (rf/sub [:contacts/sorted-and-grouped-by-first-letter])
selected-contacts-count (rf/sub [:selected-contacts-count])
selected-contacts (rf/sub [:group/selected-contacts])
Expand Down Expand Up @@ -105,7 +105,7 @@
:render-section-header-fn contact-list/contacts-section-header
:content-container-style {:padding-bottom 70}
:render-fn contact-item-render
:scroll-enabled @scroll-enabled
:scroll-enabled scroll-enabled?
:on-scroll on-scroll}])
(when contacts-selected?
[quo/button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
(str (:title item) index))

(defn- f-album-selector
[{:keys [scroll-enabled on-scroll]} album? selected-album top]
[{:keys [scroll-enabled? on-scroll]} album? selected-album top]
(let [albums (rf/sub [:camera-roll/albums])
total-photos-count-android (rf/sub [:camera-roll/total-photos-count-android])
total-photos-count-ios (rf/sub [:camera-roll/total-photos-count-ios])
Expand All @@ -87,7 +87,7 @@
:content-container-style {:padding-top 64
:padding-bottom 40}
:key-fn key-fn
:scroll-enabled @scroll-enabled
:scroll-enabled scroll-enabled?
:on-scroll on-scroll
:style {:height window-height}}]]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
(inc (utils.collection/first-index #(= (:uri item) (:uri %)) @selected))]])]))

(defn photo-selector
[{:keys [scroll-enabled on-scroll current-scroll close] :as sheet}]
[{:keys [scroll-enabled? on-scroll current-scroll close] :as sheet}]
(rf/dispatch [:photo-selector/get-photos-for-selected-album])
(rf/dispatch [:photo-selector/camera-roll-get-albums])
(let [album? (reagent/atom false)
Expand Down Expand Up @@ -134,7 +134,7 @@
:padding-bottom (+ (safe-area/get-bottom) 100)
:padding-top 64}
:on-scroll on-scroll
:scroll-enabled @scroll-enabled
:scroll-enabled scroll-enabled?
:on-end-reached (fn []
(when (and (not loading?) has-next-page?)
(rf/dispatch [:photo-selector/camera-roll-loading-more true])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
(:require [quo.core :as quo]
[quo.foundations.colors :as colors]
[react-native.core :as rn]
[react-native.gesture :as gesture]
[status-im.common.not-implemented :as not-implemented]
[status-im.common.resources :as resources]
[status-im.constants :as constants]
Expand Down Expand Up @@ -45,7 +46,7 @@
:container-style {:margin-bottom 8}}]))

(defn view
[]
[{:keys [scroll-enabled? on-scroll]}]
(let [{id :community-id} (rf/sub [:get-screen-params])]
(rf/dispatch [:communities/get-permissioned-balances id])
(fn []
Expand All @@ -67,10 +68,12 @@
:community-logo (get-in images [:thumbnail :uri])
:customization-color color}]

[rn/flat-list
[gesture/flat-list
{:render-fn account-item
:render-data [selected-addresses id]
:content-container-style {:padding 20}
:scroll-enabled scroll-enabled?
:on-scroll on-scroll
:key-fn :address
:data accounts}]

Expand Down
22 changes: 7 additions & 15 deletions src/status_im/contexts/preview/quo/tags/collectible_tag.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns status-im.contexts.preview.quo.tags.collectible-tag
(:require
[oops.core :refer [oget]]
[quo.core :as quo]
[react-native.core :as rn]
[reagent.core :as reagent]
Expand All @@ -16,9 +15,7 @@
:value "Size 32"}]}
{:key :options
:type :select
:options [{:key false
:value false}
{:key :add
:options [{:key :add
:value :add}
{:key :hold
:value :hold}]}
Expand All @@ -31,21 +28,16 @@

(defn view
[]
(let [state (reagent/atom {:size :size-24
:collectible-name "Collectible"
:collectible-id "#123"
:collectible-img-src (resources/mock-images :collectible)
:options false
:blur? false
:container-width 0})
on-layout #(swap! state assoc
:container-width
(oget % :nativeEvent :layout :width))]
(let [state (reagent/atom {:size :size-24
:collectible-name "Collectible"
:collectible-id "#123"
:collectible-img-src (resources/mock-images :collectible)
:blur? false})]
(fn []
[preview/preview-container
{:state state
:blur? (:blur? @state)
:show-blur-background? true
:descriptor descriptor}
[rn/view {:style {:align-items :center}}
[quo/collectible-tag (assoc @state :on-layout on-layout)]]])))
[quo/collectible-tag @state]]])))
Loading

0 comments on commit f4aa4af

Please sign in to comment.