Skip to content

Commit

Permalink
Add init-keyboard-listeners fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesmac committed Nov 10, 2023
1 parent baa9a20 commit b0b3ff2
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions src/status_im2/common/floating_button_page/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@
(let [height (oops/oget event "nativeEvent.layout.height")]
(reset! ratom height))))

(defn- init-keyboard-listeners
[{:keys [on-did-show]}]
(let [keyboard-will-show? (reagent/atom false)
keyboard-did-show? (reagent/atom false)
add-listener (fn [listener callback]
(oops/ocall rn/keyboard "addListener" listener callback))
will-show-listener (add-listener "keyboardWillShow"
#(reset! keyboard-will-show? true))
did-show-listener (add-listener "keyboardDidShow"
(fn [e]
(reset! keyboard-did-show? true)
(when on-did-show (on-did-show e))))
will-hide-listener (add-listener "keyboardWillHide"
#(reset! keyboard-will-show? false))
did-hide-listener (add-listener "keyboardDidHide"
#(reset! keyboard-did-show? false))
remove-listeners (fn []
(doseq [listener [will-show-listener will-hide-listener
did-show-listener did-hide-listener]]
(oops/ocall listener "remove")))]
{:keyboard-will-show? keyboard-will-show?
:keyboard-did-show? keyboard-did-show?
:remove-listeners remove-listeners}))

(defn view
[{:keys [header footer]} & children]
(reagent/with-let [window-height (:height (rn/get-window))
Expand All @@ -34,27 +58,13 @@
content-container-height (reagent/atom 0)
content-scroll-y (reagent/atom 0)
keyboard-height (reagent/atom 0)
keyboard-will-show? (reagent/atom false)
keyboard-did-show? (reagent/atom false)
will-show-listener (oops/ocall rn/keyboard
"addListener"
"keyboardWillShow"
#(reset! keyboard-will-show? true))
did-show-listener (oops/ocall rn/keyboard
"addListener"
"keyboardDidShow"
(fn [e]
(reset! keyboard-height
(oops/oget e "endCoordinates.height"))
(reset! keyboard-did-show? true)))
will-hide-listener (oops/ocall rn/keyboard
"addListener"
"keyboardWillHide"
#(reset! keyboard-will-show? false))
did-hide-listener (oops/ocall rn/keyboard
"addListener"
"keyboardDidHide"
#(reset! keyboard-did-show? false))
{:keys [keyboard-will-show?
keyboard-did-show?
remove-listeners]} (init-keyboard-listeners
{:on-did-show
(fn [e]
(reset! keyboard-height
(oops/oget e "endCoordinates.height")))})
set-header-height (set-height-on-layout header-height)
set-content-container-height (set-height-on-layout content-container-height)
set-footer-container-height (set-height-on-layout footer-container-height)
Expand Down Expand Up @@ -89,5 +99,4 @@
:blur? show-background?}
footer]]])
(finally
(doseq [listener [will-show-listener will-hide-listener did-show-listener did-hide-listener]]
(oops/ocall listener "remove")))))
(remove-listeners))))

0 comments on commit b0b3ff2

Please sign in to comment.