From b264d25b69b2175730f36f05434027b0916a2a2f Mon Sep 17 00:00:00 2001 From: Omar Basem Date: Wed, 17 May 2023 19:43:42 +0400 Subject: [PATCH] fix: composer opacity (#15929) --- .../contexts/chat/composer/actions/view.cljs | 15 ++++--- .../contexts/chat/composer/handlers.cljs | 41 ++++++++++--------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/status_im2/contexts/chat/composer/actions/view.cljs b/src/status_im2/contexts/chat/composer/actions/view.cljs index 4937ba4366..119d846fa0 100644 --- a/src/status_im2/contexts/chat/composer/actions/view.cljs +++ b/src/status_im2/contexts/chat/composer/actions/view.cljs @@ -64,7 +64,7 @@ [:f> f-send-button state animations window-height images? btn-opacity z-index])) (defn audio-button - [{:keys [record-reset-fn]} + [{:keys [record-reset-fn input-ref]} {:keys [record-permission? recording? gesture-enabled? focused?]} {:keys [container-opacity]}] (let [audio (rf/sub [:chats/sending-audio])] @@ -86,17 +86,22 @@ (reset! recording? false) (reset! gesture-enabled? true) (rf/dispatch [:chat/send-audio file-path duration]) - (when-not @focused? + (if-not @focused? (reanimated/animate container-opacity - constants/empty-opacity)) + constants/empty-opacity) + (js/setTimeout #(when @input-ref (.focus ^js @input-ref)) + 300)) (rf/dispatch [:chat.ui/set-input-audio nil])) :on-cancel (fn [] (when @recording? (reset! recording? false) (reset! gesture-enabled? true) - (when-not @focused? + (if-not @focused? (reanimated/animate container-opacity - constants/empty-opacity)) + constants/empty-opacity) + (js/setTimeout #(when @input-ref + (.focus ^js @input-ref)) + 300)) (rf/dispatch [:chat.ui/set-input-audio nil]))) :on-check-audio-permissions (fn [] (permissions/permission-granted? diff --git a/src/status_im2/contexts/chat/composer/handlers.cljs b/src/status_im2/contexts/chat/composer/handlers.cljs index 5e476b6d5b..09710ab23b 100644 --- a/src/status_im2/contexts/chat/composer/handlers.cljs +++ b/src/status_im2/contexts/chat/composer/handlers.cljs @@ -36,29 +36,30 @@ (defn blur [{:keys [text-value focused? lock-selection? cursor-position saved-cursor-position gradient-z-index - maximized?]} + maximized? recording?]} {:keys [height saved-height last-height gradient-opacity container-opacity opacity background-y]} {:keys [content-height max-height window-height]} {:keys [images reply]}] - (let [lines (utils/calc-lines (- @content-height constants/extra-content-offset)) - min-height (utils/get-min-height lines) - reopen-height (utils/calc-reopen-height text-value min-height content-height saved-height)] - (reset! focused? false) - (rf/dispatch [:chat.ui/set-input-focused false]) - (reanimated/set-shared-value last-height reopen-height) - (reanimated/animate height min-height) - (reanimated/set-shared-value saved-height min-height) - (reanimated/animate opacity 0) - (js/setTimeout #(reanimated/set-shared-value background-y (- window-height)) 300) - (when (utils/empty-input? @text-value images reply nil) - (reanimated/animate container-opacity constants/empty-opacity)) - (reanimated/animate gradient-opacity 0) - (reset! lock-selection? true) - (reset! saved-cursor-position @cursor-position) - (reset! gradient-z-index (if (= (reanimated/get-shared-value gradient-opacity) 1) -1 0)) - (when (not= reopen-height max-height) - (reset! maximized? false) - (rf/dispatch [:chat.ui/set-input-maximized false])))) + (when-not @recording? + (let [lines (utils/calc-lines (- @content-height constants/extra-content-offset)) + min-height (utils/get-min-height lines) + reopen-height (utils/calc-reopen-height text-value min-height content-height saved-height)] + (reset! focused? false) + (rf/dispatch [:chat.ui/set-input-focused false]) + (reanimated/set-shared-value last-height reopen-height) + (reanimated/animate height min-height) + (reanimated/set-shared-value saved-height min-height) + (reanimated/animate opacity 0) + (js/setTimeout #(reanimated/set-shared-value background-y (- window-height)) 300) + (when (utils/empty-input? @text-value images reply nil) + (reanimated/animate container-opacity constants/empty-opacity)) + (reanimated/animate gradient-opacity 0) + (reset! lock-selection? true) + (reset! saved-cursor-position @cursor-position) + (reset! gradient-z-index (if (= (reanimated/get-shared-value gradient-opacity) 1) -1 0)) + (when (not= reopen-height max-height) + (reset! maximized? false) + (rf/dispatch [:chat.ui/set-input-maximized false]))))) (defn content-size-change [event