14

I have the following component:

export default class StoreComponent extends Component {
  render() {
    return (
      <View style={styles.container}>
        <ScrollView contentContainerStyle={styles.scroll}>
          <StoreCarouselComponent />
          <StoreDiscountComponent />
          <StoreDetailsComponent />
        </ScrollView>
      </View>
    );
  }
}

with this style

import { StyleSheet, Dimensions, } from 'react-native';

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#ffffff',
  },
  scroll: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'center'
  },
  image: {
    width: Dimensions.get('window').width,
    height: 350,
  },
  box: {
    width: Dimensions.get('window').width - 30,
    position: 'absolute',
    shadowColor: '#000000',
    shadowOpacity: 0.34,
    shadowRadius: 5,
    shadowOffset: {
      width: 0,
      height: 10
    },
    elevation: 10,
    borderTopLeftRadius: 10,
    borderTopRightRadius: 10,
    borderBottomLeftRadius: 10,
    borderBottomRightRadius: 10,
    borderColor: 'lightgrey',
    backgroundColor: '#ffffff',
    padding: 10,
    marginTop: 410,

  },
  boxDiscount: {
    width: Dimensions.get('window').width - 30,
    position: 'absolute',
    shadowColor: '#000000',
    shadowOpacity: 0.34,
    shadowRadius: 5,
    shadowOffset: {
      width: 0,
      height: 10
    },
    elevation: 10,
    borderTopLeftRadius: 10,
    borderTopRightRadius: 10,
    borderBottomLeftRadius: 10,
    borderBottomRightRadius: 10,
    borderColor: 'lightgrey',
    backgroundColor: '#253241',
    padding: 10,
    marginTop: 320,
  },
  title: {
    fontSize: 30
  },
  distance: {
    fontSize: 20,
    color: '#767676'
  },
  distanceElement: {
    fontSize: 20,
    color: '#44D9E6'
  },
  address: {
    fontSize: 20,
    color: '#767676'
  },
  category: {
    fontSize: 20,
    color: '#767676',
  },
  categoryElement: {
    fontSize: 20,
    color: '#44D9E6',
  },
  hr: {
    borderBottomColor: 'lightgrey',
    borderBottomWidth: 1,
  },
  icons: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'center',
  }
});

export default styles;

my scrollview works on ios but on android don't and I don't understand why

here a an image of the app and as you can see I need to scroll on android:

enter image description here

8 Answers 8

22

try to import from

import { ScrollView } from 'react-native-gesture-handler';

instead of from

'react native'

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, you saved my life! Not sure why it wasn't included in react-native itself. I'm going to check what react-native-gesture-handler does.
Thanks! This works for me, but it'd nice to know why we have to use this as opposed to the one from React Native. Do you have any idea?
@ZeivRine can you explain why this works?
As of today, I can confirm that this is the only thing that worked for me. I spent several hours trying to make a horizontal ScrollView work on Android and nothing worked until I imported ScrollView from 'react-native-gesture-handler'
15

Use flexGrow : 1 inside your styles.scroll instead of flex:1

2 Comments

if it's oki to you to change the schema (swap the ScrollView with the view). use this : ``` export default class StoreComponent extends Component { render() { return ( <ScrollView contentContainerStyle={styles.scroll}> <View style={styles.container}> <StoreCarouselComponent /> <StoreDiscountComponent /> <StoreDetailsComponent /> </View> </ScrollView> ); } } ``` if this doesn't work , can you please add nestedScrollEnabled={true} props to your Scrollview ?
This doesn't really work for me. Could you take a look here please? stackoverflow.com/questions/63437251/…
4

I had a similar issue. The culprit turned out to be contentContainerStyle={{flex: 1}} on my ScrollView. Removing that (It turned out to be unnecessary, anyway.) fixed the problem on Android.

1 Comment

This doesn't really work for me. Could you take a look here please? stackoverflow.com/questions/63437251/…
4

use flex: 1 inside style={styles.container} and delete it from .scroll

1 Comment

This doesn't really work for me. Could you take a look here please? stackoverflow.com/questions/63437251/…
2

the styles on your scroll contentContainerStyle is uneccessary

try to remove : styles.scroll

and just give padding or margin on component if you to center it

if its row add props horizontal = true on ScrollView.

2 Comments

thanks, but without the style my content is aling to the left, also a need to scroll vertically no horizontally.
if you dont want to modify your child components margin/padding . another options is add this to your ScrollView contentContainerStyle={{width:'100%', alignItems:'center'}}
1

worked for me now

try to import from

import { ScrollView } from 'react-native-gesture-handler';

instead of from

'react native'

1 Comment

this is the only solution that worked for me. thanks.
0

I too had the similar structure as mentioned in question. I had 3 direct children View inside ScrollView and it wasn't scrolling. I tried all above solutions with flex, flexGrow etc. Nothing worked for me.

What worked for me is wrapping all 3 direct children to another View, so for ScrollView there's only one direct children.

// THIS DOES NOT SCROLL
<ScrollView>
  <View>// 1st direct children</View>
  <View>// 2nd direct children</View>
  <View>// 3rd direct children</View>
</ScrollView>


// THIS WILL SCROLL, As now ScrollView has only one direct children
<ScrollView>
  <View>
    <View>// 1st children</View>
    <View>// 2nd children</View>
    <View>// 3rd children</View>
  </View>
</ScrollView>

Comments

0

applying flexDirection over ScrollView can cause scrolling issues over android.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.