Skip to content

Commit 99250ea

Browse files
committed
fix: blur the composer input when canceling edit
1 parent b84561b commit 99250ea

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

Diff for: src/status_im2/contexts/chat/composer/edit/view.cljs

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[utils.re-frame :as rf]))
1212

1313
(defn edit-message
14-
[state]
14+
[{:keys [text-value input-ref]}]
1515
[rn/view
1616
{:style style/container
1717
:accessibility-label :edit-message}
@@ -30,20 +30,18 @@
3030
{:size 24
3131
:icon-only? true
3232
:accessibility-label :edit-cancel-button
33-
:on-press (fn []
34-
(utils/cancel-edit-message state)
35-
(rf/dispatch [:chat.ui/cancel-message-edit]))
33+
:on-press #(utils/cancel-edit-message text-value input-ref)
3634
:type :outline}
3735
:i/close]])
3836

3937
(defn- f-view
40-
[state]
38+
[props]
4139
(let [edit (rf/sub [:chats/edit-message])
4240
height (reanimated/use-shared-value (if edit constants/edit-container-height 0))]
4341
(rn/use-effect #(reanimated/animate height (if edit constants/edit-container-height 0)) [edit])
4442
[reanimated/view {:style (reanimated/apply-animations-to-style {:height height} {})}
45-
(when edit [edit-message state])]))
43+
(when edit [edit-message props])]))
4644

4745
(defn view
48-
[state]
49-
[:f> f-view state])
46+
[props]
47+
[:f> f-view props])

Diff for: src/status_im2/contexts/chat/composer/gesture.cljs

+3-4
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
(reset! emoji-kb-extra-height nil))
4444
(reset! maximized? false)
4545
(rf/dispatch [:chat.ui/set-input-maximized false])
46-
(when @input-ref
47-
(.blur ^js @input-ref)))
46+
(utils/blur-input input-ref))
4847

4948
(defn bounce-back
5049
[{:keys [height saved-height opacity background-y]}
@@ -96,8 +95,8 @@
9695
max-height
9796
bounded-height
9897
saved-height))
99-
(when @input-ref ; sheet at min-height, collapse keyboard
100-
(.blur ^js @input-ref)))))))
98+
; sheet at min-height, collapse keyboard
99+
(utils/blur-input input-ref))))))
101100
(gesture/on-end (fn []
102101
(let [diff (- (reanimated/get-shared-value height)
103102
(reanimated/get-shared-value saved-height))]

Diff for: src/status_im2/contexts/chat/composer/keyboard.cljs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
[react-native.async-storage :as async-storage]
55
[react-native.core :as rn]
66
[react-native.platform :as platform]
7-
[react-native.reanimated :as reanimated]))
7+
[react-native.reanimated :as reanimated]
8+
[status-im2.contexts.chat.composer.utils :as utils]))
89

910
(defn get-kb-height
1011
[curr-height default-height]
@@ -68,8 +69,8 @@
6869
#(handle-emoji-kb-ios % props state animations dimensions)))
6970
(reset! keyboard-hide-listener (.addListener rn/keyboard
7071
"keyboardDidHide"
71-
#(when (and platform/android? @input-ref)
72-
(.blur ^js @input-ref)))))
72+
#(when platform/android?
73+
(utils/blur-input input-ref)))))
7374

7475
(defn handle-refocus-emoji-kb-ios
7576
[{:keys [saved-emoji-kb-extra-height]}

Diff for: src/status_im2/contexts/chat/composer/utils.cljs

+10-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,18 @@
9999
(not reply?)
100100
(not audio?)))
101101

102+
(defn blur-input
103+
[input-ref]
104+
(when @input-ref
105+
(rf/dispatch [:chat.ui/set-input-focused false])
106+
(.blur ^js @input-ref)))
107+
102108
(defn cancel-edit-message
103-
[{:keys [text-value]}]
109+
[text-value input-ref]
104110
(reset! text-value "")
105-
(rf/dispatch [:chat.ui/set-input-content-height constants/input-height]))
111+
(blur-input input-ref)
112+
(rf/dispatch [:chat.ui/set-input-content-height constants/input-height])
113+
(rf/dispatch [:chat.ui/cancel-message-edit]))
106114

107115
(defn count-lines
108116
[s]

Diff for: src/status_im2/contexts/chat/composer/view.cljs

+5-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@
9999
(when chat-screen-loaded?
100100
[:<>
101101
[reply/view state]
102-
[edit/view state]])
102+
[edit/view
103+
{:text-value (:text-value state)
104+
:input-ref (:input-ref props)}]])
103105
[reanimated/touchable-opacity
104106
{:active-opacity 1
105107
:on-press (fn []
@@ -151,7 +153,8 @@
151153
(let [window-height (:height (rn/get-window))
152154
theme (quo.theme/use-theme-value)
153155
opacity (reanimated/use-shared-value 0)
154-
background-y (reanimated/use-shared-value (- window-height)) ; Y position of background overlay
156+
background-y (reanimated/use-shared-value (- window-height)) ; Y position of background
157+
; overlay
155158
blur-height (reanimated/use-shared-value (+ constants/composer-default-height
156159
(:bottom insets)))
157160
extra-params {:insets insets

0 commit comments

Comments
 (0)