|
89 | 89 |
|
90 | 90 | (defn link-preview-loader
|
91 | 91 | [link _]
|
92 |
| - (reagent/create-class |
93 |
| - {:component-did-mount |
94 |
| - (fn [] |
95 |
| - (rf/dispatch [:chat.ui/load-link-preview-data link])) |
96 |
| - :component-did-update |
97 |
| - (fn [this [_ previous-props]] |
98 |
| - (let [[_ props] (.-argv (.-props ^js this)) |
99 |
| - refresh-photo? (not= previous-props props)] |
100 |
| - (when refresh-photo? |
101 |
| - (rf/dispatch [:chat.ui/load-link-preview-data props])))) |
102 |
| - :reagent-render |
103 |
| - (fn [link {:keys [on-long-press]}] |
104 |
| - (let [cached-preview-data (rf/sub [:link-preview/cache link])] |
105 |
| - (when-let [{:keys [site title thumbnail-url error] :as preview-data} cached-preview-data] |
106 |
| - (when (and (not error) site title) |
107 |
| - [rn/touchable-opacity |
108 |
| - {:style (when-not (is-gif? thumbnail-url) |
109 |
| - {:align-self :stretch}) |
110 |
| - :on-press #(when (security/safe-link? link) |
111 |
| - (rf/dispatch [:browser.ui/message-link-pressed link])) |
112 |
| - :on-long-press on-long-press} |
113 |
| - [rn/view (style/wrapper) |
114 |
| - (when-not (is-gif? thumbnail-url) |
115 |
| - [:<> |
116 |
| - [rn/view (style/title-wrapper) |
117 |
| - [rn/image {:style (style/title-site-image)}] |
118 |
| - [rn/text {:style (style/title-text)} |
119 |
| - site]] |
120 |
| - [rn/text {:style (style/main-text)} |
121 |
| - title] |
122 |
| - [rn/text {:style (style/extra-text)} |
123 |
| - link]]) |
124 |
| - (when-not (string/blank? thumbnail-url) |
125 |
| - [:<> |
126 |
| - [rn/view (style/separator)] |
127 |
| - [fast-image/fast-image |
128 |
| - {:source {:uri thumbnail-url} |
129 |
| - :style (style/image (select-keys preview-data [:height :width])) |
130 |
| - :accessibility-label :member-photo}]])]]))))})) |
| 92 | + (let [measured-width (reagent/atom 0) |
| 93 | + measured-height (reagent/atom 0)] |
| 94 | + (reagent/create-class |
| 95 | + {:component-did-mount |
| 96 | + (fn [] |
| 97 | + (rf/dispatch [:chat.ui/load-link-preview-data link])) |
| 98 | + :component-did-update |
| 99 | + (fn [this [_ previous-props]] |
| 100 | + (let [[_ props] (.-argv (.-props ^js this)) |
| 101 | + refresh-photo? (not= previous-props props)] |
| 102 | + (when refresh-photo? |
| 103 | + (rf/dispatch [:chat.ui/load-link-preview-data props])))) |
| 104 | + :reagent-render |
| 105 | + (fn [link {:keys [on-long-press]}] |
| 106 | + (let [cached-preview-data (rf/sub [:link-preview/cache link])] |
| 107 | + (when-let [{:keys [site title thumbnail-url error]} cached-preview-data] |
| 108 | + (when (and (not error) site title) |
| 109 | + [rn/touchable-opacity |
| 110 | + {:style (when-not (is-gif? thumbnail-url) |
| 111 | + {:align-self :stretch}) |
| 112 | + :on-press #(when (security/safe-link? link) |
| 113 | + (rf/dispatch [:browser.ui/message-link-pressed link])) |
| 114 | + :on-long-press on-long-press} |
| 115 | + [rn/view (style/wrapper) |
| 116 | + (when-not (is-gif? thumbnail-url) |
| 117 | + [:<> |
| 118 | + [rn/view (style/title-wrapper) |
| 119 | + [rn/image {:style (style/title-site-image)}] |
| 120 | + [rn/text {:style (style/title-text)} |
| 121 | + site]] |
| 122 | + [rn/text {:style (style/main-text)} |
| 123 | + title] |
| 124 | + [rn/text {:style (style/extra-text)} |
| 125 | + link]]) |
| 126 | + (when-not (string/blank? thumbnail-url) |
| 127 | + [:<> |
| 128 | + [rn/view (style/separator)] |
| 129 | + [fast-image/fast-image |
| 130 | + {:source {:uri thumbnail-url} |
| 131 | + :on-load (fn [e] |
| 132 | + (let [{:keys [width height]} (js->clj (.-nativeEvent e) |
| 133 | + :keywordize-keys |
| 134 | + true)] |
| 135 | + (reset! measured-width width) |
| 136 | + (reset! measured-height height))) |
| 137 | + :style (style/image {:width @measured-width |
| 138 | + :height @measured-height}) |
| 139 | + :accessibility-label :member-photo}]])]]))))}))) |
131 | 140 |
|
132 | 141 | (defn link-preview-enable-request
|
133 | 142 | []
|
|
0 commit comments