Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native scrollview on android. The children overlap the border radius when scrolling

On android when I apply a border radius to a scroll view the inner container ignores the outer border radius and I can't figure out how to make it conform. This is on Pixel 2 simulator, the red dotted lines show the underlying border radius and where the overlap is. The code is just a standard scrollview I made to double check it happens on the simplest scrollview implementation which it does.

enter image description here

  <ScrollView
    contentContainerStyle={{
      alignItems: 'center',
      justifyContent: 'space-between',
    }}
    style={{
      padding: 20,
      backgroundColor: 'green',
      borderTopLeftRadius: 45,
      borderTopRightRadius: 45,
    }}>
    <View
      style={{
        width: '100%',
        height: 400,
        borderRadius: 20,
        backgroundColor: 'red',
      }}
    />
    <View
      style={{
        width: '100%',
        height: 400,
        borderRadius: 20,
        backgroundColor: 'red',
      }}
    />
    <View
      style={{
        width: '100%',
        height: 400,
        borderRadius: 20,
        backgroundColor: 'red',
      }}
    />
    <View
      style={{
        width: '100%',
        height: 400,
        borderRadius: 20,
        backgroundColor: 'red',
      }}
    />
  </ScrollView>
like image 934
Pony Avatar asked May 11 '20 20:05

Pony


People also ask

How do you scroll in React Native ScrollView?

React Native ScrollView. The ScrollView is a generic scrollable container, which scrolls multiple child components and views inside it. In the ScrollView, we can scroll the components in both direction vertically and horizontally. By default, the ScrollView container scrolls its components and views in vertical.

Do children overlap the border radius when scrolling on Android?

The children overlap the border radius when scrolling On android when I apply a border radius to a scroll view the inner container ignores the outer border radius and I can't figure out how to make it conform. This is on Pixel 2 simulator, the red dotted lines show the underlying border radius and where the overlap is.

How do I scroll a ScrollView horizontally?

In the ScrollView, we can scroll the components in both direction vertically and horizontally. By default, the ScrollView container scrolls its components and views in vertical. To scroll its components in horizontal, it uses the props horizontal: true (default, horizontal: false).

When does the Scroll View stop on the next index?

When true, the scroll view stops on the next index (in relation to scroll position at release) regardless of how fast the gesture is. This can be used for pagination when the page is less than the width of the horizontal ScrollView or the height of the vertical ScrollView.


1 Answers

Just wrap Scrollview with View and set overflow: 'hidden', structure your views like bellow code. It will force all children views to hidden if overflow.

<View
  style={{ 
      borderRadius: 45l
      overflow: 'hidden',
  }}
>
  // ->> Put your scrollview in here
  <Scrollview>
    {...children}
  </Scrollview>
</View>
like image 152
Thinh Phan Avatar answered Oct 25 '22 15:10

Thinh Phan