Skip to content

Commit 5a9afbb

Browse files
alduzykkafar
authored andcommitted
fix(Android): going back on fabric with horizontal list crash (#2403)
## 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 (cherry picked from commit d40e108)
1 parent 71db286 commit 5a9afbb

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

android/src/main/java/com/swmansion/rnscreens/ext/ViewExt.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,17 @@ internal fun View.isInsideScrollViewWithRemoveClippedSubviews(): Boolean {
4040
}
4141
var parentView = this.parent
4242
while (parentView is ViewGroup && parentView !is ScreenStack) {
43-
if (parentView is ReactScrollView) {
44-
return parentView.removeClippedSubviews
43+
when (parentView) {
44+
is ReactHorizontalScrollView -> {
45+
return parentView.removeClippedSubviews
46+
}
47+
is ReactScrollView -> {
48+
return parentView.removeClippedSubviews
49+
}
50+
else -> {
51+
parentView = parentView.parent
52+
}
4553
}
46-
parentView = parentView.parent
4754
}
4855
return false
4956
}

apps/src/tests/Test2282.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,32 @@ function Home({ navigation }: any) {
3333
}
3434

3535
function ListScreen() {
36+
return (
37+
<>
38+
<ParentFlatlist />
39+
<ParentFlatlist horizontal />
40+
</>
41+
);
42+
}
43+
44+
function ParentFlatlist(props: Partial<FlatListProps<number>>) {
3645
return (
3746
<FlatList
38-
data={Array.from({ length: 30 }).fill(0)}
47+
data={Array.from({ length: 30 }).fill(0) as number[]}
3948
renderItem={({ index }) => {
40-
if (index === 15) {
49+
if (index === 10) {
4150
return <NestedFlatlist key={index} />;
42-
} else if (index === 18) {
51+
} else if (index === 15) {
4352
return <ExtraNestedFlatlist key={index} />;
44-
} else if (index === 26) {
53+
} else if (index === 20) {
4554
return <NestedFlatlist key={index} horizontal />;
46-
} else if (index === 28) {
55+
} else if (index === 25) {
4756
return <ExtraNestedFlatlist key={index} horizontal />;
4857
} else {
4958
return <Item key={index}>List item {index + 1}</Item>;
5059
}
5160
}}
61+
{...props}
5262
/>
5363
);
5464
}

0 commit comments

Comments
 (0)