Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/recyclerview/RecyclerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ const RecyclerViewComponent = <T,>(
if (internalViewRef.current && firstChildViewRef.current) {
// Measure the outer container size and inner container layout
const outerViewSize = measureParentSize(internalViewRef.current);
if (outerViewSize.width === 0 && outerViewSize.height === 0) {
containerViewSizeRef.current = outerViewSize;
return;
}
const firstChildViewLayout = measureFirstChildLayout(
firstChildViewRef.current,
internalViewRef.current
Expand Down Expand Up @@ -204,6 +208,12 @@ const RecyclerViewComponent = <T,>(
if (pendingChildIds.size > 0) {
return;
}
if (
containerViewSizeRef.current?.width === 0 &&
containerViewSizeRef.current?.height === 0
) {
return;
}
const layoutInfo = Array.from(refHolder, ([index, viewHolderRef]) => {
const layout = measureItemLayout(
viewHolderRef.current!,
Expand Down
16 changes: 14 additions & 2 deletions src/recyclerview/hooks/useRecyclerViewController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,14 @@ export function useRecyclerViewController<T>(
}: ScrollToOffsetParams) => {
const { horizontal } = recyclerViewManager.props;
if (scrollViewRef.current) {
// Adjust offset for RTL layouts in horizontal mode
if (I18nManager.isRTL && horizontal) {
// Adjust offset for RTL layouts in horizontal mode.
// Gated on hasLayout(): the RTL math reads child container and
// window size, which throw while the list is hidden (0x0).
if (
I18nManager.isRTL &&
horizontal &&
recyclerViewManager.hasLayout()
) {
// eslint-disable-next-line no-param-reassign
offset =
adjustOffsetForRTL(
Expand Down Expand Up @@ -323,6 +329,12 @@ export function useRecyclerViewController<T>(
viewPosition,
viewOffset,
}: ScrollToIndexParams): Promise<void> => {
// While the list is hidden (parent measured 0x0) the layout manager
// is never initialized, so reading window size below would throw.
// No-op until the next layout pass makes scrolling meaningful.
if (!recyclerViewManager.hasLayout()) {
return Promise.resolve();
}
return new Promise((resolve) => {
const { horizontal } = recyclerViewManager.props;
if (
Expand Down
Loading