0

I have used a flatlist to list 4 videos getting fetched from an API, however I want them to scroll one at a time, hence added viewpager to render each video as a separate page, however on adding viewpager I do not seem to retrieve the videos on front-end, however they are appearing on my logs.

Code with viewpager:

<ViewPager scrollEnabled={true} orientation={"vertical"} >
        <FlatList
        data={this.state.data.product}
        scrollEventThrottle={1}
        onEndThreshold={0}
        renderItem={({ item }) => (
        <View style = {{alignContent: 'stretch'}} >
            <ScrollView scrollEventThrottle={1}>



      <ViewportAwareVideo
          repeat paused={this.state.videoPaused}
          source={{ uri: item.urlVid }}
          resizeMode = "cover"
          preTriggerRatio={PRE_TRIGGER_RATIO} 
          retainOnceInViewport={false}  
          style={{width: width, height:height}}
          innerRef={ref => this._videoRef = ref}
          onViewportEnter={() => this._videoRef.play()}
          onViewportLeave={() => this._videoRef.stop()} 
        />



    </ScrollView>

         <View
              style={{
                position: 'absolute',
                flexDirection: 'column',
                alignItems: 'flex-end',
                top: '50%',
                right: 10,
              }}>
              <TouchableOpacity
                 onPress= {() => this.onButtonPress(item)}
                style={{
                  alignItems: 'center',

                  borderRadius: 60,
                  padding: 10,
                }}>
                <Icon
                  name="heart"
                  size={30}
                  color={this.state.likedItemIds.includes(item._id) ? "red" : "white"}

                />
              </TouchableOpacity>


              <TouchableOpacity
                onPress={()=>this.shareProduct(item)}
                style={{
                  alignItems: 'center',

                  borderRadius: 60,
                  padding: 10,
                }}>
                <Icon name="share" size={30} color="white" />
              </TouchableOpacity>
              <Text style={{ right: 5, color: 'white' }} />
              <TouchableOpacity
                style={{
                  alignItems: 'center',

                  borderRadius: 60,
                  padding: 10,
                }}>
                <Icon name="whatsapp" size={30} color="white" />
              </TouchableOpacity>
              <Text style={{ right: 5, color: 'white' }} />
              <TouchableOpacity
              onPress= {() => this.download(item)}
                style={{
                  alignItems: 'center',
                  borderRadius: 60,
                  padding: 10,
                }}>
                <Icon name="download" size={30} color="white" />
              </TouchableOpacity>
              <Text style={{ right: 5, color: 'white' }} />
            </View>
            <View
              style={{
                position: 'absolute',
                flexDirection: 'column',

                top: '90%',
                left: 10,
              }}>
                <TouchableOpacity onPress={() => this.props.navigation.navigate('Product', {_id: item._id})}>
                <View
                style={{
                  flexDirection: 'row',
                }}>
                <Text
                  style={{ fontWeight: 'bold', fontSize: 20, color: 'white' }}>
                  {item.title} - {item.price}
                </Text>



              </View>
                </TouchableOpacity>


            </View>

        </View> 


        )}

        keyExtractor={ item => item._id}
      />
   </ViewPager>

Please help me, and let me know why is it so?

TRINA CHAUDHURI
  • 627
  • 1
  • 11
  • 42
  • Are you sure you need to use ScrollView for Video's container? I guess you should not use scrollview, since ViewPager and Flatlist has its own VirtualizedList. Also the problem could be the flatlist. for the same reason. – Ugur Eren Feb 04 '20 at 07:47
  • even if I dont use scrollView, I have the same issue – TRINA CHAUDHURI Feb 04 '20 at 07:56

0 Answers0