Flatlist for multiple images
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Text, View, TouchableHighlight, Image, StyleSheet } from 'react-native';
|
import { Text, View, TouchableHighlight, Image, StyleSheet, FlatList } from 'react-native';
|
||||||
import API from './../API.js';
|
import API from './../API.js';
|
||||||
import VideoPlayer from './VideoPlayer.js';
|
import VideoPlayer from './VideoPlayer.js';
|
||||||
import VimeoPlayer from './VimeoPlayer.js';
|
import VimeoPlayer from './VimeoPlayer.js';
|
||||||
@@ -49,13 +49,13 @@ let Media = (props) => {
|
|||||||
let getData = async () => {
|
let getData = async () => {
|
||||||
if (!videosId[1]) return 0;
|
if (!videosId[1]) return 0;
|
||||||
let videoObj = await API.getVideo(videosId[1]);
|
let videoObj = await API.getVideo(videosId[1]);
|
||||||
if(videoObj && videoObj.files && subscribed){
|
if (videoObj && videoObj.files && subscribed) {
|
||||||
setVideosFiles(videoObj.files);
|
setVideosFiles(videoObj.files);
|
||||||
setPoster(videoObj.pictures.sizes[4].link);
|
setPoster(videoObj.pictures.sizes[4].link);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
getData();
|
getData();
|
||||||
return ()=>{
|
return () => {
|
||||||
subscribed = false;
|
subscribed = false;
|
||||||
};
|
};
|
||||||
}, [props.content])
|
}, [props.content])
|
||||||
@@ -63,7 +63,7 @@ let Media = (props) => {
|
|||||||
loaded ? <VideoPlayer videosFiles={videosFiles} poster={poster} videoId={videosId[1]} /> :
|
loaded ? <VideoPlayer videosFiles={videosFiles} poster={poster} videoId={videosId[1]} /> :
|
||||||
(
|
(
|
||||||
<TouchableHighlight onPress={() => setLoaded(true)}>
|
<TouchableHighlight onPress={() => setLoaded(true)}>
|
||||||
<Image source={poster ? {uri: poster} : {}} key={poster} style={styles.poster} />
|
<Image source={poster ? { uri: poster } : {}} key={poster} style={styles.poster} />
|
||||||
</TouchableHighlight>
|
</TouchableHighlight>
|
||||||
)
|
)
|
||||||
) :
|
) :
|
||||||
@@ -73,8 +73,20 @@ let Media = (props) => {
|
|||||||
style={styles.iframe}
|
style={styles.iframe}
|
||||||
source={{ uri: iframeSrc[1] }}
|
source={{ uri: iframeSrc[1] }}
|
||||||
/> : <></>;
|
/> : <></>;
|
||||||
|
const renderImages = (({ item }) => {
|
||||||
|
return (<Image source={{ uri: item[1] }} style={styles.flatlistImages} />);
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
|
{
|
||||||
|
(imagesTag.length > 2) ?
|
||||||
|
<FlatList
|
||||||
|
horizontal={true}
|
||||||
|
data={imagesTag}
|
||||||
|
renderItem={renderImages}
|
||||||
|
keyExtractor={item => item[1]}
|
||||||
|
initialNumToRender={2}
|
||||||
|
/> :
|
||||||
<View style={{ flexDirection: "row" }}>
|
<View style={{ flexDirection: "row" }}>
|
||||||
{
|
{
|
||||||
imagesTag.map((image, i) => {
|
imagesTag.map((image, i) => {
|
||||||
@@ -85,6 +97,7 @@ let Media = (props) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
|
}
|
||||||
{video}
|
{video}
|
||||||
{iframe}
|
{iframe}
|
||||||
</View>
|
</View>
|
||||||
@@ -100,14 +113,19 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
poster: {
|
poster: {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
aspectRatio: 9/6,
|
aspectRatio: 9 / 6,
|
||||||
},
|
},
|
||||||
multipleImage: {
|
multipleImage: {
|
||||||
width: "49%",
|
width: "49%",
|
||||||
aspectRatio: 1,
|
aspectRatio: 1,
|
||||||
margin: 2,
|
margin: 2,
|
||||||
},
|
},
|
||||||
iframe:{
|
flatlistImages: {
|
||||||
|
width: 300,
|
||||||
|
aspectRatio: 1,
|
||||||
|
margin: 2,
|
||||||
|
},
|
||||||
|
iframe: {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
minHeight: 300,
|
minHeight: 300,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user