From 8957e00592032d2013d57c4ac4d0b9e6f2d4e6e2 Mon Sep 17 00:00:00 2001 From: Gustavo Nunes Date: Wed, 8 Feb 2017 22:58:58 -0200 Subject: [PATCH] Fix #774 - Profile and drawer input inconsistencies --- src/status_im/components/drawer/view.cljs | 7 +++++-- src/status_im/components/text_field/view.cljs | 5 ++++- src/status_im/profile/screen.cljs | 1 + src/status_im/profile/validations.cljs | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/status_im/components/drawer/view.cljs b/src/status_im/components/drawer/view.cljs index f379d868a7..9977df928a 100644 --- a/src/status_im/components/drawer/view.cljs +++ b/src/status_im/components/drawer/view.cljs @@ -73,8 +73,10 @@ :wrapper-style st/name-input-wrapper :value (or new-name name) :on-change-text #(dispatch [:set-in [:profile-edit :name] %]) - :on-end-editing #(when (s/valid? ::v/name new-name) - (dispatch [:account-update {:name (clean-text new-name)}]))}]] + :on-end-editing #(do + (dispatch [:set-in [:profile-edit :name] nil]) + (when (s/valid? ::v/name new-name) + (dispatch [:account-update {:name (clean-text new-name)}])))}]] [view st/status-container (if @status-edit? [text-input {:style st/status-input @@ -114,6 +116,7 @@ [view st/switch-users-container [touchable-opacity {:onPress (fn [] (close-drawer) + (dispatch [:set-in [:profile-edit :name] nil]) (dispatch [:navigate-to :accounts]))} [text {:style st/switch-users-text :font :default} diff --git a/src/status_im/components/text_field/view.cljs b/src/status_im/components/text_field/view.cljs index f80b7f7152..7ad2ac9c16 100644 --- a/src/status_im/components/text_field/view.cljs +++ b/src/status_im/components/text_field/view.cljs @@ -95,6 +95,7 @@ (defn reagent-render [_ _] (let [component (r/current-component) + input-ref (r/atom nil) {:keys [float-label? label-top label-font-size @@ -112,7 +113,8 @@ [view (merge st/text-field-container wrapper-style) (when-not label-hidden? [animated-text {:style (st/label label-top label-font-size label-color)} label]) - [text-input {:style (merge st/text-input input-style) + [text-input {:ref #(reset! input-ref %) + :style (merge st/text-input input-style) :placeholder (or placeholder "") :editable editable :secure-text-entry secure-text-entry @@ -138,6 +140,7 @@ (on-change-text text)) :on-change #(on-change %) :default-value value + :on-submit-editing #(.blur @input-ref) :on-end-editing (when on-end-editing on-end-editing)}] [view {:style (st/underline-container line-color) diff --git a/src/status_im/profile/screen.cljs b/src/status_im/profile/screen.cljs index afa24d8878..5378e78325 100644 --- a/src/status_im/profile/screen.cljs +++ b/src/status_im/profile/screen.cljs @@ -191,6 +191,7 @@ qr [:get-in [:profile-edit :qr-code]] current-account [:get-current-account] changed-account [:get :profile-edit]] + {:component-will-unmount #(dispatch [:set-in [:profile-edit :name] nil])} (let [{:keys [phone address public-key] diff --git a/src/status_im/profile/validations.cljs b/src/status_im/profile/validations.cljs index 3f7be3cf98..fc65d1d0e1 100644 --- a/src/status_im/profile/validations.cljs +++ b/src/status_im/profile/validations.cljs @@ -6,7 +6,7 @@ [status-im.utils.homoglyph :as h])) (defn correct-name? [username] - (let [username (some-> username (str/trim))] + (when-let [username (some-> username (str/trim))] (every? false? [(str/blank? username) (h/matches username console-chat-id)