Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Created January 15, 2017 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pesterhazy/f6e6fca0c663a5e6bcc21a09b8b01747 to your computer and use it in GitHub Desktop.
Save pesterhazy/f6e6fca0c663a5e6bcc21a09b8b01747 to your computer and use it in GitHub Desktop.
Reagent react-native list-view
(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