Last active
June 24, 2016 10:05
-
-
Save alwx/4c9cc6818f2902d674ebf4ad4165649a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; handlers for different types of list items | |
(defmulti render-row (fn [{item :item}] (:type item))) | |
(defmethod render-row "header" | |
[_] | |
[ui/view | |
[ui/text "Header"]]) | |
(defmethod render-row "subheader" | |
[_] | |
[ui/view | |
[ui/text "Subheader"]]) | |
(defmethod render-row "item" | |
[{:keys [image]}] | |
[ui/view | |
;; it will be loaded automatically! | |
[ui/image {:source {:uri image}}]]) | |
;; method to render our scene | |
(defn scene [] | |
[ui/list-view | |
{:flex 1 | |
:dataSource (ui/list-source [{:type "header"} | |
{:type "subheader"} | |
{:type "item" :image "http://link.to.image"}]) | |
:stickyHeaderIndices [0 1] | |
:renderRow (fn [item] | |
;; this is a bit tricky | |
;; here we use transformation from js to clj | |
;; because list-source stores data in js structure anyway | |
(r/as-element | |
(render-row {:item (-> item | |
(js->clj) | |
(keywordize-keys))})))}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment