diff --git a/components/src/status_im/ui/components/react.cljs b/components/src/status_im/ui/components/react.cljs index 9553758a04..00f2d027db 100644 --- a/components/src/status_im/ui/components/react.cljs +++ b/components/src/status_im/ui/components/react.cljs @@ -126,14 +126,18 @@ [text-class (dissoc options-with-style :nested?)] nested-text-elements))) -(def text-input-refs (atom #{})) +;; We track all currently mounted text input refs +;; in a ref-to-defaultValue map +;; so that we can clear them (restore their default values) +;; when global react-navigation's onWillBlur event is invoked +(def text-input-refs (atom {})) (defn text-input [options text] (let [input-ref (atom nil)] (reagent/create-class {:component-will-unmount #(when @input-ref - (swap! text-input-refs disj @input-ref)) + (swap! text-input-refs dissoc @input-ref)) :reagent-render (fn [options text] [text-input-class @@ -143,11 +147,10 @@ :placeholder-text-color colors/text-gray :placeholder (i18n/label :t/type-a-message) :ref (fn [r] - (if r - (when (nil? @input-ref) - (swap! text-input-refs conj r)) - (when @input-ref - (swap! text-input-refs disj @input-ref))) + ;; Store input and its defaultValue + ;; one we receive a non-nil ref + (when (and r (nil? @input-ref)) + (swap! text-input-refs assoc r (:default-value options))) (reset! input-ref r) (when (:ref options) ((:ref options) r))) diff --git a/src/status_im/ui/screens/add_new/new_chat/views.cljs b/src/status_im/ui/screens/add_new/new_chat/views.cljs index 178c8d475d..662417f05e 100644 --- a/src/status_im/ui/screens/add_new/new_chat/views.cljs +++ b/src/status_im/ui/screens/add_new/new_chat/views.cljs @@ -37,6 +37,9 @@ (re-frame/dispatch [:contact.ui/contact-code-submitted])) :placeholder (i18n/label :t/enter-contact-code) :style (add-new.styles/input @tw) + ;; Set default-value as otherwise it will + ;; be erased in global `onWillBlur` handler + :default-value new-identity :accessibility-label :enter-contact-code-input :return-key-type :go}]] (when-not platform/desktop? diff --git a/src/status_im/ui/screens/add_new/new_public_chat/view.cljs b/src/status_im/ui/screens/add_new/new_public_chat/view.cljs index 7046d04a5c..f0232086b4 100644 --- a/src/status_im/ui/screens/add_new/new_public_chat/view.cljs +++ b/src/status_im/ui/screens/add_new/new_public_chat/view.cljs @@ -34,6 +34,9 @@ :auto-capitalize :none :auto-focus false :accessibility-label :chat-name-input + ;; Set default-value as otherwise it will + ;; be erased in global `onWillBlur` handler + :default-value topic :placeholder nil :return-key-type :go :auto-correct false}]]] diff --git a/src/status_im/ui/screens/routing/core.cljs b/src/status_im/ui/screens/routing/core.cljs index 4ae7f05296..b01e4def67 100644 --- a/src/status_im/ui/screens/routing/core.cljs +++ b/src/status_im/ui/screens/routing/core.cljs @@ -40,8 +40,10 @@ :on-will-blur (fn [] (reset! screen-focused? false) - (doseq [text-input @react/text-input-refs] - (.clear text-input)))}]) + ;; Reset currently mounted text inputs to their default values + ;; on navigating away; this is a privacy measure + (doseq [[text-input default-value] @react/text-input-refs] + (.setNativeProps text-input (clj->js {:text default-value}))))}]) (defn wrap "Wraps screen with main view and adds navigation-events component"