<commit_before>(ns status-im.ui.components.bottom-panel.views
  (:require-macros [status-im.utils.views :as views])
  (:require [status-im.ui.components.react :as react]
            [status-im.ui.components.animation :as anim]
            [reagent.core :as reagent]))

(defn hide-panel-anim
  [bottom-anim-value alpha-value window-height]
  (anim/start
   (anim/parallel
    [(anim/spring bottom-anim-value {:toValue         (- window-height)
                                     :useNativeDriver true})
     (anim/timing alpha-value {:toValue         0
                               :duration        500
                               :useNativeDriver true})])))

(defn show-panel-anim
  [bottom-anim-value alpha-value]
  (anim/start
   (anim/parallel
    [(anim/spring bottom-anim-value {:toValue         40
                                     :useNativeDriver true})
     (anim/timing alpha-value {:toValue         0.4
                               :duration        500
                               :useNativeDriver true})])))

(defn bottom-panel [obj render window-height]
  (let [bottom-anim-value (anim/create-value window-height)
        alpha-value       (anim/create-value 0)
        clear-timeout     (atom nil)
        update?           (atom nil)
        current-obj       (reagent/atom nil)]
    (reagent/create-class
     {:component-will-update (fn [_ [_ obj _ _]]
                               (when @clear-timeout (js/clearTimeout @clear-timeout))
                               (when (or (not= obj @current-obj) @update?)
                                 (cond
                                   @update?
                                   (do (reset! update? false)
                                       (show-panel-anim bottom-anim-value alpha-value))

                                   (and @current-obj obj)
                                   (do (reset! update? true)
                                       (js/setTimeout #(reset! current-obj obj) 600)
                                       (hide-panel-anim bottom-anim-value alpha-value (- window-height)))

                                   obj
                                   (do (reset! current-obj obj)
                                       (show-panel-anim bottom-anim-value alpha-value))

                                   :else
                                   (do (reset! clear-timeout (js/setTimeout #(reset! current-obj nil) 600))
                                       (hide-panel-anim bottom-anim-value alpha-value (- window-height))))))
      :reagent-render        (fn []
                               (when @current-obj
                                 [react/keyboard-avoiding-view {:style {:position :absolute :top 0 :bottom 0 :left 0 :right 0}}
                                  [react/view {:flex 1}
                                   [react/animated-view {:flex 1 :background-color :black :opacity alpha-value}]
                                   [react/animated-view {:style {:position  :absolute
                                                                 :transform [{:translateY bottom-anim-value}]
                                                                 :bottom 0 :left 0 :right 0}}
                                    [react/view {:flex 1}
                                     [render @current-obj]]]]]))})))

(views/defview animated-bottom-panel [val signing-view]
  (views/letsubs [{window-height :height} [:dimensions/window]]
    [bottom-panel (when val (select-keys val [:from :contact :amount :token :approve? :message])) signing-view window-height]))
<commit_msg>[#9759] App freezes if tap on digital keyboard after "Cancel" on Send Transaction screen<commit_after>(ns status-im.ui.components.bottom-panel.views
  (:require-macros [status-im.utils.views :as views])
  (:require [status-im.ui.components.react :as react]
            [status-im.ui.components.animation :as anim]
            [reagent.core :as reagent]))

(defn hide-panel-anim
  [bottom-anim-value alpha-value window-height]
  (react/dismiss-keyboard!)
  (anim/start
   (anim/parallel
    [(anim/spring bottom-anim-value {:toValue         (- window-height)
                                     :useNativeDriver true})
     (anim/timing alpha-value {:toValue         0
                               :duration        500
                               :useNativeDriver true})])))

(defn show-panel-anim
  [bottom-anim-value alpha-value]
  (anim/start
   (anim/parallel
    [(anim/spring bottom-anim-value {:toValue         40
                                     :useNativeDriver true})
     (anim/timing alpha-value {:toValue         0.4
                               :duration        500
                               :useNativeDriver true})])))

(defn bottom-panel [obj render window-height]
  (let [bottom-anim-value (anim/create-value window-height)
        alpha-value       (anim/create-value 0)
        clear-timeout     (atom nil)
        update?           (atom nil)
        current-obj       (reagent/atom nil)]
    (reagent/create-class
     {:component-will-update (fn [_ [_ obj _ _]]
                               (when @clear-timeout (js/clearTimeout @clear-timeout))
                               (when (or (not= obj @current-obj) @update?)
                                 (cond
                                   @update?
                                   (do (reset! update? false)
                                       (show-panel-anim bottom-anim-value alpha-value))

                                   (and @current-obj obj)
                                   (do (reset! update? true)
                                       (js/setTimeout #(reset! current-obj obj) 600)
                                       (hide-panel-anim bottom-anim-value alpha-value (- window-height)))

                                   obj
                                   (do (reset! current-obj obj)
                                       (show-panel-anim bottom-anim-value alpha-value))

                                   :else
                                   (do (reset! clear-timeout (js/setTimeout #(reset! current-obj nil) 600))
                                       (hide-panel-anim bottom-anim-value alpha-value (- window-height))))))
      :reagent-render        (fn []
                               (when @current-obj
                                 [react/keyboard-avoiding-view {:style {:position :absolute :top 0 :bottom 0 :left 0 :right 0}}
                                  [react/view {:flex 1}
                                   [react/animated-view {:flex 1 :background-color :black :opacity alpha-value}]
                                   [react/animated-view {:style {:position  :absolute
                                                                 :transform [{:translateY bottom-anim-value}]
                                                                 :bottom 0 :left 0 :right 0}}
                                    [react/view {:flex 1}
                                     [render @current-obj]]]]]))})))

(views/defview animated-bottom-panel [val signing-view]
  (views/letsubs [{window-height :height} [:dimensions/window]]
    [bottom-panel (when val (select-keys val [:from :contact :amount :token :approve? :message])) signing-view window-height]))

{'fraction_non_alphanumeric': 0.10702066511564254, 'fraction_numerical': 0.008211304228821678, 'mean_word_length': 1.1653333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 52, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6641630', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1731, 'n_words': 420}