Rahul Mishra
Rahul Mishra

Reputation: 4573

Image background in scroll view not working React Native

I am new in react native and I have to design a screen and when list going longer I realised my scroll view is not working here is below my code please share suggestion...Thanks!

<View style={{flex:1}}>
    <ActionBar
      containerStyle={{height:60,alignItems: 'center'}}
      backgroundColor={'#fff'}
      title={'Select Categories'}
      titleStyle={styles.pageTitle}
      onLeftPress={() => goBack()}
      leftIconContainerStyle={{marginTop:22}}
      leftIconName={'back'}
      leftIconImageStyle={{backgroundColor:'#333',height:18,width:18}}
    />
    <Image source={require('../images/bg-login.jpg')}
     style={{position:'absolute',left:0,right:0,top:0,bottom:0}} />
     <ScrollView style={{backgroundColor:'#00000000',position:'absolute',left:0,right:0,top:0,bottom:0}} >
        {views}
    </ScrollView>
    <View style={styles.footerSec}>
        <TouchableOpacity style={styles.nextBtn}
          onPress={()=> {this.props.navigation.navigate('Tutorials',{tutId:this.state.selectedCats})}}>
          <Text style={[styles.btnText, styles.priceText]}>Next</Text>
        </TouchableOpacity>
    </View>
  </View>

Here is my list code:

<TouchableOpacity key={itemData[j]._id}
                onPress = {() => {
                  activeItem ? this.removeCat(itemData[j]._id) : this.insertCat(itemData[j]._id)
                }}>

                    <View style={{position:'relative'}}>
                      <LinearGradient colors={activeItem ? ['#cb5fb1', '#f874d8', '#f98bde'] :['#ffb6cf','#ffb6cf','#ffb6cf'] } style={{
                        position: 'absolute',
                        alignItems: 'center',
                        justifyContent:'center',
                        backgroundColor: '#f673d7',
                        width:  armSize,
                        height: armSize,
                        borderRadius: (armSize) / 2,
                        top: topp,
                        left: leftp,
                      }}>
                      <Text style={{
                            color: '#fff',
                            alignSelf:'center',
                            fontSize: RandomNumber,
                            fontWeight: '600',
                            }}>
                        {itemData[j].name}
                      </Text>
                      </LinearGradient>
                    </View>


                </TouchableOpacity>

I designed below screen but the scroll view bounce and come up on same position...I think this is because of child position style but it's required for the circle in row. I can't scroll for below circles that's the issue.

enter image description here

Upvotes: 0

Views: 6312

Answers (2)

Rahul Mishra
Rahul Mishra

Reputation: 4573

For the scroll view issues I used below code and it's working fine everywhere

<ScrollView contentContainerStyle={{ paddingBottom: 120 }}>
---code---

</ScrollView>

Upvotes: 0

Luka Dumančić
Luka Dumančić

Reputation: 126

You could use normal Image to put a background image using position='absolute' and setting background color opacity of ScrollView to #00000000 which means that will be transparent

Example

<Image
 source={require('../images/bg-login.jpg')}
 style={{position:'absolute',
 left:0, 
 right:0, 
 top:0,
 bottom:0}} />
 <ScrollView 
  style={{backgroundColor:'#00000000',
  position:'absolute',
  left:0,
  right:0,
  top:0,
  bottom:0}} >
    <View>
        <Text>Some content</Text>
    </View>
</ScrollView>

Upvotes: 2

Related Questions