fix: use callback hook for gesture section-list render function

This commit is contained in:
Sean Hagstrom 2024-11-21 10:28:42 -08:00
parent e9c56a720c
commit d98de2efbf
No known key found for this signature in database
GPG Key ID: 5257FEDF56307320
1 changed files with 17 additions and 12 deletions

View File

@ -9,6 +9,7 @@
gestureHandlerRootHOC
FlatList
ScrollView)]
[react-native.core :as rn]
[react-native.flat-list :as rn-flat-list]
[reagent.core :as reagent]))
@ -112,17 +113,21 @@
render-fn]
:or {sticky-section-headers-enabled true}
:as props}]
(let [data (flatten-sections sections)]
(let [data (flatten-sections sections)
render-item (rn/use-callback
(fn [p1 p2 p3 p4]
[:<>
(if (:header? p1)
[render-section-header-fn p1 p2 p3 p4]
[render-fn p1 p2 p3 p4])
(when (and render-section-footer-fn
(is-last-item-in-section data p2))
[render-section-footer-fn p1 p2 p3 p4])])
[render-fn render-section-header-fn render-section-footer-fn])]
[flat-list
(merge props
{:data data
:render-fn (fn [p1 p2 p3 p4]
[:<>
(if (:header? p1)
[render-section-header-fn p1 p2 p3 p4]
[render-fn p1 p2 p3 p4])
(when (and render-section-footer-fn
(is-last-item-in-section data p2))
[render-section-footer-fn p1 p2 p3 p4])])
:sticky-header-indices (when sticky-section-headers-enabled
(find-sticky-indices data))})]))
{:data data
:render-fn render-item
:sticky-header-indices
(when sticky-section-headers-enabled
(find-sticky-indices data))})]))