Suggestions style. Add close commands button.

Former-commit-id: 6f5dade40f
This commit is contained in:
virvar 2016-05-10 16:12:45 +03:00
parent 7ecce32a86
commit d285fcd6e0
16 changed files with 122 additions and 73 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 347 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 274 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 624 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 892 B

View File

@ -5,7 +5,7 @@
[reagent.core :as r] [reagent.core :as r]
[re-frame.core :refer [subscribe dispatch dispatch-sync]] [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [view [syng-im.components.react :refer [view
image icon
text text
touchable-highlight touchable-highlight
list-view list-view
@ -22,9 +22,7 @@
[touchable-highlight {:onPress (fn [] [touchable-highlight {:onPress (fn []
(set-command-content (:value suggestion))) (set-command-content (:value suggestion)))
:underlay-color :transparent} :underlay-color :transparent}
[view (merge st/suggestion-container [view st/suggestion-container
(when (= (:description suggestion) "Number format 12")
{:backgroundColor "blue"}))
[view st/suggestion-sub-container [view st/suggestion-sub-container
[text {:style st/value-text} [text {:style st/value-text}
(:value suggestion)] (:value suggestion)]
@ -45,8 +43,8 @@
;; TODO hide suggestions? ;; TODO hide suggestions?
) )
:underlay-color :transparent} :underlay-color :transparent}
[image {:source {:uri "icon_drag_down"} [view nil
:style st/drag-down-icon}]] [icon :drag_down st/drag-down-icon]]]
[view (st/suggestions-container (count suggestions)) [view (st/suggestions-container (count suggestions))
[list-view {:dataSource (to-datasource suggestions) [list-view {:dataSource (to-datasource suggestions)
:renderRow render-row}]]]))))) :renderRow render-row}]]])))))

View File

@ -7,14 +7,6 @@
chat-background chat-background
color-black]])) color-black]]))
(def money-input
{:flex 1
:marginLeft 8
:lineHeight 42
:fontSize 32
:fontFamily font
:color :black})
(def command-input-and-suggestions-container (def command-input-and-suggestions-container
{:flexDirection :column}) {:flexDirection :column})

View File

@ -6,5 +6,4 @@
(defn money-input-view [command] (defn money-input-view [command]
[simple-command-input-view command [simple-command-input-view command
{:keyboardType :numeric {:keyboardType :numeric}])
:style st/money-input}])

View File

@ -1,7 +1,6 @@
(ns syng-im.components.chat.input.simple-command (ns syng-im.components.chat.input.simple-command
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [view [syng-im.components.react :refer [view
image
icon icon
text text
text-input text-input
@ -47,5 +46,4 @@
[view st/send-container [icon :send st/send-icon]]] [view st/send-container [icon :send st/send-icon]]]
[touchable-highlight {:on-press cancel-command-input} [touchable-highlight {:on-press cancel-command-input}
[view st/cancel-container [view st/cancel-container
[image {:source res/icon-close-gray [icon :close-gray st/cancel-icon]]])]]))))
:style st/cancel-icon}]]])]]))))

View File

