[#11470] Statuses issues

Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
andrey 2020-11-30 11:38:32 +01:00
parent b9f896f4e3
commit d2493c0725
No known key found for this signature in database
GPG Key ID: 89B67245FD2F0272
13 changed files with 105 additions and 78 deletions

View File

@ -82,10 +82,9 @@
[react/view {:style (merge style styles/item-checkbox)} [react/view {:style (merge style styles/item-checkbox)}
[radio/radio (:checked? props)]])]) [radio/radio (:checked? props)]])])
;;TODO DEPRECATED, use status-im.ui.components.list-item.views
(defn- wrap-render-fn [f] (defn- wrap-render-fn [f]
(fn [^js data] (fn [^js data]
(reagent/as-element (f (.-item data) (.-index data) (.-separators data))))) (reagent/as-element [f (.-item data) (.-index data) (.-separators data)])))
(defn- wrap-key-fn [f] (defn- wrap-key-fn [f]
(fn [data index] (fn [data index]
@ -135,8 +134,8 @@
(defn- wrap-render-section-header-fn [f] (defn- wrap-render-section-header-fn [f]
(fn [^js data] (fn [^js data]
(let [^js section (.-section data)] (let [^js section (.-section data)]
(reagent/as-element (f {:title (.-title section) (reagent/as-element [f {:title (.-title section)
:data (.-data section)}))))) :data (.-data section)}]))))
(defn- default-render-section-header [{:keys [title data]}] (defn- default-render-section-header [{:keys [title data]}]
(when (seq data) (when (seq data)
@ -150,7 +149,7 @@
(assoc (dissoc props :render-fn) :renderItem (wrap-render-fn f)) (assoc (dissoc props :render-fn) :renderItem (wrap-render-fn f))
props) props)
:data to-array)) :data to-array))
;;TODO DEPRECATED, use status-im.ui.components.list-item.views
(defn section-list (defn section-list
"A wrapper for SectionList. "A wrapper for SectionList.
To render something on empty sections, use renderSectionFooter and conditionaly To render something on empty sections, use renderSectionFooter and conditionaly

View File

@ -5,6 +5,7 @@
[status-im.ui.components.typography :as typography] [status-im.ui.components.typography :as typography]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
["react" :as reactjs]
["react-native" :as react-native :refer (Keyboard)] ["react-native" :as react-native :refer (Keyboard)]
["react-native-image-crop-picker" :default image-picker] ["react-native-image-crop-picker" :default image-picker]
["react-native-safe-area-context" :as safe-area-context ["react-native-safe-area-context" :as safe-area-context
@ -29,7 +30,8 @@
(def text-class (reagent/adapt-react-class (.-Text react-native))) (def text-class (reagent/adapt-react-class (.-Text react-native)))
(def text-input-class (reagent/adapt-react-class (.-TextInput react-native))) (def text-input-class (reagent/adapt-react-class (.-TextInput react-native)))
(def image-class (reagent/adapt-react-class (.-Image react-native)))
(def image-class (reagent/adapt-react-class (reactjs/memo (.-Image react-native))))
(defn image-get-size [uri callback] (.getSize (.-Image react-native) uri callback)) (defn image-get-size [uri callback] (.getSize (.-Image react-native) uri callback))
(defn resolve-asset-source [uri] (js->clj (.resolveAssetSource (.-Image react-native) uri) :keywordize-keys true)) (defn resolve-asset-source [uri] (js->clj (.resolveAssetSource (.-Image react-native) uri) :keywordize-keys true))

View File

@ -36,15 +36,15 @@
:content {:title (i18n/label :t/wallet) :content {:title (i18n/label :t/wallet)
:icon :main-icons/wallet} :icon :main-icons/wallet}
:accessibility-label :wallet-tab-button} :accessibility-label :wallet-tab-button}
{:nav-stack :status-stack
:content {:title (i18n/label :t/status)
:icon :main-icons/status}
:accessibility-label :status-tab-button}
{:nav-stack :profile-stack {:nav-stack :profile-stack
:content {:title (i18n/label :t/profile) :content {:title (i18n/label :t/profile)
:icon :main-icons/user-profile} :icon :main-icons/user-profile}
:count-subscription :get-profile-unread-messages-number :count-subscription :get-profile-unread-messages-number
:accessibility-label :profile-tab-button} :accessibility-label :profile-tab-button}]
{:nav-stack :status-stack
:content {:title (i18n/label :t/status)
:icon :main-icons/status}
:accessibility-label :status-tab-button}]
(remove nil?) (remove nil?)
(map-indexed vector))) (map-indexed vector)))

View File

@ -19,7 +19,7 @@
(re-frame/dispatch [:chat.ui/fill-gaps ids])))) (re-frame/dispatch [:chat.ui/fill-gaps ids]))))
(views/defview gap (views/defview gap
[{:keys [gaps first-gap?]} idx list-ref] [{:keys [gaps first-gap?]} idx list-ref timeline]
(views/letsubs [range [:chats/range] (views/letsubs [range [:chats/range]
{:keys [might-have-join-time-messages?]} [:chats/current-raw-chat] {:keys [might-have-join-time-messages?]} [:chats/current-raw-chat]
in-progress? [:chats/fetching-gap-in-progress? in-progress? [:chats/fetching-gap-in-progress?
@ -40,8 +40,8 @@
[react/nested-text [react/nested-text
{:style (style/gap-text connected?)} {:style (style/gap-text connected?)}
(i18n/label (if first-gap? (i18n/label (if first-gap?
:t/load-more-messages (if timeline :t/load-more-timeline :t/load-more-messages)
:t/fetch-messages)) (if timeline :t/fetch-timeline :t/fetch-messages)))
(when first-gap? (when first-gap?
[{:style style/date} [{:style style/date}
(let [date (datetime/timestamp->long-date (let [date (datetime/timestamp->long-date

View File

@ -57,7 +57,7 @@
:type :secondary} :type :secondary}
(i18n/label :t/dont-ask)]]) (i18n/label :t/dont-ask)]])
(defview link-preview-loader [link outgoing] (defview link-preview-loader [link outgoing timeline]
(letsubs [cache [:link-preview/cache]] (letsubs [cache [:link-preview/cache]]
(let [{:keys [site title thumbnailUrl error] :as preview-data} (get cache link)] (let [{:keys [site title thumbnailUrl error] :as preview-data} (get cache link)]
(if (not preview-data) (if (not preview-data)
@ -71,7 +71,7 @@
(re-frame/dispatch (re-frame/dispatch
[:browser.ui/message-link-pressed link]))} [:browser.ui/message-link-pressed link]))}
[react/view (styles/link-preview-wrapper outgoing) [react/view (styles/link-preview-wrapper outgoing timeline)
[react/image {:source {:uri thumbnailUrl} [react/image {:source {:uri thumbnailUrl}
:style (styles/link-preview-image outgoing) :style (styles/link-preview-image outgoing)
:accessibility-label :member-photo}] :accessibility-label :member-photo}]
@ -83,7 +83,7 @@
:style styles/link-preview-site} :style styles/link-preview-site}
site]]]))))) site]]])))))
(defview link-preview-wrapper [links outgoing] (defview link-preview-wrapper [links outgoing timeline]
(letsubs (letsubs
[ask-user? [:link-preview/link-preview-request-enabled] [ask-user? [:link-preview/link-preview-request-enabled]
whitelist [:link-preview/whitelist] whitelist [:link-preview/whitelist]
@ -93,6 +93,6 @@
{:keys [link whitelisted enabled]} link-info] {:keys [link whitelisted enabled]} link-info]
(when (and link whitelisted) (when (and link whitelisted)
(if enabled (if enabled
[link-preview-loader link outgoing] [link-preview-loader link outgoing timeline]
(when ask-user? (when ask-user?
[link-preview-enable-request]))))))) [link-preview-enable-request])))))))

View File

@ -234,24 +234,31 @@
;;MESSAGE CONTENT ;;MESSAGE CONTENT
[react/view [react/view
content] content]
[link-preview/link-preview-wrapper (:links (:content message)) outgoing]]] [link-preview/link-preview-wrapper (:links (:content message)) outgoing false]]]
; delivery status ; delivery status
[react/view (style/delivery-status outgoing) [react/view (style/delivery-status outgoing)
[message-delivery-status message]]]) [message-delivery-status message]]])
(def image-max-width 260)
(def image-max-height 192)
(defn image-set-size [dimensions]
(fn [width height]
(when (< width height)
;; if width less than the height we reduce width proportionally to height
(let [k (/ height image-max-height)]
(when (not= (/ width k) (first @dimensions))
(reset! dimensions [(/ width k) image-max-height]))))))
(defn message-content-image [{:keys [content outgoing] :as message} {:keys [on-long-press]}] (defn message-content-image [{:keys [content outgoing] :as message} {:keys [on-long-press]}]
(let [dimensions (reagent/atom [260 260]) (let [dimensions (reagent/atom [image-max-width image-max-height])
visible (reagent/atom false) visible (reagent/atom false)
uri (:image content)] uri (:image content)]
(react/image-get-size (react/image-get-size uri (image-set-size dimensions))
uri
(fn [width height]
(reset! dimensions [width height])))
(fn [] (fn []
(let [k (/ (max (first @dimensions) (second @dimensions)) 260) (let [style-opts {:outgoing outgoing
style-opts {:outgoing outgoing :width (first @dimensions)
:width (/ (first @dimensions) k) :height (second @dimensions)}]
:height (/ (second @dimensions) k)}]
[:<> [:<>
[preview/preview-image {:message message [preview/preview-image {:message message
:visible @visible :visible @visible
@ -261,13 +268,12 @@
(reset! visible true) (reset! visible true)
(react/dismiss-keyboard!)) (react/dismiss-keyboard!))
:on-long-press on-long-press} :on-long-press on-long-press}
[react/view {:style (style/image-message style-opts) [react/view {:style (style/image-message style-opts)
:accessibility-label :message-image} :accessibility-label :message-image}
[react/image {:style {:width (/ (first @dimensions) k) [react/image {:style (dissoc style-opts :outgoing)
:height (/ (second @dimensions) k)} :resize-mode :cover
:resize-mode :contain :source {:uri uri}}
:source {:uri uri}}] [react/view {:style (style/image-message-border style-opts)}]]]]]))))
[react/view {:style (style/image-message-border style-opts)}]]]]))))
(defmulti ->message :content-type) (defmulti ->message :content-type)

View File

@ -4,8 +4,8 @@
[quo.react-native :as rn] [quo.react-native :as rn]
[quo.core :as quo])) [quo.core :as quo]))
(defn reaction [{:keys [outgoing]} {:keys [own emoji-id quantity]}] (defn reaction [{:keys [outgoing]} {:keys [own emoji-id quantity]} timeline]
[rn/view {:style (styles/reaction-style {:outgoing outgoing [rn/view {:style (styles/reaction-style {:outgoing (and outgoing (not timeline))
:own own})} :own own})}
[rn/image {:source (get constants/reactions emoji-id) [rn/image {:source (get constants/reactions emoji-id)
:style {:width 16 :style {:width 16
@ -20,4 +20,4 @@
[rn/view {:style (styles/reactions-row message timeline)} [rn/view {:style (styles/reactions-row message timeline)}
(for [emoji-reaction reactions] (for [emoji-reaction reactions]
^{:key (str emoji-reaction)} ^{:key (str emoji-reaction)}
[reaction message emoji-reaction])])) [reaction message emoji-reaction timeline])]))

View File

@ -73,7 +73,7 @@
{:justify-content :flex-end} {:justify-content :flex-end}
{:justify-content :flex-start}) {:justify-content :flex-start})
(if (or display-photo? timeline) (if (or display-photo? timeline)
{:padding-left (+ 16 photos/default-size)} {:padding-left (+ 16 photos/default-size (when timeline 8))}
{:padding-left 8}))) {:padding-left 8})))
(defn reaction-button [active] (defn reaction-button [active]
@ -102,12 +102,12 @@
:height 94 :height 94
:align-self :center}) :align-self :center})
(defn link-preview-wrapper [outgoing] (defn link-preview-wrapper [outgoing timeline]
{:overflow :hidden {:overflow :hidden
:border-top-left-radius 16 :border-top-left-radius 16
:border-top-right-radius 16 :border-top-right-radius 16
:border-bottom-left-radius (if outgoing 16 4) :border-bottom-left-radius (if timeline 16 (if outgoing 16 4))
:border-bottom-right-radius (if outgoing 4 16) :border-bottom-right-radius (if timeline 16 (if outgoing 4 16))
:border-width 1 :border-width 1
:border-color components.colors/gray-lighter :border-color components.colors/gray-lighter
:margin-vertical 4 :margin-vertical 4

View File

@ -299,7 +299,7 @@
(defn image-message (defn image-message
[{:keys [outgoing width height]}] [{:keys [outgoing width height]}]
{:overflow "hidden" {:overflow :hidden
:border-top-left-radius 16 :border-top-left-radius 16
:border-top-right-radius 16 :border-top-right-radius 16
:border-bottom-left-radius (if outgoing 16 4) :border-bottom-left-radius (if outgoing 16 4)
@ -309,9 +309,9 @@
(defn image-message-border [opts] (defn image-message-border [opts]
(merge (image-message opts) (merge (image-message opts)
{:position :absolute {:border-width 1
:top 0 :top 0
:left 0 :left 0
:background-color "transparent" :position :absolute
:border-width 1 :background-color :transparent
:border-color colors/black-transparent})) :border-color colors/black-transparent}))

View File

@ -178,7 +178,7 @@
(if (= type :datemark) (if (= type :datemark)
[message-datemark/chat-datemark (:value message)] [message-datemark/chat-datemark (:value message)]
(if (= type :gap) (if (= type :gap)
[gap/gap message idx messages-list-ref] [gap/gap message idx messages-list-ref false]
; message content ; message content
[message/chat-message [message/chat-message
(assoc message (assoc message

View File

@ -46,12 +46,12 @@
{:name :wallet-stack {:name :wallet-stack
:insets {:top false} :insets {:top false}
:component wallet-stack/wallet-stack} :component wallet-stack/wallet-stack}
{:name :profile-stack
:insets {:top false}
:component profile-stack/profile-stack}
{:name :status-stack {:name :status-stack
:insets {:top false} :insets {:top false}
:component status-stack/status-stack}]]) :component status-stack/status-stack}
{:name :profile-stack
:insets {:top false}
:component profile-stack/profile-stack}]])
(views/defview get-main-component [_] (views/defview get-main-component [_]
(views/letsubs [logged-in? [:multiaccount/logged-in?]] (views/letsubs [logged-in? [:multiaccount/logged-in?]]

View File

@ -25,32 +25,50 @@
[status-im.chat.models :as chat])) [status-im.chat.models :as chat]))
(defonce messages-list-ref (atom nil)) (defonce messages-list-ref (atom nil))
(def image-max-dimension 260) (def image-max-dimension 192)
(def image-sizes (atom {}))
(defn image-set-size [dimensions uri]
(fn [width height]
(swap! image-sizes assoc uri {:initialized? true})
(when (< width height)
;; if width less than the height we reduce width proportionally to height
(let [k (/ height image-max-dimension)]
(when (not= (/ width k) (first @dimensions))
(swap! image-sizes assoc uri {:width (/ width k)})
(reset! dimensions [(/ width k) image-max-dimension]))))))
(defn message-content-image [uri _] (defn message-content-image [uri _]
(let [dimensions (reagent/atom [image-max-dimension image-max-dimension])] (let [stored-image (get @image-sizes uri)
(react/image-get-size dimensions (reagent/atom [nil image-max-dimension])]
uri (if stored-image
(fn [width height] (reset! dimensions [(:width stored-image) image-max-dimension])
(let [k (/ (max width height) image-max-dimension)] (js/setTimeout #(react/image-get-size uri (image-set-size dimensions uri)) 20))
(reset! dimensions [(/ width k) (/ height k)]))))
(fn [uri show-close?] (fn [uri show-close?]
[react/view [react/view {:style {:width (first @dimensions)
[react/view {:style {:width (first @dimensions) :height image-max-dimension
:height (last @dimensions) :overflow :hidden
:border-width 1 :border-radius 16
:border-color colors/black-transparent :margin-top 8}
:overflow :hidden :accessibility-label :message-image}
:border-radius 16 [react/image {:style {:width (first @dimensions)
:margin-top 8} :height image-max-dimension}
:accessibility-label :message-image} :cache :force-cache
[react/image {:style {:width (first @dimensions) :height (last @dimensions)} :resize-mode :cover
:resize-mode :contain :source {:uri uri}}]
:source {:uri uri}}]] [react/view {:border-width 1
:top 0
:left 0
:width (first @dimensions)
:height image-max-dimension
:border-radius 16
:position :absolute
:background-color :transparent
:border-color colors/black-transparent}]
(when show-close? (when show-close?
[react/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/cancel-sending-image]) [react/touchable-highlight {:on-press #(re-frame/dispatch [:chat.ui/cancel-sending-image])
:accessibility-label :cancel-send-image :accessibility-label :cancel-send-image
:style {:left (- (first @dimensions) 28) :top 12 :position :absolute}} :style {:right 4 :top 12 :position :absolute}}
[react/view {:width 24 [react/view {:width 24
:height 24 :height 24
:background-color colors/black-persist :background-color colors/black-persist
@ -82,12 +100,12 @@
:on-long-press #(on-long-press-fn on-long-press content true)} :on-long-press #(on-long-press-fn on-long-press content true)}
[message-content-image (:image content) false]]]))) [message-content-image (:image content) false]]])))
(defn message-item [timeline? account] (defn message-item [account]
(fn [{:keys [content-type content from timestamp identicon outgoing] :as message} (fn [{:keys [content-type content from timestamp identicon outgoing] :as message}
{:keys [modal on-long-press close-modal]}] {:keys [modal on-long-press close-modal]}]
[react/view (merge {:padding-vertical 8 [react/view (merge {:padding-vertical 8
:flex-direction :row :flex-direction :row
:background-color (if (and timeline? outgoing) colors/blue-light colors/white) :background-color (when modal colors/white)
:padding-horizontal 16} :padding-horizontal 16}
(when modal (when modal
{:border-radius 16})) {:border-radius 16}))
@ -115,7 +133,7 @@
[react/touchable-highlight (when-not modal [react/touchable-highlight (when-not modal
{:on-long-press #(on-long-press-fn on-long-press content false)}) {:on-long-press #(on-long-press-fn on-long-press content false)})
[message/render-parsed-text (assoc message :outgoing false) (:parsed-text content)]]) [message/render-parsed-text (assoc message :outgoing false) (:parsed-text content)]])
[link-preview/link-preview-wrapper (:links content) outgoing]]]])) [link-preview/link-preview-wrapper (:links content) outgoing true]]]]))
(defn render-message [timeline? account] (defn render-message [timeline? account]
(fn [{:keys [type] :as message} idx] (fn [{:keys [type] :as message} idx]
@ -125,7 +143,7 @@
(if (= type :gap) (if (= type :gap)
(if timeline? (if timeline?
nil nil
[gap/gap message idx messages-list-ref]) [gap/gap message idx messages-list-ref true])
; message content ; message content
(let [chat-id (chat/profile-chat-topic (:from message))] (let [chat-id (chat/profile-chat-topic (:from message))]
[react/view (merge {:accessibility-label :chat-item} [react/view (merge {:accessibility-label :chat-item}
@ -151,7 +169,7 @@
:chat-id chat-id :chat-id chat-id
:emoji-id emoji-id :emoji-id emoji-id
:emoji-reaction-id emoji-reaction-id}])) :emoji-reaction-id emoji-reaction-id}]))
:render (message-item timeline? account)}]]))))])) :render (message-item account)}]]))))]))
(def state (reagent/atom {:tab :timeline})) (def state (reagent/atom {:tab :timeline}))

View File

@ -469,6 +469,7 @@
"failed": "Failed", "failed": "Failed",
"faq": "Frequently asked questions", "faq": "Frequently asked questions",
"fetch-messages": "↓ Fetch messages", "fetch-messages": "↓ Fetch messages",
"fetch-timeline": "↓ Fetch",
"find": "Find", "find": "Find",
"finish": "Finish", "finish": "Finish",
"finishing-card-setup": "Finishing card setup", "finishing-card-setup": "Finishing card setup",
@ -677,6 +678,7 @@
"linked-on": "Linked on {{date}}", "linked-on": "Linked on {{date}}",
"load-messages-before": "before {{date}}", "load-messages-before": "before {{date}}",
"load-more-messages": "↓ Fetch more messages", "load-more-messages": "↓ Fetch more messages",
"load-more-timeline": "↓ Fetch more",
"loading": "Loading...", "loading": "Loading...",
"log-level": "Log level", "log-level": "Log level",
"log-level-settings": "Log level settings", "log-level-settings": "Log level settings",