···148148 */
149149 const shouldHandleScroll = useRef(true)
150150 /**
151151- * Called any time the content size of the list changes, _just_ before paint.
151151+ * Called any time the content size of the list changes. Could be a fresh
152152+ * render, items being added to the list, or any resize that changes the
153153+ * scrollable size of the content.
152154 *
153155 * We want this to fire every time we change params (which will reset
154156 * `deferParents` via `onLayout` on the anchor post, due to the key change),
···193195 * will give us a _positive_ offset, which will scroll the anchor post
194196 * back _up_ to the top of the screen.
195197 */
196196- list.scrollToOffset({
197197- offset: anchorOffsetTop - headerHeight,
198198- })
198198+ const offset = anchorOffsetTop - headerHeight
199199+ list.scrollToOffset({offset})
199200200201 /*
201201- * After the second pass, `deferParents` will be `false`, and we need
202202- * to ensure this doesn't run again until scroll handling is requested
203203- * again via `shouldHandleScroll.current === true` and a params
204204- * change via `prepareForParamsUpdate`.
202202+ * After we manage to do a positive adjustment, we need to ensure this
203203+ * doesn't run again until scroll handling is requested again via
204204+ * `shouldHandleScroll.current === true` and a params change via
205205+ * `prepareForParamsUpdate`.
205206 *
206207 * The `isRoot` here is needed because if we're looking at the anchor
207208 * post, this handler will not fire after `deferParents` is set to
208209 * `false`, since there are no parents to render above it. In this case,
209209- * we want to make sure `shouldHandleScroll` is set to `false` so that
210210- * subsequent size changes unrelated to a params change (like pagination)
211211- * do not affect scroll.
210210+ * we want to make sure `shouldHandleScroll` is set to `false` right away
211211+ * so that subsequent size changes unrelated to a params change (like
212212+ * pagination) do not affect scroll.
212213 */
213213- if (!deferParents || isRoot) shouldHandleScroll.current = false
214214+ if (offset > 0 || isRoot) shouldHandleScroll.current = false
214215 }
215216 })
216217