use the new defview

This commit is contained in:
Adrian Tiberius 2016-05-17 17:03:21 +03:00
parent 3881da9156
commit dfc772d0cd
6 changed files with 46 additions and 40 deletions

View File

@ -14,6 +14,7 @@
[syng-im.components.drawer.view :refer [drawer-view open-drawer]]
[syng-im.components.styles :refer [color-blue]]
[syng-im.components.toolbar :refer [toolbar]]
[syng-im.components.main-tabs :refer [main-tabs]]
[syng-im.components.icons.ionicons :refer [icon]]
[syng-im.chats-list.styles :as st]))
@ -37,7 +38,9 @@
:renderRow (fn [row _ _]
(list-item [chat-list-item row]))
:style st/list-container}]
[action-button {:buttonColor color-blue}
[action-button {:buttonColor color-blue
:offsetY 72
:offsetX 16}
[action-button-item
{:title "New Chat"
:buttonColor :#9b59b6
@ -49,4 +52,5 @@
:buttonColor :#1abc9c
:onPress #(dispatch [:show-group-new])}
[icon {:name :person-stalker
:style st/person-stalker-icon}]]]]])))
:style st/person-stalker-icon}]]]
[main-tabs]]])))

View File

@ -1,4 +1,5 @@
(ns syng-im.components.main-tabs
(:require-macros [syng-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [view
text-input
@ -8,23 +9,22 @@
[syng-im.components.tabs.tabs :refer [tabs]]
[syng-im.utils.logging :as log]))
(defn main-tabs []
(let [view-id (subscribe [:view-id])]
(fn []
[tabs {:selected-index (case @view-id
:chat-list 0
:discovery 1
:contact-list 2
0)
:tab-list [{:handler #(dispatch [:navigate-to
:chat-list])
:title "Chats"
:icon "icon_tab_chats"}
{:handler #(dispatch [:navigate-to
:discovery])
:title "Discover"
:icon "icon_tab_discovery"}
{:handler #(dispatch [:navigate-to
:contact-list])
:title "Contacts"
:icon "icon_tab_contacts"}]}])))
(defview main-tabs []
[view-id [:get :view-id]]
[tabs {:selected-index (case view-id
:chat-list 0
:discovery 1
:contact-list 2
0)
:tab-list [{:handler #(dispatch [:navigate-to
:chat-list])
:title "Chats"
:icon "icon_tab_chats"}
{:handler #(dispatch [:navigate-to
:discovery])
:title "Discover"
:icon "icon_tab_discovery"}
{:handler #(dispatch [:navigate-to
:contact-list])
:title "Contacts"
:icon "icon_tab_contacts"}]}])

View File

@ -1,4 +1,5 @@
(ns syng-im.components.tabs.tab
(:require-macros [syng-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [view
text-input
@ -8,13 +9,11 @@
[reagent.core :as r]
[syng-im.components.tabs.styles :as st]))
(defn tab [{:keys [handler title icon selected-index index]}]
(fn [{:keys [handler title icon selected-index index]}]
[touchable-highlight {:style st/tab
:onPress #(do (reset! selected-index index)
(handler))}
[view {:style st/tab-container}
(defview tab [{:keys [handler title icon selected-index index]}]
[touchable-highlight {:style st/tab
:onPress handler}
[view {:style st/tab-container}
[image {:source {:uri icon}
:style st/tab-icon}]
(when (= @selected-index index)
[text {:style st/tab-title} title])]]))
(when (= selected-index index)
[text {:style st/tab-title} title])]])

View File

@ -1,4 +1,5 @@
(ns syng-im.components.tabs.tabs
(:require-macros [syng-im.utils.views :refer [defview]])
(:require [re-frame.core :refer [subscribe dispatch dispatch-sync]]
[syng-im.components.react :refer [view
text-input
@ -10,14 +11,12 @@
[syng-im.components.tabs.tab :refer [tab]]))
(defn create-tab [index data selected-index]
(let [data (merge data {:key index
:index index
(let [data (merge data {:key index
:index index
:selected-index selected-index})]
[tab data]))
(defn tabs [{:keys [style tab-list selected-index]}]
(let [selected-index (r/atom selected-index)]
(fn [{:keys [style tab-list]}]
(let [style (merge st/tabs style)]
[view {:style style}
(doall (map-indexed #(create-tab %1 %2 selected-index) tab-list))]))))
(defview tabs [{:keys [style tab-list selected-index]}]
(let [style (merge st/tabs style)]
[view {:style style}
(doall (map-indexed #(create-tab %1 %2 selected-index) tab-list))]))

View File

@ -9,6 +9,7 @@
[syng-im.contacts.views.contact :refer [contact-view]]
[syng-im.components.styles :refer [toolbar-background2]]
[syng-im.components.toolbar :refer [toolbar]]
[syng-im.components.main-tabs :refer [main-tabs]]
[syng-im.contacts.styles :as st]
[syng-im.utils.listview :as lw]))
@ -32,4 +33,5 @@
[list-view {:dataSource (lw/to-datasource contacts)
:enableEmptySections true
:renderRow render-row
:style st/contacts-list}])])
:style st/contacts-list}])
[main-tabs]])

View File

@ -9,6 +9,7 @@
[syng-im.components.toolbar :refer [toolbar]]
[syng-im.discovery.views.popular :refer [popular]]
[syng-im.discovery.views.recent :refer [discovery-recent]]
[syng-im.components.main-tabs :refer [main-tabs]]
[syng-im.discovery.styles :as st]))
(defn get-hashtags [status]
@ -49,4 +50,5 @@
[popular]
[view st/section-spacing
[text {:style st/discovery-subtitle} "Recent"]]
[discovery-recent]]])
[discovery-recent]]
[main-tabs]])