-
Notifications
You must be signed in to change notification settings - Fork 1k
[#22404] [News Feed] Implement News AC component #22453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
(ns status-im.contexts.shell.activity-center.notification.news.view | ||
(:require [clojure.string :as string] | ||
[promesa.core :as promesa] | ||
[quo.core :as quo] | ||
[react-native.core :as rn] | ||
[react-native.gesture :as gesture] | ||
[status-im.contexts.shell.activity-center.notification.common.view :as common] | ||
[utils.datetime :as datetime] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn auto-resized-image | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use custom hooks more often, even if they will be used only once, since a hook is just a function anyway. The following is untested code. This allows us to decouple state management & effects from hiccup. Note: untested code. (defn- use-auto-image-height
[url]
(let [[height set-height] (rn/use-state nil)
window-width (- (:width (rn/get-window)) 40)]
(rn/use-effect
(fn []
(-> (rn/image-get-size url)
(promesa/then (fn [[w h]]
(let [scale (/ window-width w)
new-height (* h scale)]
(set-height new-height))))))
[url])
{:height height
:width window-width}))
(defn auto-resized-image
[url]
(let [{:keys [height width]} (use-auto-image-height url)]
(if height
[rn/image
{:resize-mode :contain
:style {:width width
:height height
:align-self :center
:border-radius 12}
:source url}]
[rn/view {:style {:height 200 :align-items :center :justify-content :center}}
[rn/activity-indicator]]))) |
||
[url] | ||
(let [[height set-height] (rn/use-state nil) | ||
window-width (- (:width (rn/get-window)) 40)] | ||
(rn/use-effect #(-> (rn/image-get-size url) | ||
(promesa/then (fn [[w h]] | ||
(let [scale (/ window-width w) | ||
new-height (* h scale)] | ||
(set-height new-height)))))) | ||
(if height | ||
[rn/image | ||
{:resize-mode :contain | ||
:style {:width window-width | ||
:height height | ||
:align-self :center | ||
:border-radius 12} | ||
:source url}] | ||
[rn/view {:style {:height 200 :align-items :center :justify-content :center}} | ||
[rn/activity-indicator]]))) | ||
|
||
(defn sheet | ||
[{:keys [news-image-url news-title news-content news-link news-link-label]} timestamp] | ||
(let [customization-color (rf/sub [:profile/customization-color])] | ||
[:<> | ||
[quo/drawer-top {:title news-title :description timestamp}] | ||
[rn/scroll-view {:style {:flex 1}} | ||
(when (not (string/blank? news-image-url)) | ||
[auto-resized-image news-image-url]) | ||
[quo/text | ||
{:style {:padding-horizontal 20 | ||
:padding-vertical 8}} | ||
news-content]] | ||
(when (and (not (string/blank? news-link)) (not (string/blank? news-link-label))) | ||
[quo/bottom-actions | ||
{:button-one-label news-link-label | ||
:button-one-props {:customization-color customization-color | ||
:icon-right :i/external | ||
:on-press (fn [] | ||
(rf/dispatch [:browser.ui/open-url news-link]) | ||
(rf/dispatch [:hide-bottom-sheet]))}}])])) | ||
|
||
(defn view | ||
[{:keys [notification extra-fn]}] | ||
(let [customization-color (rf/sub [:profile/customization-color]) | ||
{:keys [news-title | ||
news-description | ||
timestamp | ||
read | ||
id]} notification | ||
timestamp (datetime/timestamp->relative timestamp) | ||
on-press (rn/use-callback | ||
(fn [] | ||
(rf/dispatch [:activity-center.notifications/mark-as-read id]) | ||
(rf/dispatch [:show-bottom-sheet | ||
{:theme :dark | ||
:content (fn [] | ||
[sheet notification timestamp])}])))] | ||
[common/swipeable | ||
{:left-button common/swipe-button-read-or-unread | ||
:left-on-press common/swipe-on-press-toggle-read | ||
:right-button common/swipe-button-delete | ||
:right-on-press common/swipe-on-press-delete | ||
:extra-fn extra-fn} | ||
[gesture/touchable-without-feedback | ||
{:on-press on-press} | ||
[quo/activity-log | ||
{:title news-title | ||
:customization-color customization-color | ||
:icon :i/status-logo-bw | ||
:timestamp timestamp | ||
:unread? (not read) | ||
:context [[quo/text {} news-description]] | ||
:items [{:type :button | ||
:subtype :primary | ||
:key :button-reply | ||
:customization-color customization-color | ||
:label (i18n/label :t/read-more) | ||
:accessibility-label :read-more | ||
:on-press on-press}]}]]])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sharing for awareness: it's not the first time I see an opportunity to make
settings_saveSetting
support multiple settings at once so that we can do one atomic update.