Skip to content
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

fix subs bug #15680

Merged
merged 3 commits into from
Apr 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/status_im2/common/toasts/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
[:f>
(fn []
(let [duration (or (rf/sub [:toasts/toast-cursor id :duration]) 3000)
on-dismissed #((or (rf/sub [:toasts/toast-cursor id :on-dismissed]) identity) id)
on-dismissed (or (rf/sub [:toasts/toast-cursor id :on-dismissed]) identity)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the fix

create-timer (fn []
(reset! timer (utils.utils/set-timeout close! duration)))
translate-y (reanimated/use-shared-value 0)
Expand Down Expand Up @@ -80,7 +80,7 @@
(create-timer)))))]
;; create auto dismiss timer, clear timer when unmount or duration changed
(rn/use-effect (fn [] (create-timer) clear-timer) [duration])
(rn/use-unmount on-dismissed)
(rn/use-unmount #(on-dismissed id))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to pass the id here and create the anonymous function? It's questionable because the subscription [:toasts/toast-cursor id :on-dismissed] already returns a function that has access to the id value and the identity function doesn't care about any argument in this case.

I'm just wondering why it wouldn't work using just (rn/use-unmount on-dismissed).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just to handle situations where id and on-dismissed are both dynamically generated and hard or not elegant enough to pass the id to the on-dismissed fn.
It might be a premature optimization.

[gesture/gesture-detector {:gesture pan}
[reanimated/view
{;; TODO: this will enable layout animation at runtime and causing flicker on android
Expand All @@ -100,4 +100,5 @@
[into
[rn/view
{:style style/outmost-transparent-container}]
(map (fn [id] ^{:key id} [container id]) toasts-ordered)]))
(doall
(map (fn [id] ^{:key id} [container id]) toasts-ordered))]))