Skip to content

Commit 3367f87

Browse files
committed
Revert "fix: remove workaround for removing clipped subviews (software-mansion#2596)"
This reverts commit 2aa278c.
1 parent 5408827 commit 3367f87

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

android/src/main/java/com/swmansion/rnscreens/Screen.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
1717
import com.facebook.react.bridge.GuardedRunnable
1818
import com.facebook.react.bridge.ReactContext
1919
import com.facebook.react.uimanager.PixelUtil
20+
import com.facebook.react.uimanager.ReactClippingViewGroup
2021
import com.facebook.react.uimanager.UIManagerHelper
2122
import com.facebook.react.uimanager.UIManagerModule
2223
import com.facebook.react.uimanager.events.EventDispatcher
24+
import com.facebook.react.views.scroll.ReactHorizontalScrollView
25+
import com.facebook.react.views.scroll.ReactScrollView
2326
import com.google.android.material.bottomsheet.BottomSheetBehavior
2427
import com.google.android.material.shape.CornerFamily
2528
import com.google.android.material.shape.MaterialShapeDrawable
@@ -401,6 +404,29 @@ class Screen(
401404
}
402405

403406
if (child is ViewGroup) {
407+
// The children are miscounted when there's removeClippedSubviews prop
408+
// set to true (which is the default for FlatLists).
409+
// Unless the child is a ScrollView it's safe to assume that it's true
410+
// and add a simple view for each possibly clipped item to make it work as expected.
411+
// See https://github.com/software-mansion/react-native-screens/pull/2495
412+
413+
if (child is ReactClippingViewGroup &&
414+
child.removeClippedSubviews &&
415+
child !is ReactScrollView &&
416+
child !is ReactHorizontalScrollView
417+
) {
418+
// We need to workaround the issue until our changes land in core.
419+
// Some views do not accept any children or have set amount and they throw
420+
// when we want to brute-forcefully manipulate that.
421+
// Is this ugly? Very. Do we have better option before changes land in core?
422+
// I'm not aware of any.
423+
try {
424+
for (j in 0 until child.childCount) {
425+
child.addView(View(context))
426+
}
427+
} catch (_: Exception) {
428+
}
429+
}
404430
startTransitionRecursive(child)
405431
}
406432
}

apps/src/tests/Test2282.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,12 @@ function ExtraNestedFlatlist(props: Partial<FlatListProps<number>>) {
135135

136136
const Stack = createNativeStackNavigator();
137137

138-
/**
139-
* You can use either the App component with `ListScreen` or `ListScreenSimplified`,
140-
* of `AppSimple` component which has little to no navigation and attempts to reproduce the issue
141-
*/
142-
143138
export default function App(): React.JSX.Element {
144139
return (
145140
<NavigationContainer>
146141
<Stack.Navigator screenOptions={{ animation: 'slide_from_right' }}>
147142
<Stack.Screen name="Home" component={Home} />
148-
<Stack.Screen name="List" component={ListScreenSimplified}/> {/* <- Exchange here for ListScreen for more complex case */}
143+
<Stack.Screen name="List" component={ListScreenSimplified}/>
149144
</Stack.Navigator>
150145
</NavigationContainer>
151146
);

0 commit comments

Comments
 (0)