use the new defview

Former-commit-id: dfc772d0cd61f60a245b8c1c624228fae2a5eac9
This commit is contained in:
Adrian Tiberius 2016-05-17 17:03:21 +03:00
parent daf75759fc
commit a03b1a0357
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.drawer.view :refer [drawer-view open-drawer]]
[syng-im.components.styles :refer [color-blue]] [syng-im.components.styles :refer [color-blue]]
[syng-im.components.toolbar :refer [toolbar]] [syng-im.components.toolbar :refer [toolbar]]
[syng-im.components.main-tabs :refer [main-tabs]]
[syng-im.components.icons.ionicons :refer [icon]] [syng-im.components.icons.ionicons :refer [icon]]
[syng-im.chats-list.styles :as st])) [syng-im.chats-list.styles :as st]))
@ -37,7 +38,9 @@
:renderRow (fn [row _ _] :renderRow (fn [row _ _]
(list-item [chat-list-item row])) (list-item [chat-list-item row]))
:style st/list-container}] :style st/list-container}]
[action-button {:buttonColor color-blue} [action-button {:buttonColor color-blue
:offsetY 72
:offsetX 16}
[action-button-item [action-button-item
{:title "New Chat" {:title "New Chat"
:buttonColor :#9b59b6 :buttonColor :#9b59b6
@ -49,4 +52,5 @@
:buttonColor :#1abc9c :buttonColor :#1abc9c
:onPress #(dispatch [:show-group-new])} :onPress #(dispatch [:show-group-new])}
[icon {:name :person-stalker [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 (ns syng-im.components.main-tabs
(:require-macros [syng-im.utils.views :refer [defview]])
(: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
text-input text-input
@ -8,23 +9,22 @@
[syng-im.components.tabs.tabs :refer [tabs]] [syng-im.components.tabs.tabs :refer [tabs]]
[syng-im.utils.logging :as log])) [syng-im.utils.logging :as log]))
(defn main-tabs [] (defview main-tabs []
(let [view-id (subscribe [:view-id])] [view-id [:get :view-id]]
(fn [] [tabs {:selected-index (case view-id
[tabs {:selected-index (case @view-id :chat-list 0
:chat-list 0 :discovery 1
:discovery 1 :contact-list 2
:contact-list 2 0)
0) :tab-list [{:handler #(dispatch [:navigate-to
:tab-list [{:handler #(dispatch [:navigate-to :chat-list])
:chat-list]) :title "Chats"
:title "Chats" :icon "icon_tab_chats"}
:icon "icon_tab_chats"} {:handler #(dispatch [:navigate-to
{:handler #(dispatch [:navigate-to :discovery])
:discovery]) :title "Discover"
:title "Discover" :icon "icon_tab_discovery"}
:icon "icon_tab_discovery"} {:handler #(dispatch [:navigate-to
{:handler #(dispatch [:navigate-to :contact-list])
:contact-list]) :title "Contacts"
:title "Contacts" :icon "icon_tab_contacts"}]}])
:icon "icon_tab_contacts"}]}])))

View File

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

View File

@ -1,4 +1,5 @@
(ns syng-im.components.tabs.tabs (ns syng-im.components.tabs.tabs
(:require-macros [syng-im.utils.views :refer [defview]])
(: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
text-input text-input
@ -10,14 +11,12 @@
[syng-im.components.tabs.tab :refer [tab]])) [syng-im.components.tabs.tab :refer [tab]]))
(defn create-tab [index data selected-index] (defn create-tab [index data selected-index]
(let [data (merge data {:key index (let [data (merge data {:key index
:index index :index index
:selected-index selected-index})] :selected-index selected-index})]
[tab data])) [tab data]))
(defn tabs [{:keys [style tab-list selected-index]}] (defview tabs [{:keys [style tab-list selected-index]}]
(let [selected-index (r/atom selected-index)] (let [style (merge st/tabs style)]
(fn [{:keys [style tab-list]}] [view {:style style}
(let [style (merge st/tabs style)] (doall (map-indexed #(create-tab %1 %2 selected-index) tab-list))]))
[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.contacts.views.contact :refer [contact-view]]
[syng-im.components.styles :refer [toolbar-background2]] [syng-im.components.styles :refer [toolbar-background2]]
[syng-im.components.toolbar :refer [toolbar]] [syng-im.components.toolbar :refer [toolbar]]
[syng-im.components.main-tabs :refer [main-tabs]]
[syng-im.contacts.styles :as st] [syng-im.contacts.styles :as st]
[syng-im.utils.listview :as lw])) [syng-im.utils.listview :as lw]))
@ -32,4 +33,5 @@
[list-view {:dataSource (lw/to-datasource contacts) [list-view {:dataSource (lw/to-datasource contacts)
:enableEmptySections true :enableEmptySections true
:renderRow render-row :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.components.toolbar :refer [toolbar]]
[syng-im.discovery.views.popular :refer [popular]] [syng-im.discovery.views.popular :refer [popular]]
[syng-im.discovery.views.recent :refer [discovery-recent]] [syng-im.discovery.views.recent :refer [discovery-recent]]
[syng-im.components.main-tabs :refer [main-tabs]]
[syng-im.discovery.styles :as st])) [syng-im.discovery.styles :as st]))
(defn get-hashtags [status] (defn get-hashtags [status]
@ -49,4 +50,5 @@
[popular] [popular]
[view st/section-spacing [view st/section-spacing
[text {:style st/discovery-subtitle} "Recent"]] [text {:style st/discovery-subtitle} "Recent"]]
[discovery-recent]]]) [discovery-recent]]
[main-tabs]])