@ -18,25 +18,39 @@
(dispatch [:send-group-chat-msg chat-id input-message]) (dispatch [:send-group-chat-msg chat-id input-message])
(dispatch [:send-chat-msg])))) (dispatch [:send-chat-msg]))))
(defn message-valid? [staged-commands message]
(or (and (pos? (count message))
(not= "!" message))
(pos? (count staged-commands))))
(defn try-send [chat staged-commands message]
(when (message-valid? staged-commands message)
(send chat message)))
(defn plain-message-input-view [] (defn plain-message-input-view []
(let [chat (subscribe [:get-current-chat]) (let [chat (subscribe [:get-current-chat])
input-message-atom (subscribe [:get-chat-input-text]) input-message-atom (subscribe [:get-chat-input-text])
staged-commands-atom (subscribe [:get-chat-staged-commands])] staged-commands-atom (subscribe [:get-chat-staged-commands])
typing-command? (subscribe [:typing-command?])]
(fn [] (fn []
(let [input-message @input-message-atom] (let [input-message @input-message-atom]
[view st/input-container [view st/input-container
[suggestions-view] [suggestions-view]
[view st/input-view [view st/input-view
[touchable-highlight {:on-press #(dispatch [:switch-command-suggestions])} [touchable-highlight {:on-press #(dispatch [:switch-command-suggestions])
[view nil [icon :list st/list-icon]]] :style st/switch-commands-touchable}
[view nil
(if @typing-command?
[icon :close-gray st/close-icon]
[icon :list st/list-icon])]]
[text-input {:style st/message-input [text-input {:style st/message-input
:autoFocus (pos? (count @staged-commands-atom)) :autoFocus (pos? (count @staged-commands-atom))
:onChangeText set-input-message :onChangeText set-input-message
:onSubmitEditing #(send @chat input-message)} :onSubmitEditing #(try-send @chat @staged-commands-atom
input-message)}
input-message] input-message]
[icon :smile st/smile-icon] [icon :smile st/smile-icon]
(when (or (pos? (count input-message)) (when (message-valid? @staged-commands-atom input-message)
(pos? (count @staged-commands-atom)))
[touchable-highlight {:on-press #(send @chat input-message)} [touchable-highlight {:on-press #(send @chat input-message)}
[view st/send-container [view st/send-container
[icon :send st/send-icon]]])]])))) [icon :send st/send-icon]]])]]))))

View File

