Replace default keyExtractor with individual key-fns

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
Itoh, Masaru 2018-03-01 22:11:16 +09:00 committed by Julien Eluard
parent 946a44d257
commit 1b86179a81
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
24 changed files with 46 additions and 12 deletions

View File

@ -98,8 +98,8 @@
[react/text {:style style/empty-chat-text} [react/text {:style style/empty-chat-text}
(i18n/label :t/empty-chat-description)]] (i18n/label :t/empty-chat-description)]]
[list/flat-list {:data messages [list/flat-list {:data messages
:render-fn (fn [{:keys [message-id] :as message}] :key-fn #(or (:message-id %) (:value %))
^{:key message-id} :render-fn (fn [message]
[message-row {:group-chat group-chat [message-row {:group-chat group-chat
:current-public-key current-public-key :current-public-key current-public-key
:row message}]) :row message}])

View File

@ -27,6 +27,7 @@
:padding-bottom 12}} :padding-bottom 12}}
title] title]
[list/flat-list {:data contacts [list/flat-list {:data contacts
:key-fn :address
:render-fn (render-contact arg-index bot-db-key) :render-fn (render-contact arg-index bot-db-key)
:enableEmptySections true :enableEmptySections true
:keyboardShouldPersistTaps :always :keyboardShouldPersistTaps :always

View File

@ -76,5 +76,6 @@
[container (* styles/item-height (count statuses)) [container (* styles/item-height (count statuses))
[list/flat-list {:contentContainerStyle styles/bottom-info-list-container [list/flat-list {:contentContainerStyle styles/bottom-info-list-container
:data statuses :data statuses
:key-fn :address
:render-fn (render-status @contacts) :render-fn (render-status @contacts)
:enableEmptySections true}]]]))}))) :enableEmptySections true}]]]))})))

View File

