chore: use banner from quo library (#14629)
This commit is contained in:
parent
9ed89ac97d
commit
846d628a9d
|
@ -1,4 +1,4 @@
|
||||||
(ns quo2.components.banners.--tests--.banner-component-spec
|
(ns quo2.components.banners.banner.component-spec
|
||||||
(:require ["@testing-library/react-native" :as rtl]
|
(:require ["@testing-library/react-native" :as rtl]
|
||||||
[quo2.components.banners.banner.view :as banner]
|
[quo2.components.banners.banner.view :as banner]
|
||||||
[reagent.core :as reagent]))
|
[reagent.core :as reagent]))
|
||||||
|
@ -15,3 +15,13 @@
|
||||||
(.toBeTruthy))
|
(.toBeTruthy))
|
||||||
(-> (js/expect (rtl/screen.getByText "5"))
|
(-> (js/expect (rtl/screen.getByText "5"))
|
||||||
(.toBeTruthy))))
|
(.toBeTruthy))))
|
||||||
|
|
||||||
|
(js/global.test "banner component fires an event when pressed"
|
||||||
|
(let [mock-fn (js/jest.fn)]
|
||||||
|
(fn []
|
||||||
|
(render-banner {:on-press mock-fn
|
||||||
|
:pins-count "5"
|
||||||
|
:latest-pin-text "this message"})
|
||||||
|
(rtl/fireEvent.press (rtl/screen.getByText "this message"))
|
||||||
|
(-> (js/expect mock-fn)
|
||||||
|
(.toHaveBeenCalledTimes 1)))))
|
|
@ -3,17 +3,26 @@
|
||||||
|
|
||||||
|
|
||||||
(def container
|
(def container
|
||||||
{:width "100%"
|
{:height 40
|
||||||
:height 50
|
:flex 1
|
||||||
:background-color colors/primary-50-opa-20
|
:background-color colors/primary-50-opa-20
|
||||||
:flex-direction :row
|
:flex-direction :row
|
||||||
:align-items :center
|
:align-items :center
|
||||||
:padding-horizontal 20
|
:padding-right 22
|
||||||
|
:padding-left 20
|
||||||
:padding-vertical 10})
|
:padding-vertical 10})
|
||||||
|
|
||||||
(def counter
|
(def counter
|
||||||
{:padding-right 22
|
{:flex 1
|
||||||
:height 20
|
|
||||||
:width 20
|
|
||||||
:justify-content :center
|
:justify-content :center
|
||||||
:align-items :center})
|
:align-items :center})
|
||||||
|
|
||||||
|
(def icon
|
||||||
|
{:flex 1
|
||||||
|
:margin-right 10})
|
||||||
|
|
||||||
|
(defn text
|
||||||
|
[hide-pin?]
|
||||||
|
{:flex (if hide-pin? 16 15)
|
||||||
|
:margin-right 10})
|
||||||
|
|
||||||
|
|
|
@ -3,22 +3,28 @@
|
||||||
[quo2.components.counter.counter :as counter]
|
[quo2.components.counter.counter :as counter]
|
||||||
[quo2.components.icon :as icons]
|
[quo2.components.icon :as icons]
|
||||||
[quo2.components.markdown.text :as text]
|
[quo2.components.markdown.text :as text]
|
||||||
|
[quo2.foundations.colors :as colors]
|
||||||
[react-native.core :as rn]))
|
[react-native.core :as rn]))
|
||||||
|
|
||||||
(defn banner
|
(defn banner
|
||||||
[{:keys [show-pin? latest-pin-text pins-count on-press]}]
|
[{:keys [hide-pin? latest-pin-text pins-count on-press]}]
|
||||||
|
(when (pos? pins-count)
|
||||||
[rn/touchable-opacity
|
[rn/touchable-opacity
|
||||||
{:accessibility-label :pinned-banner
|
{:accessibility-label :pinned-banner
|
||||||
:style style/container
|
:style style/container
|
||||||
:active-opacity 1
|
:active-opacity 1
|
||||||
:on-press on-press}
|
:on-press on-press}
|
||||||
(when show-pin? [icons/icon :i/pin {:size 20}])
|
(when-not hide-pin?
|
||||||
|
[rn/view {:style style/icon}
|
||||||
|
[icons/icon :i/pin
|
||||||
|
{:color (colors/theme-colors colors/neutral-100 colors/white)
|
||||||
|
:size 20}]])
|
||||||
|
[rn/view {:style (style/text hide-pin?)}
|
||||||
[text/text
|
[text/text
|
||||||
{:number-of-lines 1
|
{:number-of-lines 1
|
||||||
:size :paragraph-2
|
:size :paragraph-2}
|
||||||
:style {:margin-left 10 :margin-right 50}}
|
latest-pin-text]]
|
||||||
latest-pin-text]
|
|
||||||
[rn/view
|
[rn/view
|
||||||
{:accessibility-label :pins-count
|
{:accessibility-label :pins-count
|
||||||
:style style/counter}
|
:style style/counter}
|
||||||
(when (pos? pins-count) [counter/counter {:type :secondary} pins-count])]])
|
(when (> pins-count 1) [counter/counter {:type :secondary} pins-count])]]))
|
|
@ -1,5 +1,5 @@
|
||||||
(ns quo2.core-spec
|
(ns quo2.core-spec
|
||||||
(:require [quo2.components.banners.--tests--.banner-component-spec]
|
(:require [quo2.components.banners.banner.component-spec]
|
||||||
[quo2.components.buttons.--tests--.buttons-component-spec]
|
[quo2.components.buttons.--tests--.buttons-component-spec]
|
||||||
[quo2.components.counter.--tests--.counter-component-spec]
|
[quo2.components.counter.--tests--.counter-component-spec]
|
||||||
[quo2.components.dividers.--tests--.divider-label-component-spec]
|
[quo2.components.dividers.--tests--.divider-label-component-spec]
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
|
|
||||||
(defn pin-popover
|
(defn pin-popover
|
||||||
[width]
|
[width]
|
||||||
{:position :absolute
|
{:width (- width 16)
|
||||||
:width (- width 16)
|
:margin-left 8
|
||||||
:left 8
|
|
||||||
:background-color (colors/theme-colors colors/neutral-80-opa-90 colors/white-opa-90)
|
:background-color (colors/theme-colors colors/neutral-80-opa-90 colors/white-opa-90)
|
||||||
:flex-direction :row
|
:flex-direction :row
|
||||||
:border-radius 16
|
:border-radius 16
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
(reanimated/with-timing (if show-pin-limit-modal? 1 0)))
|
(reanimated/with-timing (if show-pin-limit-modal? 1 0)))
|
||||||
(reanimated/set-shared-value z-index-animation
|
(reanimated/set-shared-value z-index-animation
|
||||||
(reanimated/with-timing (if show-pin-limit-modal? 10 -1)))))
|
(reanimated/with-timing (if show-pin-limit-modal? 10 -1)))))
|
||||||
|
(when show-pin-limit-modal?
|
||||||
[reanimated/view
|
[reanimated/view
|
||||||
{:style (reanimated/apply-animations-to-style
|
{:style (reanimated/apply-animations-to-style
|
||||||
{:opacity opacity-animation
|
{:opacity opacity-animation
|
||||||
|
@ -43,7 +44,8 @@
|
||||||
:active-opacity 1
|
:active-opacity 1
|
||||||
:on-press (fn []
|
:on-press (fn []
|
||||||
(rf/dispatch [:pin-message/hide-pin-limit-modal chat-id])
|
(rf/dispatch [:pin-message/hide-pin-limit-modal chat-id])
|
||||||
(rf/dispatch [:bottom-sheet/show-sheet :pinned-messages-list chat-id]))
|
(rf/dispatch [:bottom-sheet/show-sheet :pinned-messages-list
|
||||||
|
chat-id]))
|
||||||
:style style/view-pinned-messages}
|
:style style/view-pinned-messages}
|
||||||
[quo/text {:size :paragraph-2 :weight :medium :color colors/white}
|
[quo/text {:size :paragraph-2 :weight :medium :color colors/white}
|
||||||
(i18n/label :t/view-pinned-messages)]]]
|
(i18n/label :t/view-pinned-messages)]]]
|
||||||
|
@ -56,6 +58,6 @@
|
||||||
:right 16}}
|
:right 16}}
|
||||||
[quo/icon :i/close
|
[quo/icon :i/close
|
||||||
{:color (colors/theme-colors colors/white colors/neutral-100)
|
{:color (colors/theme-colors colors/white colors/neutral-100)
|
||||||
:size 12}]]]))])
|
:size 12}]]])))])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
(ns status-im.ui2.screens.chat.pinned-banner.view
|
|
||||||
(:require [quo2.core :as quo]
|
|
||||||
[quo2.foundations.colors :as colors]
|
|
||||||
[react-native.core :as rn]))
|
|
||||||
|
|
||||||
;; TODO (flexsurfer) this should be a banner component in quo2
|
|
||||||
;; https://github.com/status-im/status-mobile/issues/14528
|
|
||||||
(defn pinned-banner
|
|
||||||
[{:keys [latest-pin-text pins-count on-press]}]
|
|
||||||
[rn/touchable-opacity
|
|
||||||
{:accessibility-label :pinned-banner
|
|
||||||
:style {:height 50
|
|
||||||
:background-color colors/primary-50-opa-20
|
|
||||||
:flex-direction :row
|
|
||||||
:align-items :center
|
|
||||||
:padding-horizontal 20
|
|
||||||
:padding-vertical 10}
|
|
||||||
:active-opacity 1
|
|
||||||
:on-press on-press}
|
|
||||||
[quo/icon :i/pin {:size 20}]
|
|
||||||
[quo/text
|
|
||||||
{:number-of-lines 1
|
|
||||||
:size :paragraph-2
|
|
||||||
:style {:margin-left 10 :margin-right 50}}
|
|
||||||
latest-pin-text]
|
|
||||||
[rn/view
|
|
||||||
{:accessibility-label :pins-count
|
|
||||||
:style {:position :absolute
|
|
||||||
:right 22
|
|
||||||
:height 20
|
|
||||||
:width 20
|
|
||||||
:border-radius 8
|
|
||||||
:justify-content :center
|
|
||||||
:align-items :center
|
|
||||||
:background-color colors/neutral-80-opa-5}}
|
|
||||||
[quo/text {:size :label :weight :medium} pins-count]]])
|
|
|
@ -3,5 +3,6 @@
|
||||||
|
|
||||||
(defn not-implemented
|
(defn not-implemented
|
||||||
[content]
|
[content]
|
||||||
|
(when content
|
||||||
[rn/view {:border-color :red :border-width 1}
|
[rn/view {:border-color :red :border-width 1}
|
||||||
content])
|
content]))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
(ns status-im2.contexts.chat.messages.pin.banner.view
|
(ns status-im2.contexts.chat.messages.pin.banner.view
|
||||||
(:require [status-im.ui2.screens.chat.pinned-banner.view :as pinned-banner]
|
(:require [quo2.core :as quo]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn banner
|
(defn banner
|
||||||
|
@ -7,14 +7,14 @@
|
||||||
(let [pinned-messages (rf/sub [:chats/pinned chat-id])
|
(let [pinned-messages (rf/sub [:chats/pinned chat-id])
|
||||||
latest-pin-id (-> pinned-messages
|
latest-pin-id (-> pinned-messages
|
||||||
vals
|
vals
|
||||||
last
|
first
|
||||||
(get :message-id))
|
(get :message-id))
|
||||||
latest-pin-text (get-in (rf/sub [:chats/chat-messages chat-id])
|
latest-pin-text (get-in (rf/sub [:chats/chat-messages chat-id])
|
||||||
[latest-pin-id :content :text])
|
[latest-pin-id :content :text])
|
||||||
pins-count (count (seq pinned-messages))]
|
pins-count (count (seq pinned-messages))]
|
||||||
(when (> pins-count 0)
|
[quo/banner
|
||||||
;; TODO (flexsurfer) this should be banner component in quo2
|
|
||||||
[pinned-banner/pinned-banner
|
|
||||||
{:latest-pin-text latest-pin-text
|
{:latest-pin-text latest-pin-text
|
||||||
:pins-count pins-count
|
:pins-count pins-count
|
||||||
:on-press #(rf/dispatch [:bottom-sheet/show-sheet :pinned-messages-list chat-id])}])))
|
:on-press #(rf/dispatch [:bottom-sheet/show-sheet :pinned-messages-list chat-id])}]))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,8 @@
|
||||||
[status-im2.navigation.state :as navigation.state]
|
[status-im2.navigation.state :as navigation.state]
|
||||||
[utils.debounce :as debounce]
|
[utils.debounce :as debounce]
|
||||||
[utils.re-frame :as rf]
|
[utils.re-frame :as rf]
|
||||||
[status-im2.common.not-implemented :as not-implemented]))
|
[status-im2.common.not-implemented :as not-implemented]
|
||||||
|
[quo2.foundations.colors :as colors]))
|
||||||
|
|
||||||
(defn navigate-back-handler
|
(defn navigate-back-handler
|
||||||
[]
|
[]
|
||||||
|
@ -32,8 +33,7 @@
|
||||||
[quo/page-nav
|
[quo/page-nav
|
||||||
{:align-mid? true
|
{:align-mid? true
|
||||||
|
|
||||||
:mid-section
|
:mid-section (if group-chat
|
||||||
(if group-chat
|
|
||||||
{:type :text-only
|
{:type :text-only
|
||||||
:main-text display-name}
|
:main-text display-name}
|
||||||
{:type :user-avatar
|
{:type :user-avatar
|
||||||
|
@ -42,18 +42,18 @@
|
||||||
:profile-picture photo-path
|
:profile-picture photo-path
|
||||||
:size :medium}
|
:size :medium}
|
||||||
:main-text display-name
|
:main-text display-name
|
||||||
:on-press #(debounce/dispatch-and-chill [:chat.ui/show-profile chat-id] 1000)})
|
:on-press #(debounce/dispatch-and-chill [:chat.ui/show-profile chat-id]
|
||||||
|
1000)})
|
||||||
|
|
||||||
:left-section
|
:left-section {:on-press #(do
|
||||||
{:on-press #(do
|
|
||||||
(rf/dispatch [:close-chat])
|
(rf/dispatch [:close-chat])
|
||||||
(rf/dispatch [:navigate-back]))
|
(rf/dispatch [:navigate-back]))
|
||||||
:icon :i/arrow-left
|
:icon :i/arrow-left
|
||||||
:accessibility-label :back-button}
|
:accessibility-label :back-button}
|
||||||
|
|
||||||
:right-section-buttons
|
:right-section-buttons [{:on-press #()
|
||||||
[{:on-press #()
|
:style {:border-width 1
|
||||||
:style {:border-width 1 :border-color :red}
|
:border-color :red}
|
||||||
:icon :i/options
|
:icon :i/options
|
||||||
:accessibility-label :options-button}]}]))
|
:accessibility-label :options-button}]}]))
|
||||||
|
|
||||||
|
@ -61,12 +61,21 @@
|
||||||
[]
|
[]
|
||||||
(let [;;NOTE: we want to react only on these fields, do not use full chat map here
|
(let [;;NOTE: we want to react only on these fields, do not use full chat map here
|
||||||
{:keys [chat-id show-input?] :as chat} (rf/sub [:chats/current-chat-chat-view])]
|
{:keys [chat-id show-input?] :as chat} (rf/sub [:chats/current-chat-chat-view])]
|
||||||
[rn/keyboard-avoiding-view {:style {:flex 1}}
|
[rn/keyboard-avoiding-view {:style {:position :relative :flex 1}}
|
||||||
[page-nav]
|
[rn/view
|
||||||
|
{:style {:position :absolute
|
||||||
|
:top 56
|
||||||
|
:z-index 2
|
||||||
|
:background-color (colors/theme-colors colors/white colors/neutral-100)
|
||||||
|
:width "100%"}}
|
||||||
|
|
||||||
|
[pin.banner/banner chat-id]
|
||||||
[not-implemented/not-implemented
|
[not-implemented/not-implemented
|
||||||
[pin-limit-popover/pin-limit-popover chat-id]]
|
[pin-limit-popover/pin-limit-popover chat-id]]
|
||||||
[not-implemented/not-implemented
|
]
|
||||||
[pin.banner/banner chat-id]]
|
[page-nav]
|
||||||
|
|
||||||
|
|
||||||
[messages.list/messages-list {:chat chat :show-input? show-input?}]
|
[messages.list/messages-list {:chat chat :show-input? show-input?}]
|
||||||
(when show-input?
|
(when show-input?
|
||||||
[composer/composer chat-id])]))
|
[composer/composer chat-id])]))
|
||||||
|
|
|
@ -12,16 +12,17 @@
|
||||||
{:label "number of messages"
|
{:label "number of messages"
|
||||||
:key :pins-count
|
:key :pins-count
|
||||||
:type :text}
|
:type :text}
|
||||||
{:label "show pin icon?"
|
{:label "hide pin icon?"
|
||||||
:key :show-pin?
|
:key :hide-pin?
|
||||||
:type :boolean}
|
:type :boolean}
|
||||||
])
|
])
|
||||||
|
|
||||||
(defn cool-preview
|
(defn cool-preview
|
||||||
[]
|
[]
|
||||||
(let [state (reagent/atom {:show-pin? true
|
(let [state (reagent/atom
|
||||||
|
{:hide-pin? false
|
||||||
:pins-count 2
|
:pins-count 2
|
||||||
:latest-pin-text "Be respectful of fellow community member..."})]
|
:latest-pin-text "Be respectful of fellow community members, even if they"})]
|
||||||
(fn []
|
(fn []
|
||||||
[rn/touchable-without-feedback {:on-press rn/dismiss-keyboard!}
|
[rn/touchable-without-feedback {:on-press rn/dismiss-keyboard!}
|
||||||
[rn/view {:padding-bottom 150}
|
[rn/view {:padding-bottom 150}
|
||||||
|
|
Loading…
Reference in New Issue