Custom toolbar for group chat views

Former-commit-id: cadf1b2a0b
This commit is contained in:
virvar 2016-05-04 14:35:35 +03:00
parent 0d10422897
commit 3b9c738714
5 changed files with 134 additions and 70 deletions

View File

@ -1,13 +1,11 @@
(ns syng-im.components.chat (ns syng-im.components.chat
(:require [clojure.string :as s] (:require [clojure.string :as s]
[re-frame.core :refer [subscribe dispatch dispatch-sync]] [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [android? [syng-im.components.react :refer [view
view
text text
image image
navigator navigator
touchable-highlight touchable-highlight]]
toolbar-android]]
[syng-im.components.realm :refer [list-view]] [syng-im.components.realm :refer [list-view]]
[syng-im.components.styles :refer [font [syng-im.components.styles :refer [font
title-font title-font

View File

@ -6,8 +6,7 @@
text text
image image
touchable-highlight touchable-highlight
navigator navigator]]
toolbar-android]]
[syng-im.components.styles :refer [font [syng-im.components.styles :refer [font
color-light-blue-transparent color-light-blue-transparent
color-white color-white

View File

@ -1,35 +1,63 @@
(ns syng-im.components.chat.new-participants (ns syng-im.components.chat.new-participants
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.resources :as res] [syng-im.resources :as res]
[syng-im.components.react :refer [view toolbar-android android? text-input]] [syng-im.components.react :refer [view android? text-input text image
touchable-highlight]]
[syng-im.components.realm :refer [list-view]] [syng-im.components.realm :refer [list-view]]
[syng-im.components.styles :refer [font
title-font
color-white
color-black
color-blue
text1-color
text2-color
toolbar-background1]]
[syng-im.utils.listview :refer [to-realm-datasource]] [syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.components.chats.new-participant-contact :refer [new-participant-contact]] [syng-im.components.chats.new-participant-contact :refer [new-participant-contact]]
[reagent.core :as r] [reagent.core :as r]
[syng-im.navigation :refer [nav-pop]])) [syng-im.navigation :refer [nav-pop]]))
(defn toolbar [navigator]
[view {:style {:flexDirection "row"
:backgroundColor toolbar-background1
:height 56
:elevation 2}}
[touchable-highlight {:on-press (fn []
(nav-pop navigator))
:underlay-color :transparent}
[view {:width 56
:height 56}
[image {:source {:uri "icon_back"}
:style {:marginTop 21
:marginLeft 23
:width 8
:height 14}}]]]
[view {:style {:flex 1
:alignItems "center"
:justifyContent "center"}}
[text {:style {:marginTop -2.5
:color text1-color
:fontSize 16
:fontFamily font}}
"Add Participants"]]
[touchable-highlight {:on-press (fn []
(dispatch [:add-new-participants navigator]))
:underlay-color :transparent}
[view {:width 56
:height 56}
[image {:source res/v ;; {:uri "icon_search"}
:style {:marginTop 19
:marginHorizontal 18
:width 20
:height 18}}]]]])
(defn new-participants [{:keys [navigator]}] (defn new-participants [{:keys [navigator]}]
(let [contacts (subscribe [:all-new-contacts])] (let [contacts (subscribe [:all-new-contacts])]
(fn [] (fn []
(let [contacts-ds (to-realm-datasource @contacts)] (let [contacts-ds (to-realm-datasource @contacts)]
[view {:style {:flex 1 [view {:style {:flex 1
:backgroundColor "white"}} :backgroundColor "white"}}
(when android? [toolbar navigator]
;; TODO add IOS version
[toolbar-android {:logo res/logo-icon
:title "Add Participants"
:titleColor "#4A5258"
:style {:backgroundColor "white"
:height 56
:elevation 2}
:actions [{:title "Add"
:icon res/v
:show "always"}]
:onActionSelected (fn [position]
(dispatch [:add-new-participants navigator]))
:navIcon res/nav-back-icon
:onIconClicked (fn []
(nav-pop navigator))}])
[list-view {:dataSource contacts-ds [list-view {:dataSource contacts-ds
:renderRow (fn [row section-id row-id] :renderRow (fn [row section-id row-id]
(r/as-element [new-participant-contact (js->clj row :keywordize-keys true) navigator])) (r/as-element [new-participant-contact (js->clj row :keywordize-keys true) navigator]))

View File

@ -1,35 +1,63 @@
(ns syng-im.components.chat.remove-participants (ns syng-im.components.chat.remove-participants
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.resources :as res] [syng-im.resources :as res]
[syng-im.components.react :refer [view toolbar-android android? text-input]] [syng-im.components.react :refer [view text-input text image
touchable-highlight]]
[syng-im.components.realm :refer [list-view]] [syng-im.components.realm :refer [list-view]]
[syng-im.components.styles :refer [font
title-font
color-white
color-black
color-blue
text1-color
text2-color
toolbar-background1]]
[syng-im.utils.listview :refer [to-realm-datasource]] [syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.components.chats.new-participant-contact :refer [new-participant-contact]] [syng-im.components.chats.new-participant-contact :refer [new-participant-contact]]
[reagent.core :as r] [reagent.core :as r]
[syng-im.navigation :refer [nav-pop]])) [syng-im.navigation :refer [nav-pop]]))
(defn toolbar [navigator]
[view {:style {:flexDirection "row"
:backgroundColor toolbar-background1
:height 56
:elevation 2}}
[touchable-highlight {:on-press (fn []
(nav-pop navigator))
:underlay-color :transparent}
[view {:width 56
:height 56}
[image {:source {:uri "icon_back"}
:style {:marginTop 21
:marginLeft 23
:width 8
:height 14}}]]]
[view {:style {:flex 1
:alignItems "center"
:justifyContent "center"}}
[text {:style {:marginTop -2.5
:color text1-color
:fontSize 16
:fontFamily font}}
"Remove Participants"]]
[touchable-highlight {:on-press (fn []
)
:underlay-color :transparent}
[view {:width 56
:height 56}
[image {:source res/trash-icon ;; {:uri "icon_search"}
:style {:marginTop 13
:marginHorizontal 17
:width 22
:height 30}}]]]])
(defn remove-participants [{:keys [navigator]}] (defn remove-participants [{:keys [navigator]}]
(let [contacts (subscribe [:current-chat-contacts])] (let [contacts (subscribe [:current-chat-contacts])]
(fn [] (fn []
(let [contacts-ds (to-realm-datasource @contacts)] (let [contacts-ds (to-realm-datasource @contacts)]
[view {:style {:flex 1 [view {:style {:flex 1
:backgroundColor "white"}} :backgroundColor "white"}}
(when android? [toolbar navigator]
;; TODO add IOS version
[toolbar-android {:logo res/logo-icon
:title "Remove Participants"
:titleColor "#4A5258"
:style {:backgroundColor "white"
:height 56
:elevation 2}
:actions [{:title "Remove"
:icon res/trash-icon
:show "always"}]
:onActionSelected (fn [position]
(dispatch [:remove-selected-participants navigator]))
:navIcon res/nav-back-icon
:onIconClicked (fn []
(nav-pop navigator))}])
[list-view {:dataSource contacts-ds [list-view {:dataSource contacts-ds
:renderRow (fn [row section-id row-id] :renderRow (fn [row section-id row-id]
(r/as-element [new-participant-contact (js->clj row :keywordize-keys true) navigator])) (r/as-element [new-participant-contact (js->clj row :keywordize-keys true) navigator]))

View File

@ -2,55 +2,66 @@
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.resources :as res] [syng-im.resources :as res]
[syng-im.components.react :refer [view [syng-im.components.react :refer [view
toolbar-android
android?
text-input text-input
text text
image image
touchable-highlight]] touchable-highlight]]
[syng-im.components.styles :refer [font [syng-im.components.styles :refer [font
title-font
color-white
color-purple
text1-color text1-color
text2-color text2-color
color-white toolbar-background1]]
color-purple]]
[syng-im.components.realm :refer [list-view]] [syng-im.components.realm :refer [list-view]]
[syng-im.utils.listview :refer [to-realm-datasource]] [syng-im.utils.listview :refer [to-realm-datasource]]
[syng-im.components.chats.new-group-contact :refer [new-group-contact]] [syng-im.components.chats.new-group-contact :refer [new-group-contact]]
[reagent.core :as r] [reagent.core :as r]
[syng-im.navigation :refer [nav-pop]])) [syng-im.navigation :refer [nav-pop]]))
(defn toolbar [navigator group-name]
[view {:style {:flexDirection "row"
:backgroundColor toolbar-background1
:height 56
:elevation 2}}
[touchable-highlight {:on-press (fn []
(nav-pop navigator))
:underlay-color :transparent}
[view {:width 56
:height 56}
[image {:source {:uri "icon_back"}
:style {:marginTop 21
:marginLeft 23
:width 8
:height 14}}]]]
[view {:style {:flex 1
:alignItems "center"
:justifyContent "center"}}
[text {:style {:marginTop -2.5
:color text1-color
:fontSize 16
:fontFamily font}}
"New group chat"]]
[touchable-highlight {:on-press (fn []
(dispatch [:create-new-group group-name navigator]))
:underlay-color :transparent}
[view {:width 56
:height 56}
[image {:source res/v ;; {:uri "icon_search"}
:style {:marginTop 19
:marginHorizontal 18
:width 20
:height 18}}]]]])
(defn new-group [{:keys [navigator]}] (defn new-group [{:keys [navigator]}]
(let [contacts (subscribe [:all-contacts]) (let [contacts (subscribe [:all-contacts])
group-name (atom nil)] group-name (r/atom nil)]
(fn [] (fn [{:keys [navigator]}]
(let [contacts-ds (to-realm-datasource @contacts)] (let [contacts-ds (to-realm-datasource @contacts)]
[view {:style {:flex 1 [view {:style {:flex 1
:flexDirection "column" :flexDirection "column"
:backgroundColor color-white}} :backgroundColor color-white}}
(when android? [toolbar navigator @group-name]
;; TODO add IOS version
[toolbar-android {:navIcon {:uri "icon_back"}
:style {:backgroundColor color-white
:height 56
:elevation 2}
:onIconClicked (fn []
(nav-pop navigator))
:actions [{:title "Create"
;; :icon res/icon-ok
:show "always"
:showWithText true}]
:onActionSelected (fn [position]
(dispatch [:create-new-group @group-name navigator]))}
[view {:style {:flex 1
:alignItems "center"
:justifyContent "center"
:marginRight 112
:backgroundColor "transparent"}}
[text {:style {:marginTop -2.5
:color text1-color
:fontSize 16
:fontFamily font}}
"New group chat"]]])
[view {:style {:marginHorizontal 16}} [view {:style {:marginHorizontal 16}}
[text {:style {:marginTop 24 [text {:style {:marginTop 24
:marginBottom 16 :marginBottom 16