From 1df074c1009ceb68026b2a433fc7b7bb8288f448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Thor=C3=A9n?= Date: Thu, 12 Oct 2017 13:31:39 +0200 Subject: [PATCH] Extend list components to set separator? with same default behavior - base-list props private and takes additional separator arg - flat-list and section-list extended with separator? key that defaults to true --- src/status_im/components/list/views.cljs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/status_im/components/list/views.cljs b/src/status_im/components/list/views.cljs index c7509292f3..69ad2319c7 100644 --- a/src/status_im/components/list/views.cljs +++ b/src/status_im/components/list/views.cljs @@ -75,24 +75,25 @@ (defn- section-separator [] [rn/view lst/section-separator]) -(defn base-list-props [render-fn empty-component] +(defn- base-list-props [render-fn empty-component separator?] (merge {:keyExtractor (fn [_ i] i)} - (when render-fn {:renderItem (wrap-render-fn render-fn)}) - (when p/ios? {:ItemSeparatorComponent (fn [] (r/as-element [separator]))}) - ; TODO(jeluard) Does not work with our current ReactNative version - (when empty-component {:ListEmptyComponent (r/as-element [empty-component])}))) + (when render-fn {:renderItem (wrap-render-fn render-fn)}) + (when (and p/ios? separator?) {:ItemSeparatorComponent (fn [] (r/as-element [separator]))}) + ;; TODO(jeluard) Does not work with our current ReactNative version + (when empty-component {:ListEmptyComponent (r/as-element [empty-component])}))) (defn flat-list "A wrapper for FlatList. See https://facebook.github.io/react-native/docs/flatlist.html" - [{:keys [data render-fn empty-component] :as props}] + [{:keys [data render-fn empty-component separator?] :as props + :or {separator? true}}] {:pre [(or (nil? data) (sequential? data))]} (if (and (empty? data) empty-component) ;; TODO(jeluard) remove when native :ListEmptyComponent is supported empty-component [flat-list-class - (merge (base-list-props render-fn empty-component) + (merge (base-list-props render-fn empty-component separator?) {:data (clj->js data)} props)])) @@ -116,11 +117,13 @@ (defn section-list "A wrapper for SectionList. See https://facebook.github.io/react-native/docs/sectionlist.html" - [{:keys [sections render-fn empty-component render-section-header-fn] :or {render-section-header-fn default-render-section-header} :as props}] + [{:keys [sections render-fn empty-component render-section-header-fn separator?] :as props + :or {render-section-header-fn default-render-section-header + separator? true}}] (if (and (every? #(empty? (:data %)) sections) empty-component) empty-component [section-list-class - (merge (base-list-props render-fn empty-component) + (merge (base-list-props render-fn empty-component separator?) {:sections (clj->js (map wrap-per-section-render-fn sections)) :renderSectionHeader (wrap-render-section-header-fn render-section-header-fn)} (when p/ios? {:SectionSeparatorComponent (fn [] (r/as-element [section-separator]))})