2016-06-06 18:47:11 +03:00
|
|
|
(ns status-im.chat.views.plain-message
|
|
|
|
(:require-macros [status-im.utils.views :refer [defview]])
|
|
|
|
(:require [re-frame.core :refer [subscribe dispatch]]
|
|
|
|
[reagent.core :as r]
|
|
|
|
[status-im.components.react :refer [view
|
|
|
|
animated-view
|
|
|
|
icon
|
2016-06-15 11:39:38 +03:00
|
|
|
touchable-highlight]]
|
2016-06-06 18:47:11 +03:00
|
|
|
[status-im.components.animation :as anim]
|
|
|
|
[status-im.chat.styles.plain-message :as st]
|
|
|
|
[status-im.constants :refer [response-input-hiding-duration]]))
|
|
|
|
|
|
|
|
(defn set-input-message [message]
|
|
|
|
(dispatch [:set-chat-input-text message]))
|
|
|
|
|
2016-06-20 21:15:05 +03:00
|
|
|
(defn send []
|
2016-06-06 18:47:11 +03:00
|
|
|
(dispatch [:send-chat-msg]))
|
|
|
|
|
|
|
|
(defn message-valid? [staged-commands message]
|
|
|
|
(or (and (pos? (count message))
|
|
|
|
(not= "!" message))
|
|
|
|
(pos? (count staged-commands))))
|
|
|
|
|
2016-06-20 01:20:48 +03:00
|
|
|
(defn button-animation-logic [{:keys [command? val]}]
|
2016-06-06 18:47:11 +03:00
|
|
|
(fn [_]
|
2016-06-20 01:20:48 +03:00
|
|
|
(let [to-scale (if @command? 0 1)]
|
2016-06-23 15:47:58 +03:00
|
|
|
(anim/start (anim/spring val {:toValue to-scale
|
|
|
|
:tension 30})))))
|
2016-06-20 01:20:48 +03:00
|
|
|
|
|
|
|
(defn list-container [min]
|
|
|
|
(fn [{:keys [command? width]}]
|
|
|
|
(let [n-width (if @command? min 56)
|
2016-06-23 15:47:58 +03:00
|
|
|
delay (if @command? 100 0)]
|
2016-06-20 01:20:48 +03:00
|
|
|
(anim/start (anim/timing width {:toValue n-width
|
|
|
|
:duration response-input-hiding-duration
|
2016-06-23 15:47:58 +03:00
|
|
|
:delay delay})))))
|
2016-06-06 18:47:11 +03:00
|
|
|
|
|
|
|
(defn commands-button []
|
2016-06-21 12:46:02 +03:00
|
|
|
(let [command? (subscribe [:command?])
|
2016-06-20 01:20:48 +03:00
|
|
|
buttons-scale (anim/create-value (if @command? 1 0))
|
|
|
|
container-width (anim/create-value (if @command? 20 56))
|
|
|
|
context {:command? command?
|
|
|
|
:val buttons-scale
|
|
|
|
:width container-width}
|
|
|
|
on-update (fn [_]
|
|
|
|
((button-animation-logic context))
|
|
|
|
((list-container 20) context))]
|
2016-06-06 18:47:11 +03:00
|
|
|
(r/create-class
|
|
|
|
{:component-did-mount
|
|
|
|
on-update
|
|
|
|
:component-did-update
|
|
|
|
on-update
|
|
|
|
:reagent-render
|
|
|
|
(fn []
|
2016-06-25 18:44:37 +03:00
|
|
|
[touchable-highlight {:on-press #(dispatch [:switch-command-suggestions!])
|
2016-06-20 01:20:48 +03:00
|
|
|
:disabled @command?}
|
|
|
|
[animated-view {:style (st/message-input-button-touchable
|
|
|
|
container-width)}
|
|
|
|
[animated-view {:style (st/message-input-button buttons-scale)}
|
|
|
|
[icon :list st/list-icon]]]])})))
|
|
|
|
|
|
|
|
(defn smile-animation-logic [{:keys [command? val width]}]
|
|
|
|
(fn [_]
|
|
|
|
(let [to-scale (if @command? 0 1)]
|
|
|
|
(when-not @command? (anim/set-value width 56))
|
2016-06-23 15:47:58 +03:00
|
|
|
(anim/start (anim/spring val {:toValue to-scale
|
|
|
|
:tension 30})
|
2016-06-21 10:27:07 +03:00
|
|
|
(fn [e]
|
|
|
|
(when (and @command? (.-finished e))
|
2016-06-20 01:20:48 +03:00
|
|
|
(anim/set-value width 0.1)))))))
|
2016-06-06 18:47:11 +03:00
|
|
|
|
|
|
|
(defn smile-button []
|
2016-06-23 15:47:58 +03:00
|
|
|
(let [command? (subscribe [:command?])
|
|
|
|
buttons-scale (anim/create-value (if @command? 1 0))
|
2016-06-20 01:20:48 +03:00
|
|
|
container-width (anim/create-value (if @command? 0.1 56))
|
2016-06-23 15:47:58 +03:00
|
|
|
context {:command? command?
|
|
|
|
:val buttons-scale
|
|
|
|
:width container-width}
|
|
|
|
on-update (smile-animation-logic context)]
|
2016-06-06 18:47:11 +03:00
|
|
|
(r/create-class
|
|
|
|
{:component-did-mount
|
|
|
|
on-update
|
|
|
|
:component-did-update
|
|
|
|
on-update
|
|
|
|
:reagent-render
|
|
|
|
(fn []
|
2016-06-20 01:20:48 +03:00
|
|
|
[touchable-highlight {:on-press (fn []
|
2016-06-06 18:47:11 +03:00
|
|
|
;; TODO emoticons: not implemented
|
|
|
|
)
|
2016-06-20 01:20:48 +03:00
|
|
|
:disabled @command?}
|
|
|
|
[animated-view {:style (st/message-input-button-touchable
|
|
|
|
container-width)}
|
|
|
|
[animated-view {:style (st/message-input-button buttons-scale)}
|
|
|
|
[icon :smile st/smile-icon]]]])})))
|