-
-
Save olivergeorge/97a5c7179d2e7076da68e9cc4dc0bea8 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
(ns interop.react-native | |
(:require [reagent.core :as r] | |
[react-native :as module])) | |
;... | |
(def flat-list (r/adapt-react-class module/FlatList)) |
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
(defn list-options2 | |
[{:keys [options value on-press]}] | |
(let [initial-idx (keep-indexed (fn [idx {:keys [pk]}] (when (= pk value) idx)) options) | |
first-pk (:pk (first options)) | |
last-pk (:pk (last options)) | |
padding-top 40 | |
padding-bottom 40 | |
row-height 50] | |
[rn/flat-list | |
{:data (into-array options) | |
:key-extractor (fn [option] | |
(:pk option)) | |
:initial-scroll-index initial-idx | |
:initialNumToRender (count options) | |
:get-item-layout (fn [{:keys [pk]} index] | |
#js {:length (cond (= pk first-pk) (+ row-height padding-top) | |
(= pk last-pk) (+ row-height padding-bottom) | |
:else row-height) | |
:offset (* index row-height) | |
:index index}) | |
:render-item (fn [js-props] | |
(let [{:keys [pk description]} (gobj/get js-props "item")] | |
(r/as-element | |
[rn/view | |
(when (= pk first-pk) | |
[rn/view {:style {:height padding-top}}]) | |
(if (= pk value) | |
[list-tick {:title description :on-press #(on-press nil) :selected? true}] | |
[list-tick {:title description :on-press #(on-press pk)}]) | |
(when (= pk last-pk) | |
[rn/view {:style {:height padding-bottom}}])])))}])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment