Clear all TextInput refs in on-will-blur event
Signed-off-by: Vitaliy Vlasov <siphiuel@gmail.com>
This commit is contained in:
parent
2b34900a9b
commit
697c767a8b
|
@ -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]}]
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue