m-pull-to-refresh
m-pull-to-refresh copied to clipboard
与 ListView 同时使用时没有正确触发重新渲染
在 ListView
中使用时,传过来的 getScrollContainer
第一次必然得到 undefined
,第二次渲染才会使用 ListView
提供的 container,且第二次渲染不会自动触发,在 onTouchMove
等事件产生导致重新渲染时会导致 DOM 结构整体变化,以及 children 被重新创建 / 渲染。
https://github.com/react-component/m-pull-to-refresh/blob/e60268f7ffe19b355482418f85fded80e8a78565/src/PullToRefresh.tsx#L297
相关:https://github.com/react-component/m-pull-to-refresh/issues/171
复现:https://clxjt.csb.app/
workaround:
const MyPullToRefresh = ({ getScrollContainer, ...props }) => (
<PullToRefresh
getScrollContainer={() => getScrollContainer?.() || true}
{...props}
/>
);
由于 getScrollContainer
被 ListView
覆盖了,因此只能自己包一个 MyPullToRefresh
,保证返回值非 undefined
。