Commit d508f85
committed
Fix autoplay timing by stabilizing _scrollToIndex and processing all viewability changes
Two issues caused unreliable autoplay behavior:
1. _scrollToIndex was recreated on every prevIndex change (via its dependency
on currentIndexes.index and currentIndexes.prevIndex). Since it was in the
autoplay useEffect dependency array, this caused unnecessary timer resets
whenever _onViewableItemsChanged updated prevIndex during scroll animations.
Fix: use functional state updater so _scrollToIndex has an empty dependency
array and remains a stable reference.
2. _onViewableItemsChanged only processed the first item in the changed array.
When FlatList reported multiple viewability changes simultaneously (e.g.,
one item becoming non-viewable and another becoming viewable), the second
change was silently dropped. Fix: iterate over all changed items with
forEach to ensure correct index tracking.
https://claude.ai/code/session_012WFS8zGREtMjNNj9NECCVw1 parent 16fb10e commit d508f85
1 file changed
Lines changed: 23 additions & 30 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 105 | + | |
| 106 | + | |
109 | 107 | | |
110 | | - | |
| 108 | + | |
111 | 109 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
122 | 114 | | |
| 115 | + | |
| 116 | + | |
123 | 117 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
131 | 123 | | |
132 | 124 | | |
133 | 125 | | |
| |||
216 | 208 | | |
217 | 209 | | |
218 | 210 | | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
226 | 219 | | |
227 | | - | |
| 220 | + | |
228 | 221 | | |
229 | 222 | | |
230 | 223 | | |
| |||
0 commit comments