Created
January 15, 2017 16:00
-
-
Save pesterhazy/f6e6fca0c663a5e6bcc21a09b8b01747 to your computer and use it in GitHub Desktop.
Reagent react-native list-view
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
(def list-view (r/adapt-react-class (.-ListView js/React))) | |
; use sg-list-view instead of list-view for better performance | |
; in long lists | |
; | |
; (def sg-list-view* (r/adapt-react-class (js/require "react-native-sglistview/lib/SGListView.js"))) | |
; | |
;(defn sg-list-view | |
; "Adds some defaults to sg-list-view*" | |
; [m] | |
; [sg-list-view* (merge {:stickyHeaderIndices #js [] ;; default in ListView | |
; :scrollRenderAheadDistance 1000} | |
; m)]) | |
(def list-data-source (.-DataSource (.-ListView js/React))) | |
(defn list-view-ui [{:keys [items opts]}] | |
(let [!ds (atom (-> (list-data-source. #js {:rowHasChanged not=}) | |
(.cloneWithRows (into-array items))))] | |
(r/create-class | |
{:component-will-receive-props (fn [this [_ {:keys [items]}]] | |
(swap! !ds #(.cloneWithRows % (into-array items)))) | |
:reagent-render (fn [{:keys [items]}] | |
[list-view (merge {:dataSource @!ds} opts)])}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment