From a340e2a55c3933b5431e2373f12a171cb43d19ef Mon Sep 17 00:00:00 2001 From: Parvesh Monu Date: Thu, 13 Jul 2023 14:07:42 +0530 Subject: [PATCH] fix image long press issue and cropping (#16571) --- .../chat/lightbox/zoomable_image/view.cljs | 21 ++++++++++++------- .../chat/messages/content/album/view.cljs | 2 +- .../chat/messages/content/image/view.cljs | 2 +- .../contexts/chat/messages/content/view.cljs | 2 +- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/status_im2/contexts/chat/lightbox/zoomable_image/view.cljs b/src/status_im2/contexts/chat/lightbox/zoomable_image/view.cljs index 1394cb7ca6..cc3aaa76d5 100644 --- a/src/status_im2/contexts/chat/lightbox/zoomable_image/view.cljs +++ b/src/status_im2/contexts/chat/lightbox/zoomable_image/view.cljs @@ -205,7 +205,8 @@ (anim/animate-decay pan-y-start velocity [lower-bound upper-bound])))))))) (defn- f-zoomable-image - [dimensions animations state rescale curr-orientation content focused? index render-data] + [dimensions animations state rescale curr-orientation content focused? index render-data + image-dimensions-nil?] (let [{:keys [transparent? set-full-height?]} render-data portrait? (= curr-orientation orientation/portrait) on-tap #(utils/toggle-opacity index render-data portrait?) @@ -225,9 +226,12 @@ @set-full-height? (= curr-orientation orientation/portrait))} [reanimated/fast-image - {:source {:uri (http/replace-port (:image content) (rf/sub [:mediaserver/port]))} - :native-ID (when focused? :shared-element) - :style (style/image dimensions animations render-data index)}]]])) + (merge + {:source {:uri (http/replace-port (:image content) (rf/sub [:mediaserver/port]))} + :native-ID (when focused? :shared-element) + :style (style/image dimensions animations render-data index)} + (when image-dimensions-nil? + {:resize-mode :contain}))]]])) (defn zoomable-image [] @@ -238,9 +242,12 @@ zoom-out-signal (rf/sub [:lightbox/zoom-out-signal]) {:keys [set-full-height? curr-orientation]} render-data focused? (= shared-element-id message-id) + ;; TODO - remove `image-dimensions` check, + ;; once https://github.com/status-im/status-desktop/issues/10944 is fixed + image-dimensions-nil? (not (and image-width image-height)) dimensions (utils/get-dimensions - (or image-width c/default-dimension) - (or image-height c/default-duration) + (or image-width (:screen-width render-data)) + (or image-height (:screen-height render-data)) curr-orientation render-data) animations (utils/init-animations) @@ -261,4 +268,4 @@ set-full-height?)) (utils/handle-zoom-out-signal zoom-out-signal index (anim/get-val (:scale animations)) rescale) [:f> f-zoomable-image dimensions animations state rescale curr-orientation content focused? - index render-data])))) + index render-data image-dimensions-nil?])))) diff --git a/src/status_im2/contexts/chat/messages/content/album/view.cljs b/src/status_im2/contexts/chat/messages/content/album/view.cljs index 63495f6c91..00e11efab3 100644 --- a/src/status_im2/contexts/chat/messages/content/album/view.cljs +++ b/src/status_im2/contexts/chat/messages/content/album/view.cljs @@ -74,5 +74,5 @@ (map-indexed (fn [index item] [:<> {:key (:message-id item)} - [image/image-message index item #(on-long-press message context)]]) + [image/image-message index item {:on-long-press #(on-long-press message context)}]]) (:album message))]))) diff --git a/src/status_im2/contexts/chat/messages/content/image/view.cljs b/src/status_im2/contexts/chat/messages/content/image/view.cljs index 188dce7d3c..b9c11430ae 100644 --- a/src/status_im2/contexts/chat/messages/content/image/view.cljs +++ b/src/status_im2/contexts/chat/messages/content/image/view.cljs @@ -15,7 +15,7 @@ {:width (min width max-width) :height (min height max-height)})) (defn image-message - [index {:keys [content image-width image-height message-id] :as message} on-long-press] + [index {:keys [content image-width image-height message-id] :as message} {:keys [on-long-press]}] (let [insets (safe-area/get-insets) dimensions (calculate-dimensions (or image-width 1000) (or image-height 1000)) shared-element-id (rf/sub [:shared-element-id]) diff --git a/src/status_im2/contexts/chat/messages/content/view.cljs b/src/status_im2/contexts/chat/messages/content/view.cljs index 9d50243834..48113a1976 100644 --- a/src/status_im2/contexts/chat/messages/content/view.cljs +++ b/src/status_im2/contexts/chat/messages/content/view.cljs @@ -154,7 +154,7 @@ [audio/audio-message message-data context] constants/content-type-image - [image/image-message 0 message-data context on-long-press] + [image/image-message 0 message-data context] constants/content-type-album [album/album-message message-data context on-long-press]