Clear all TextInput refs in on-will-blur event

Signed-off-by: Vitaliy Vlasov <siphiuel@gmail.com>
This commit is contained in:
Vitaliy Vlasov 2019-08-19 13:55:40 +03:00
parent 2b34900a9b
commit 697c767a8b
No known key found for this signature in database
GPG Key ID: A7D57C347F2B2964
2 changed files with 32 additions and 11 deletions

View File

@ -144,18 +144,36 @@
[text-class (dissoc options-with-style :nested?)]
nested-text-elements)))
(def text-input-refs (atom #{}))
(defn text-input
[options text]
[(text-input-class)
(merge
{:underline-color-android :transparent
:max-font-size-multiplier max-font-size-multiplier
:placeholder-text-color colors/text-gray
:placeholder (i18n/label :t/type-a-message)
:value text}
(-> options
(update :style typography/get-style)
(update :style dissoc :line-height)))])
(let [input-ref (atom nil)]
(reagent/create-class
{:component-will-unmount #(when @input-ref
(swap! text-input-refs disj @input-ref))
:reagent-render
(fn [options text]
[(text-input-class)
(merge
{:underline-color-android :transparent
:max-font-size-multiplier max-font-size-multiplier
: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)))
(reset! input-ref r)
(when (:ref options)
((:ref options) r)))
:value text}
(-> options
(dissoc :ref)
(update :style typography/get-style)
(update :style dissoc :line-height)))])})))
(defn i18n-text
[{:keys [style key]}]

View File

@ -38,7 +38,10 @@
(when-not modal?
(status-bar/set-status-bar current-view-id)))
:on-will-blur
(fn [] (reset! screen-focused? false))}])
(fn []
(reset! screen-focused? false)
(doseq [text-input @react/text-input-refs]
(.clear text-input)))}])
(defn wrap
"Wraps screen with main view and adds navigation-events component"