@ -12,17 +12,22 @@
:height 56 :height 56
:backgroundColor color-white}) :backgroundColor color-white})
(def switch-commands-touchable
{:width 56
:height 56
:alignItems :center
:justifyContent :center})
(def list-icon (def list-icon
{:marginTop 22 {:width 13
:marginRight 6 :height 12})
:marginBottom 6
:marginLeft 21 (def close-icon
:width 13 {:width 12
:height 12}) :height 12})
(def message-input (def message-input
{:flex 1 {:flex 1
:marginLeft 16
:marginTop -2 :marginTop -2
:padding 0 :padding 0
:fontSize 14 :fontSize 14

View File

@ -4,6 +4,7 @@
(:require [re-frame.core :refer [subscribe dispatch]] (:require [re-frame.core :refer [subscribe dispatch]]
[syng-im.components.react :refer [view [syng-im.components.react :refer [view
text text
icon
touchable-highlight touchable-highlight
list-view list-view
list-item]] list-item]]
@ -16,12 +17,15 @@
(defn suggestion-list-item [suggestion] (defn suggestion-list-item [suggestion]
[touchable-highlight [touchable-highlight
{:onPress #(set-command-input (keyword (:command suggestion)))} {:onPress #(set-command-input (keyword (:command suggestion)))}
[view st/suggestion-item-container [view st/suggestion-container
[view st/suggestion-sub-container
[view (st/suggestion-background suggestion) [view (st/suggestion-background suggestion)
[text {:style st/suggestion-text} [text {:style st/suggestion-text}
(:text suggestion)]] (:text suggestion)]]
[text {:style st/suggestion-description} [text {:style st/value-text}
(:description suggestion)]]]) (:text suggestion)]
[text {:style st/description-text}
(:description suggestion)]]]])
(defn render-row [row _ _] (defn render-row [row _ _]
(list-item [suggestion-list-item (js->clj row :keywordize-keys true)])) (list-item [suggestion-list-item (js->clj row :keywordize-keys true)]))
@ -31,8 +35,14 @@
(fn [] (fn []
(let [suggestions @suggestions-atom] (let [suggestions @suggestions-atom]
(when (seq suggestions) (when (seq suggestions)
[view (st/suggestions-container suggestions) [view nil
[touchable-highlight {:style st/drag-down-touchable
:onPress (fn []
;; TODO hide suggestions?
)}
[view nil
[icon :drag_down st/drag-down-icon]]]
[view (st/suggestions-container (count suggestions))
[list-view {:dataSource (to-datasource suggestions) [list-view {:dataSource (to-datasource suggestions)
:enableEmptySections true :enableEmptySections true
:renderRow render-row :renderRow render-row}]]])))))
:style {}}]])))))

View File

@ -1,44 +1,69 @@
(ns syng-im.components.chat.suggestions-styles (ns syng-im.components.chat.suggestions-styles
(:require [syng-im.components.styles :refer [font color-white]])) (:require [syng-im.components.styles :refer [font
color-light-blue-transparent
color-white
color-black
color-blue
color-blue-transparent
selected-message-color
online-color
separator-color
text1-color
text2-color
text3-color]]))
(def suggestion-item-container (def suggestion-height 88)
{:flexDirection :row
:marginVertical 1 (def suggestion-container
:marginHorizontal 0 {:flexDirection :column
:height 40 :paddingLeft 16
:backgroundColor color-white}) :backgroundColor color-white})
(def suggestion-sub-container
{:height suggestion-height
:borderBottomWidth 1
:borderBottomColor separator-color})
(defn suggestion-background (defn suggestion-background
[{:keys [color]}] [{:keys [color]}]
{:flexDirection :column {:alignSelf :flex-start
:position :absolute :marginTop 10
:top 10 :height 24
:left 60
:backgroundColor color :backgroundColor color
:borderRadius 10}) :borderRadius 50})
(def suggestion-text (def suggestion-text
{:marginTop -2 {:marginTop 2.5
:marginHorizontal 10 :marginHorizontal 12
:fontSize 14 :fontSize 12
:fontFamily font :fontFamily font
:color color-white}) :color color-white})
(def suggestion-description (def value-text
{:flex 1 {:marginTop 6
:position :absolute
:top 7
:left 190
:lineHeight 18
:fontSize 14 :fontSize 14
:fontFamily font :fontFamily font
:color :black}) :color text1-color})
(defn suggestions-container (def description-text
[suggestions] {:marginTop 2
:fontSize 12
:fontFamily font
:color text2-color})
(defn suggestions-container [suggestions-count]
{:flexDirection :row {:flexDirection :row
:marginVertical 1 :marginVertical 1
:marginHorizontal 0 :marginHorizontal 0
:height (min 105 (* 42 (count suggestions))) :height (min 168 (* suggestion-height suggestions-count))
:backgroundColor color-white :backgroundColor color-white
:borderRadius 5}) :borderRadius 5})
(def drag-down-touchable
{:height 22
:alignItems :center
:justifyContent :center})
(def drag-down-icon
{:width 16
:height 16})

View File

@ -65,6 +65,9 @@
(get-commands db))] (get-commands db))]
suggestion))) suggestion)))
(defn switch-command-suggestions [db] (defn typing-command? [db]
(let [text (get-chat-input-text db)] (let [text (get-chat-input-text db)]
(set-chat-input-text db (if (suggestion? text) nil "!")))) (suggestion? text)))
(defn switch-command-suggestions [db]
(set-chat-input-text db (if (typing-command? db) nil "!")))

View File

@ -18,7 +18,8 @@
get-chat-command-content get-chat-command-content
get-chat-command-request get-chat-command-request
parse-command-request]] parse-command-request]]
[syng-im.handlers.suggestions :refer [get-suggestions]] [syng-im.handlers.suggestions :refer [get-suggestions
typing-command?]]
[syng-im.handlers.content-suggestions :refer [get-content-suggestions]])) [syng-im.handlers.content-suggestions :refer [get-content-suggestions]]))
;; -- Chat -------------------------------------------------------------- ;; -- Chat --------------------------------------------------------------
@ -40,6 +41,10 @@
(reaction))] (reaction))]
(reaction (get-suggestions @db @input-text))))) (reaction (get-suggestions @db @input-text)))))
(register-sub :typing-command?
(fn [db _]
(reaction (typing-command? @db))))
(register-sub :get-content-suggestions (register-sub :get-content-suggestions
(fn [db _] (fn [db _]
(let [command (reaction (get-chat-command @db)) (let [command (reaction (get-chat-command @db))