@ -100,6 +100,11 @@
(fn [data] (fn [data]
(reagent/as-element (f (.-item data) (.-index data) (.-separators data))))) (reagent/as-element (f (.-item data) (.-index data) (.-separators data)))))
(defn- wrap-key-fn [f]
(fn [data index]
{:post [(string? %)]}
(f data index)))
(def default-separator [react/view styles/separator]) (def default-separator [react/view styles/separator])
(def default-header [react/view styles/list-header-footer-spacing]) (def default-header [react/view styles/list-header-footer-spacing])
@ -109,9 +114,9 @@
(def section-separator [react/view styles/section-separator]) (def section-separator [react/view styles/section-separator])
(defn- base-list-props (defn- base-list-props
[{:keys [render-fn empty-component header separator default-separator?]}] [{:keys [key-fn render-fn empty-component header separator default-separator?]}]
(let [separator (or separator (when (and platform/ios? default-separator?) default-separator))] (let [separator (or separator (when (and platform/ios? default-separator?) default-separator))]
(merge {:keyExtractor (fn [_ i] (str i))} (merge (when key-fn {:keyExtractor (wrap-key-fn key-fn)})
(when render-fn {:renderItem (wrap-render-fn render-fn)}) (when render-fn {:renderItem (wrap-render-fn render-fn)})
(when separator {:ItemSeparatorComponent (fn [] (reagent/as-element separator))}) (when separator {:ItemSeparatorComponent (fn [] (reagent/as-element separator))})
(when empty-component {:ListEmptyComponent (fn [] (reagent/as-element empty-component))}) (when empty-component {:ListEmptyComponent (fn [] (reagent/as-element empty-component))})
@ -206,6 +211,7 @@
[react/view (merge styles/action-separator [react/view (merge styles/action-separator
action-separator-style)]) action-separator-style)])
:data actions :data actions
:key-fn (fn [_ i] (str i))
:render-fn #(render-action % styles)}]]) :render-fn #(render-action % styles)}]])
(defn list-with-label [{:keys [style]} label list] (defn list-with-label [{:keys [style]} label list]

View File

@ -37,6 +37,7 @@
[react/view styles/accounts-container [react/view styles/accounts-container
[react/view styles/accounts-list-container [react/view styles/accounts-list-container
[list/flat-list {:data (vals accounts) [list/flat-list {:data (vals accounts)
:key-fn :address
:render-fn (fn [account] [account-view account]) :render-fn (fn [account] [account-view account])
:separator [react/view {:height 12}]}]] :separator [react/view {:height 12}]}]]
[react/view [react/view

View File

@ -43,6 +43,7 @@
[react/text {:style open-dapp.styles/list-title} [react/text {:style open-dapp.styles/list-title}
(i18n/label :t/contacts)] (i18n/label :t/contacts)]
[list/flat-list {:data contacts [list/flat-list {:data contacts
:key-fn :address
:render-fn render-row :render-fn render-row
:default-separator? true :default-separator? true
:enableEmptySections true :enableEmptySections true

View File

@ -73,5 +73,6 @@
:font :medium} :font :medium}
(i18n/label :t/selected)]] (i18n/label :t/selected)]]
[list/flat-list {:data default-public-chats [list/flat-list {:data default-public-chats
:key-fn identity
:render-fn render-topic :render-fn render-topic
:default-separator? true}]])) :default-separator? true}]]))

View File

@ -39,6 +39,7 @@
[react/text {:style styles/list-title} [react/text {:style styles/list-title}
(i18n/label :t/selected-dapps)] (i18n/label :t/selected-dapps)]
[list/flat-list {:data dapps [list/flat-list {:data dapps
:key-fn :dapp-url
:render-fn render-row :render-fn render-row
:default-separator? true :default-separator? true
:enableEmptySections true :enableEmptySections true

View File

@ -32,6 +32,7 @@
(letsubs [contacts [:all-added-group-contacts (:group-id group)]] (letsubs [contacts [:all-added-group-contacts (:group-id group)]]
[list/flat-list {:style styles/contacts-list [list/flat-list {:style styles/contacts-list
:data contacts :data contacts
:key-fn :address
:render-fn (render-row group edit?) :render-fn (render-row group edit?)
:enableEmptySections true :enableEmptySections true
:keyboardShouldPersistTaps :always :keyboardShouldPersistTaps :always

View File

@ -51,6 +51,7 @@
[toolbar/simple-toolbar (i18n/label :t/contacts)] [toolbar/simple-toolbar (i18n/label :t/contacts)]
[list/flat-list {:style st/contacts-list-modal [list/flat-list {:style st/contacts-list-modal
:data contacts :data contacts
:key-fn :address
:render-fn (render-row click-handler action params) :render-fn (render-row click-handler action params)
:header (when-not (:hide-actions? params) :header (when-not (:hide-actions? params)
[react/view [react/view

View File

@ -38,6 +38,7 @@
true] true]
(if (seq dapps) (if (seq dapps)
[list/flat-list {:data (vals dapps) [list/flat-list {:data (vals dapps)
:key-fn :dapp-url
:render-fn render-dapp :render-fn render-dapp
:horizontal true :horizontal true
:default-separator? false :default-separator? false
@ -54,7 +55,9 @@
(if (zero? extras) (if (zero? extras)
dapps dapps
(concat dapps (concat dapps
(repeat (- columns extras) {:name ""}))))) (map (fn [i] {:name ""
:dapp-url (str "blank-" i)})
(range (- columns extras)))))))
(defview main [] (defview main []
(letsubs [all-dapps [:discover/all-dapps]] (letsubs [all-dapps [:discover/all-dapps]]
@ -65,6 +68,7 @@
toolbar/default-nav-back toolbar/default-nav-back
[toolbar/content-title (i18n/label :t/dapps)]] [toolbar/content-title (i18n/label :t/dapps)]]
[list/flat-list {:data (add-blank-dapps-for-padding columns (vals all-dapps)) [list/flat-list {:data (add-blank-dapps-for-padding columns (vals all-dapps))
:key-fn :dapp-url
:render-fn render-dapp :render-fn render-dapp
:num-columns columns :num-columns columns
:content-container-style styles/all-dapps-flat-list}]])))) :content-container-style styles/all-dapps-flat-list}]]))))

View File

@ -19,6 +19,7 @@
(defn tags-menu [tags] (defn tags-menu [tags]
[react/view styles/tag-title-container [react/view styles/tag-title-container
[list/flat-list {:data tags [list/flat-list {:data tags
:key-fn (fn [_ i] (str i))
:render-fn render-tag :render-fn render-tag
:horizontal true :horizontal true
:shows-horizontal-scroll-indicator false :shows-horizontal-scroll-indicator false

View File

@ -126,6 +126,7 @@
[react/view styles/public-chats-container [react/view styles/public-chats-container
[components/title-no-action :t/public-chats] [components/title-no-action :t/public-chats]
[list/flat-list {:data public-chats-mock-data [list/flat-list {:data public-chats-mock-data
:key-fn :topic
:render-fn render-public-chats-item}]]) :render-fn render-public-chats-item}]])
(defview discover [current-view?] (defview discover [current-view?]

View File

@ -37,6 +37,7 @@
[react/view {:flex 1} [react/view {:flex 1}
[list/flat-list {:style contacts.styles/contacts-list [list/flat-list {:style contacts.styles/contacts-list
:data contacts :data contacts
:key-fn :address
:render-fn render-function :render-fn render-function
:keyboardShouldPersistTaps :always}]]) :keyboardShouldPersistTaps :always}]])

View File

@ -13,6 +13,7 @@
[react/view {:flex 1} [react/view {:flex 1}
[list/flat-list {:data contacts [list/flat-list {:data contacts
:enableEmptySections true :enableEmptySections true
:key-fn :address
:render-fn (fn [contact] :render-fn (fn [contact]
[contact-view {:contact contact [contact-view {:contact contact
:extended? extended? :extended? extended?

View File

@ -56,6 +56,7 @@
[list/list-with-label {:flex 1} [list/list-with-label {:flex 1}
(i18n/label :t/members-title) (i18n/label :t/members-title)
[list/flat-list {:data contacts [list/flat-list {:data contacts
:key-fn :address
:render-fn render-contact :render-fn render-contact
:bounces false :bounces false
:keyboardShouldPersistTaps :always :keyboardShouldPersistTaps :always

View File

@ -82,8 +82,9 @@
(i18n/label :t/no-recent-chats)]] (i18n/label :t/no-recent-chats)]]
:else :else
[list/flat-list {:data home-items [list/flat-list {:data home-items
:render-fn (fn [[home-item-id :as home-item]] :key-fn first
^{:key home-item-id} [home-list-deletable home-item])}]) :render-fn (fn [home-item]
[home-list-deletable home-item])}])
(when platform/android? (when platform/android?
[home-action-button]) [home-action-button])
[connectivity/error-view]])) [connectivity/error-view]]))

View File

@ -66,6 +66,7 @@
[react/view {:flex 1} [react/view {:flex 1}
[list/flat-list {:style styles/networks-list [list/flat-list {:style styles/networks-list
:data (vals networks) :data (vals networks)
:key-fn :id
:render-fn (render-network network) :render-fn (render-network network)
:header [react/view :header [react/view
[actions-view [actions-view

View File

@ -65,6 +65,7 @@
[render-header wnodes] [render-header wnodes]
[list/flat-list {:data (vals wnodes) [list/flat-list {:data (vals wnodes)
:separator? false :separator? false
:key-fn :id
:render-fn (render-row current-wnode) :render-fn (render-row current-wnode)
:ListFooterComponent (reagent/as-element (render-footer)) :ListFooterComponent (reagent/as-element (render-footer))
:style styles/wnodes-list}]]])) :style styles/wnodes-list}]]]))

View File

@ -84,6 +84,7 @@
[react/view [react/view
[list/flat-list {:data contacts [list/flat-list {:data contacts
:separator list/default-separator :separator list/default-separator
:key-fn :address
:render-fn #(render-contact % admin?)}]])) :render-fn #(render-contact % admin?)}]]))
(defn members-list [admin?] (defn members-list [admin?]

View File

@ -60,6 +60,7 @@
[react/view {:style (assoc components.styles/flex :background-color :white)} [react/view {:style (assoc components.styles/flex :background-color :white)}
[list/flat-list {:default-separator? true [list/flat-list {:default-separator? true
:data (concat [tokens/ethereum] (wallet/current-tokens visible-tokens network)) :data (concat [tokens/ethereum] (wallet/current-tokens visible-tokens network))
:key-fn (comp str :symbol)
:render-fn #(render-token % balance type)}]]])) :render-fn #(render-token % balance type)}]]]))
(defn send-assets [] (defn send-assets []
@ -129,6 +130,7 @@
[components/toolbar (i18n/label :t/recipient)] [components/toolbar (i18n/label :t/recipient)]
[react/view styles/recent-recipients [react/view styles/recent-recipients
[list/flat-list {:data contacts [list/flat-list {:data contacts
:key-fn :address
:render-fn render-contact}]]])) :render-fn render-contact}]]]))
(defn contact-code [] (defn contact-code []

View File

@ -34,4 +34,5 @@
(i18n/label :t/wallet-assets)]] (i18n/label :t/wallet-assets)]]
[react/view {:style components.styles/flex} [react/view {:style components.styles/flex}
[list/flat-list {:data (tokens/tokens-for (ethereum/network->chain-keyword network)) [list/flat-list {:data (tokens/tokens-for (ethereum/network->chain-keyword network))
:key-fn (comp str :symbol)
:render-fn #(render-token % visible-tokens)}]]])) :render-fn #(render-token % visible-tokens)}]]]))

View File

@ -121,6 +121,7 @@
(when error-message? (when error-message?
(re-frame/dispatch [:wallet/show-error])) (re-frame/dispatch [:wallet/show-error]))
[list/section-list {:sections (map #(update-transactions % filter-data) transactions-history-list) [list/section-list {:sections (map #(update-transactions % filter-data) transactions-history-list)
:key-fn :hash
:render-fn render-transaction :render-fn render-transaction
:empty-component [react/text {:style styles/empty-text} :empty-component [react/text {:style styles/empty-text}
(i18n/label :t/transactions-history-empty)] (i18n/label :t/transactions-history-empty)]
@ -131,6 +132,7 @@
(letsubs [transactions [:wallet.transactions/unsigned-transactions-list]] (letsubs [transactions [:wallet.transactions/unsigned-transactions-list]]
[react/view {:style components.styles/flex} [react/view {:style components.styles/flex}
[list/flat-list {:data transactions [list/flat-list {:data transactions
:key-fn (fn [_ i] (str i))
:render-fn render-transaction :render-fn render-transaction
:empty-component [react/text {:style styles/empty-text :empty-component [react/text {:style styles/empty-text
:accessibility-label :no-unsigned-transactions-text} :accessibility-label :no-unsigned-transactions-text}
@ -171,7 +173,8 @@
:accessibility-label :select-all-button} :accessibility-label :select-all-button}
(i18n/label :t/transactions-filter-select-all)]] (i18n/label :t/transactions-filter-select-all)]]
[react/view {:style (merge {:background-color :white} components.styles/flex)} [react/view {:style (merge {:background-color :white} components.styles/flex)}
[list/section-list {:sections (wrap-filter-data filter-data)}]]])) [list/section-list {:sections (wrap-filter-data filter-data)
:key-fn :id}]]]))
(defn history-tab [active?] (defn history-tab [active?]
[react/text {:force-uppercase? true [react/text {:force-uppercase? true

View File

@ -75,6 +75,7 @@
[list/flat-list [list/flat-list
{:default-separator? true {:default-separator? true
:data assets :data assets
:key-fn (comp str :symbol)
:render-fn render-asset :render-fn render-asset
:on-refresh #(re-frame/dispatch [:update-wallet (map :symbol tokens)]) :on-refresh #(re-frame/dispatch [:update-wallet (map :symbol tokens)])
:refreshing refreshing?}]])) :refreshing refreshing?}]]))