Skip to content

Commit

Permalink
fix(Android): going back on fabric with horizontal list crash (#2403)
Browse files Browse the repository at this point in the history
## Description

This PR handles yet another case for going back on fabric. In the
previous one
(#2383) I
omitted a case where a horizontal list is simply rendered w/o being
nested in any other list!

Fixes #2341 

## Changes

- updated `Test2292.tsx` repro
- handle `parentView is ReactHorizontalScrollView`

<!--

## Screenshots / GIFs

Here you can add screenshots / GIFs documenting your change.

You can add before / after section if you're changing some behavior.

### Before

### After

-->

## Test code and steps to reproduce

- use `Test2282.tsx` repro

## Checklist

- [x] Included code example that can be used to test this change
- [x] Ensured that CI passes
  • Loading branch information
alduzy authored Oct 14, 2024
1 parent 63af46b commit d40e108
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
13 changes: 10 additions & 3 deletions android/src/main/java/com/swmansion/rnscreens/ext/ViewExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ internal fun View.isInsideScrollViewWithRemoveClippedSubviews(): Boolean {
}
var parentView = this.parent
while (parentView is ViewGroup && parentView !is ScreenStack) {
if (parentView is ReactScrollView) {
return parentView.removeClippedSubviews
when (parentView) {
is ReactHorizontalScrollView -> {
return parentView.removeClippedSubviews
}
is ReactScrollView -> {
return parentView.removeClippedSubviews
}
else -> {
parentView = parentView.parent
}
}
parentView = parentView.parent
}
return false
}
20 changes: 15 additions & 5 deletions apps/src/tests/Test2282.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,32 @@ function Home({ navigation }: any) {
}

function ListScreen() {
return (
<>
<ParentFlatlist />
<ParentFlatlist horizontal />
</>
);
}

function ParentFlatlist(props: Partial<FlatListProps<number>>) {
return (
<FlatList
data={Array.from({ length: 30 }).fill(0)}
data={Array.from({ length: 30 }).fill(0) as number[]}
renderItem={({ index }) => {
if (index === 15) {
if (index === 10) {
return <NestedFlatlist key={index} />;
} else if (index === 18) {
} else if (index === 15) {
return <ExtraNestedFlatlist key={index} />;
} else if (index === 26) {
} else if (index === 20) {
return <NestedFlatlist key={index} horizontal />;
} else if (index === 28) {
} else if (index === 25) {
return <ExtraNestedFlatlist key={index} horizontal />;
} else {
return <Item key={index}>List item {index + 1}</Item>;
}
}}
{...props}
/>
);
}
Expand Down

0 comments on commit d40e108

Please sign in to comment.