adapt animation

Former-commit-id: 831132ccef8f9280f0f2601f540894d2469723ba
This commit is contained in:
Roman Volosovskyi 2016-06-23 15:47:58 +03:00
parent 5abe38445e
commit 6e20f11ed8
16 changed files with 66 additions and 132 deletions

View File

@ -0,0 +1,6 @@
(ns status-im.chat.constants)
(def input-height 56)
(def request-info-height 61)
(def response-height-normal 211)
(def minimum-suggestion-height (+ input-height request-info-height))

View File

@ -3,7 +3,6 @@
[status-im.models.commands :as commands] [status-im.models.commands :as commands]
[clojure.string :as str] [clojure.string :as str]
[status-im.components.styles :refer [default-chat-color]] [status-im.components.styles :refer [default-chat-color]]
[status-im.chat.styles.response :refer [request-info-height response-height-normal]]
[status-im.chat.suggestions :as suggestions] [status-im.chat.suggestions :as suggestions]
[status-im.protocol.api :as api] [status-im.protocol.api :as api]
[status-im.models.messages :as messages] [status-im.models.messages :as messages]
@ -20,9 +19,7 @@
[status-im.utils.phone-number :refer [format-phone-number]] [status-im.utils.phone-number :refer [format-phone-number]]
[status-im.utils.datetime :as time] [status-im.utils.datetime :as time]
[status-im.components.jail :as j] [status-im.components.jail :as j]
[status-im.commands.utils :refer [generate-hiccup]] [status-im.commands.utils :refer [generate-hiccup]]))
[status-im.chat.handlers.animation :refer [update-response-height
get-response-height]]))
(register-handler :set-show-actions (register-handler :set-show-actions
(fn [db [_ show-actions]] (fn [db [_ show-actions]]
@ -74,16 +71,12 @@
(fn [{:keys [current-chat-id] :as db} [_ content]] (fn [{:keys [current-chat-id] :as db} [_ content]]
(as-> db db (as-> db db
(commands/set-chat-command-content db content) (commands/set-chat-command-content db content)
(assoc-in db [:chats current-chat-id :input-text] nil) (assoc-in db [:chats current-chat-id :input-text] nil))))
(if (commands/get-chat-command-to-msg-id db)
(update-response-height db)
db))))
(defn update-input-text (defn update-input-text
[{:keys [current-chat-id] :as db} text] [{:keys [current-chat-id] :as db} text]
(assoc-in db [:chats current-chat-id :input-text] text)) (assoc-in db [:chats current-chat-id :input-text] text))
(defn invoke-command-preview! (defn invoke-command-preview!
[{:keys [current-chat-id staged-command] :as db} _] [{:keys [current-chat-id staged-command] :as db} _]
(let [commands (get-in db [:chats current-chat-id :commands]) (let [commands (get-in db [:chats current-chat-id :commands])
@ -123,7 +116,8 @@
(register-handler :set-response-chat-command (register-handler :set-response-chat-command
[(after invoke-suggestions-handler!) [(after invoke-suggestions-handler!)
(after #(dispatch [:command-edit-mode])) (after #(dispatch [:command-edit-mode]))
(after #(dispatch [:animate-show-response]))] ;(after #(dispatch [:animate-show-response]))
]
(fn [db [_ to-msg-id command-key]] (fn [db [_ to-msg-id command-key]]
(commands/set-response-chat-command db to-msg-id command-key))) (commands/set-response-chat-command db to-msg-id command-key)))
@ -304,7 +298,8 @@
(register-handler :set-chat-command (register-handler :set-chat-command
[(after #(dispatch [:command-edit-mode])) [(after #(dispatch [:command-edit-mode]))
(after #(dispatch [:animate-show-response]))] ;(after #(dispatch [:animate-show-response]))
]
(fn [db [_ command-key]] (fn [db [_ command-key]]
(commands/set-chat-command db command-key))) (commands/set-chat-command db command-key)))

View File

@ -1,14 +1,15 @@
(ns status-im.chat.handlers.animation (ns status-im.chat.handlers.animation
(:require [re-frame.core :refer [register-handler after dispatch]] (:require [re-frame.core :refer [register-handler after dispatch debug]]
[re-frame.middleware :refer [path]] [re-frame.middleware :refer [path]]
[status-im.models.commands :as commands] [status-im.models.commands :as commands]
[status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]]
[status-im.chat.styles.message-input :refer [input-height]] [status-im.chat.constants :refer [input-height request-info-height
[status-im.chat.styles.response :refer [request-info-height response-height-normal]] response-height-normal minimum-suggestion-height]]
[status-im.chat.styles.response-suggestions :as response-suggestions-styles] [status-im.chat.styles.response-suggestions :as response-suggestions-styles]
[status-im.constants :refer [response-input-hiding-duration]])) [status-im.constants :refer [response-input-hiding-duration]]))
(def zero-height input-height) ;; todo magic value
(def middle-height 270)
(defn animation-handler (defn animation-handler
([name handler] (animation-handler name nil handler)) ([name handler] (animation-handler name nil handler))
@ -19,25 +20,21 @@
(after #(dispatch [:text-edit-mode])) (after #(dispatch [:text-edit-mode]))
(fn [db _] (fn [db _]
(assoc db (assoc db
:to-response-height zero-height :to-response-height input-height
:messages-offset 0))) :messages-offset 0)))
(defn get-response-height [db] (defn get-response-height
(let [command (commands/get-chat-command db) [{:keys [current-chat-id] :as db}]
text (commands/get-chat-command-content db) (let [suggestions (get-in db [:suggestions current-chat-id])
suggestions (get-content-suggestions command text) suggestions-height (if suggestions middle-height 0)]
suggestions-height (reduce + 0 (map #(if (:header %) (+ input-height
response-suggestions-styles/header-height
response-suggestions-styles/suggestion-height)
suggestions))]
(+ zero-height
(min response-height-normal (+ suggestions-height request-info-height))))) (min response-height-normal (+ suggestions-height request-info-height)))))
(defn update-response-height [db] (defn update-response-height [db]
(assoc-in db [:animations :to-response-height] (get-response-height db))) (assoc-in db [:animations :to-response-height] (get-response-height db)))
(register-handler :animate-show-response (register-handler :animate-show-response
(after #(dispatch [:command-edit-mode])) [(after #(dispatch [:command-edit-mode]))]
(fn [db _] (fn [db _]
(-> db (-> db
(assoc-in [:animations :messages-offset] request-info-height) (assoc-in [:animations :messages-offset] request-info-height)
@ -54,26 +51,28 @@
db)))) db))))
(register-handler :fix-response-height (register-handler :fix-response-height
(fn [db [_ vy current]] (fn [{:keys [current-chat-id] :as db} [_ vy current]]
(let [max-height (get-in db [:animations :response-height-max]) (let [max-height (get-in db [:animations :response-height-max])
;; todo magic value
middle 270
moving-down? (pos? vy) moving-down? (pos? vy)
moving-up? (not moving-down?) moving-up? (not moving-down?)
under-middle-position? (<= current middle) under-middle-position? (<= current middle-height)
over-middle-position? (not under-middle-position?) over-middle-position? (not under-middle-position?)
min-height (+ zero-height request-info-height) suggestions (get-in db [:suggestions current-chat-id])
new-fixed (cond (and under-middle-position? moving-down?) new-fixed (cond (not suggestions)
min-height minimum-suggestion-height
(and under-middle-position? moving-up?) (and under-middle-position? moving-up?)
middle middle-height
(and over-middle-position? moving-down?) (and over-middle-position? moving-down?)
middle middle-height
(and over-middle-position? moving-up?) (and over-middle-position? moving-up?)
max-height)] max-height
(and under-middle-position?
moving-down?)
minimum-suggestion-height)]
(-> db (-> db
(assoc-in [:animations :to-response-height] new-fixed) (assoc-in [:animations :to-response-height] new-fixed)
(update-in [:animations :response-height-changed] inc))))) (update-in [:animations :response-height-changed] inc)))))

View File

@ -18,7 +18,6 @@
[status-im.components.invertible-scroll-view :refer [invertible-scroll-view]] [status-im.components.invertible-scroll-view :refer [invertible-scroll-view]]
[status-im.components.toolbar :refer [toolbar]] [status-im.components.toolbar :refer [toolbar]]
[status-im.chat.views.message :refer [chat-message]] [status-im.chat.views.message :refer [chat-message]]
[status-im.chat.views.content-suggestions :refer [content-suggestions-view]]
[status-im.chat.views.suggestions :refer [suggestions-view]] [status-im.chat.views.suggestions :refer [suggestions-view]]
[status-im.chat.views.response :refer [response-view]] [status-im.chat.views.response :refer [response-view]]
[status-im.chat.views.new-message :refer [chat-message-new]] [status-im.chat.views.new-message :refer [chat-message-new]]

View File

@ -1,8 +1,7 @@
(ns status-im.chat.styles.message-input (ns status-im.chat.styles.message-input
(:require [status-im.components.styles :refer [color-white (:require [status-im.components.styles :refer [color-white
color-blue]])) color-blue]]
[status-im.chat.constants :refer [input-height]]))
(def input-height 56)
(def message-input-container (def message-input-container
{:flex 1 {:flex 1

View File

@ -6,10 +6,8 @@
text2-color text2-color
chat-background chat-background
color-black]] color-black]]
[status-im.chat.styles.message-input :refer [input-height]])) [status-im.chat.constants :refer [input-height request-info-height
response-height-normal]]))
(def response-height-normal 211)
(def request-info-height 61)
(def drag-container (def drag-container
{:height 16 {:height 16

View File

@ -1,15 +1,15 @@
(ns status-im.chat.subs (ns status-im.chat.subs
(:require-macros [reagent.ratom :refer [reaction]]) (:require-macros [reagent.ratom :refer [reaction]])
(:require [re-frame.core :refer [register-sub dispatch subscribe]] (:require [re-frame.core :refer [register-sub dispatch subscribe path]]
[status-im.db :as db] [status-im.db :as db]
;todo handlers in subs?...
[status-im.chat.suggestions :refer [status-im.chat.suggestions :refer
[get-suggestions typing-command?]] [get-suggestions typing-command?]]
[status-im.models.commands :as commands] [status-im.models.commands :as commands]
[status-im.constants :refer [response-suggesstion-resize-duration]] [status-im.constants :refer [response-suggesstion-resize-duration]]
[status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.handlers.content-suggestions :refer [get-content-suggestions]]
[status-im.chat.views.plain-message :as plain-message] [status-im.chat.views.plain-message :as plain-message]
[status-im.chat.views.command :as command])) [status-im.chat.views.command :as command]
[status-im.chat.constants :as c]))
(register-sub :chat-properties (register-sub :chat-properties
(fn [db [_ properties]] (fn [db [_ properties]]

View File

@ -1,34 +0,0 @@
(ns status-im.chat.views.content-suggestions
(:require-macros [status-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch]]
[status-im.components.react :refer [view
icon
text
touchable-highlight
list-view
list-item]]
[status-im.chat.styles.content-suggestions :as st]
[status-im.utils.listview :refer [to-datasource]]))
(defn set-command-content [content]
(dispatch [:set-chat-command-content content]))
(defn suggestion-list-item [{:keys [value description]}]
[touchable-highlight {:onPress #(set-command-content value)}
[view st/suggestion-container
[view st/suggestion-sub-container
[text {:style st/value-text} value]
[text {:style st/description-text} description]]]])
(defn render-row [row _ _]
(list-item [suggestion-list-item row]))
(defview content-suggestions-view []
[suggestions [:get-content-suggestions]]
(when (seq suggestions)
[view st/container
[touchable-highlight {:style st/drag-down-touchable
;; TODO hide suggestions?
:onPress (fn [])}
[view [icon :drag_down st/drag-down-icon]]]
suggestions]))

View File

@ -24,7 +24,8 @@
(defn button-animation-logic [{:keys [command? val]}] (defn button-animation-logic [{:keys [command? val]}]
(fn [_] (fn [_]
(let [to-scale (if @command? 0 1)] (let [to-scale (if @command? 0 1)]
(anim/start (anim/spring val {:toValue to-scale}))))) (anim/start (anim/spring val {:toValue to-scale
:tension 30})))))
(defn list-container [min] (defn list-container [min]
(fn [{:keys [command? width]}] (fn [{:keys [command? width]}]
@ -62,7 +63,8 @@
(fn [_] (fn [_]
(let [to-scale (if @command? 0 1)] (let [to-scale (if @command? 0 1)]
(when-not @command? (anim/set-value width 56)) (when-not @command? (anim/set-value width 56))
(anim/start (anim/spring val {:toValue to-scale}) (anim/start (anim/spring val {:toValue to-scale
:tension 30})
(fn [e] (fn [e]
(when (and @command? (.-finished e)) (when (and @command? (.-finished e))
(anim/set-value width 0.1))))))) (anim/set-value width 0.1)))))))

View File

@ -13,7 +13,6 @@
[status-im.components.drag-drop :as drag] [status-im.components.drag-drop :as drag]
[status-im.chat.views.response-suggestions :refer [response-suggestions-view]] [status-im.chat.views.response-suggestions :refer [response-suggestions-view]]
[status-im.chat.styles.response :as st] [status-im.chat.styles.response :as st]
[status-im.chat.styles.message-input :refer [input-height]]
[status-im.components.animation :as anim] [status-im.components.animation :as anim]
[status-im.components.react :as react])) [status-im.components.react :as react]))
@ -112,5 +111,4 @@
(let [response-height (anim/create-value 0)] (let [response-height (anim/create-value 0)]
[container response-height [container response-height
[request-info response-height] [request-info response-height]
[response-suggestions-view] [response-suggestions-view]]))
[view st/input-placeholder]]))

View File

@ -1,35 +1,7 @@
(ns status-im.chat.views.response-suggestions (ns status-im.chat.views.response-suggestions
(:require-macros [status-im.utils.views :refer [defview]]) (:require-macros [status-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch]] (:require [re-frame.core :refer [subscribe dispatch]]))
[status-im.components.react :refer [view
icon
text
touchable-highlight
list-view
list-item]]
[status-im.chat.styles.response-suggestions :as st]
[status-im.utils.listview :refer [to-datasource]]))
(defn set-command-content [content]
(dispatch [:set-chat-command-content content]))
(defn header-list-item [{:keys [header]}]
[view st/header-container
[text {:style st/header-text} header]])
(defn suggestion-list-item [{:keys [value description]}]
[touchable-highlight {:onPress #(set-command-content value)}
[view st/suggestion-container
[view st/suggestion-sub-container
[text {:style st/value-text} value]
[text {:style st/description-text} description]]]])
(defn render-row [row _ _]
(list-item (if (:header row)
[header-list-item row]
[suggestion-list-item row])))
(defview response-suggestions-view [] (defview response-suggestions-view []
[suggestions [:get-content-suggestions]] [suggestions [:get-content-suggestions]]
(when (seq suggestions) (when (seq suggestions) suggestions))
suggestions))

View File

@ -63,6 +63,8 @@
(reg-handler ::render-command render-command) (reg-handler ::render-command render-command)
(reg-handler :command-handler! (u/side-effect! command-nadler!)) (reg-handler :command-handler! (u/side-effect! command-nadler!))
(reg-handler :suggestions-handler suggestions-handler) (reg-handler :suggestions-handler
(after #(dispatch [:animate-show-response]))
suggestions-handler)
(reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!)) (reg-handler :suggestions-event! (u/side-effect! suggestions-events-handler!))
(reg-handler :command-preview command-preview) (reg-handler :command-preview command-preview)

View File

@ -55,9 +55,6 @@
;; todo check ;; todo check
#_(= (get-hash-by-identity db identity) #_(= (get-hash-by-identity db identity)
(get-hash-by-file file))] (get-hash-by-file file))]
(println :hash
(get-hash-by-identity db identity)
(get-hash-by-file file))
(assoc db ::valid-hash valid?))) (assoc db ::valid-hash valid?)))
(defn add-commands (defn add-commands

View File

@ -45,4 +45,4 @@
(defn reg-handler (defn reg-handler
([name handler] (reg-handler name nil handler)) ([name handler] (reg-handler name nil handler))
([name middleware handler] ([name middleware handler]
(register-handler name [debug trim-v middleware] handler))) (register-handler name [#_debug trim-v middleware] handler)))

View File

@ -122,5 +122,5 @@ var status = {
(.stringify js/JSON (clj->js data))) (.stringify js/JSON (clj->js data)))
(defn call [chat-id path params callback] (defn call [chat-id path params callback]
(println :call chat-id (cljs->json path) (cljs->json params)) ;(println :call chat-id (cljs->json path) (cljs->json params))
(.call jail chat-id (cljs->json path) (cljs->json params) callback)) (.call jail chat-id (cljs->json path) (cljs->json params) callback))

View File

@ -9,6 +9,7 @@
[status-im.utils.crypt :refer [gen-random-bytes]] [status-im.utils.crypt :refer [gen-random-bytes]]
[status-im.utils.handlers :as u] [status-im.utils.handlers :as u]
status-im.chat.handlers status-im.chat.handlers
status-im.chat.handlers.animation
status-im.group-settings.handlers status-im.group-settings.handlers
status-im.navigation.handlers status-im.navigation.handlers
status-im.contacts.handlers status-im.contacts.handlers