Detect image dimensions correctly

This commit is contained in:
alwx 2023-11-22 10:38:14 +01:00 committed by Andrea Maria Piana
parent dbc8df251a
commit 671aa67002
No known key found for this signature in database
1 changed files with 10 additions and 1 deletions

View File

@ -8,6 +8,10 @@
[utils.re-frame :as rf]
[utils.url :as url]))
;; these constants are used when there is no width or height defined for a specific image
(def ^:const fallback-image-width 1000)
(def ^:const fallback-image-height 1000)
(defn calculate-dimensions
[width height max-container-width max-container-height]
(let [max-width (if (> width height) max-container-width (* 1.5 constants/image-size))
@ -15,7 +19,12 @@
{:width (min width max-width) :height (min height max-height)}))
(defn image-message
[index {:keys [content image-width image-height message-id] :as message} {:keys [on-long-press]}
[index
{:keys [content image-width image-height message-id]
:as message
:or {image-width fallback-image-width
image-height fallback-image-height}}
{:keys [on-long-press]}
message-container-data]
(let [insets (safe-area/get-insets)
{:keys [window-width padding-left padding-right avatar-container-width