Image load first then video when click
This commit is contained in:
@@ -69,6 +69,9 @@ let Feed = ({ navigation, route }) => {
|
|||||||
onRefresh={() => {
|
onRefresh={() => {
|
||||||
API.getPosts().then(setPosts);
|
API.getPosts().then(setPosts);
|
||||||
}}
|
}}
|
||||||
|
initialNumToRender={3}
|
||||||
|
maxToRenderPerBatch={3}
|
||||||
|
removeClippedSubviews={true}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
<StatusBar style="auto" />
|
<StatusBar style="auto" />
|
||||||
|
|||||||
+3
-1
@@ -72,7 +72,9 @@ let Profile = ({ navigation, route }) => {
|
|||||||
keyExtractor={item => item._id || item.createdAt}
|
keyExtractor={item => item._id || item.createdAt}
|
||||||
ListHeaderComponent={header}
|
ListHeaderComponent={header}
|
||||||
refreshing={Posts.length === 0}
|
refreshing={Posts.length === 0}
|
||||||
initialNumToRender={2}
|
initialNumToRender={3}
|
||||||
|
maxToRenderPerBatch={3}
|
||||||
|
removeClippedSubviews={true}
|
||||||
onRefresh={() => {
|
onRefresh={() => {
|
||||||
API.getPosts(route.params.profileid).then(setPosts);
|
API.getPosts(route.params.profileid).then(setPosts);
|
||||||
}}
|
}}
|
||||||
|
|||||||
+17
-5
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { Text, View, ScrollView, Image, StyleSheet } from 'react-native';
|
import { Text, View, TouchableHighlight, Image, StyleSheet } 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';
|
||||||
@@ -41,17 +41,25 @@ let Media = (props) => {
|
|||||||
const imageStyle = imagesTag.length == 1 ? styles.image : styles.multipleImage;
|
const imageStyle = imagesTag.length == 1 ? styles.image : styles.multipleImage;
|
||||||
const videosId = videoIdF(props.content);
|
const videosId = videoIdF(props.content);
|
||||||
const iframeSrc = iframeTagF(props.content) || [];
|
const iframeSrc = iframeTagF(props.content) || [];
|
||||||
let [videosFiles, setVideosFiles] = useState([]);
|
const [videosFiles, setVideosFiles] = useState([]);
|
||||||
let [poster, setPoster] = useState('');
|
const [poster, setPoster] = useState('');
|
||||||
|
const [loaded, setLoaded] = useState(false);
|
||||||
useEffect(async () => {
|
useEffect(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){
|
if(videoObj && videoObj.files){
|
||||||
setVideosFiles(videoObj.files);
|
setVideosFiles(videoObj.files);
|
||||||
setPoster(videoObj.pictures.sizes[videoObj.pictures.sizes.length - 1].link);
|
setPoster(videoObj.pictures.sizes[4].link);
|
||||||
}
|
}
|
||||||
}, [props.content])
|
}, [props.content])
|
||||||
const video = videosFiles.length ? <VideoPlayer videosFiles={videosFiles} poster={poster} videoId={videosId[1]} /> :
|
const video = videosFiles.length ? (
|
||||||
|
loaded ? <VideoPlayer videosFiles={videosFiles} poster={poster} videoId={videosId[1]} /> :
|
||||||
|
(
|
||||||
|
<TouchableHighlight onPress={() => setLoaded(true)}>
|
||||||
|
<Image source={poster ? {uri: poster} : {}} key={poster} style={styles.poster} />
|
||||||
|
</TouchableHighlight>
|
||||||
|
)
|
||||||
|
) :
|
||||||
(videosId.length ? <VimeoPlayer videoId={videosId[1]} /> : <></>);
|
(videosId.length ? <VimeoPlayer videoId={videosId[1]} /> : <></>);
|
||||||
const iframe = iframeSrc.length ?
|
const iframe = iframeSrc.length ?
|
||||||
<WebView
|
<WebView
|
||||||
@@ -83,6 +91,10 @@ const styles = StyleSheet.create({
|
|||||||
width: "100%",
|
width: "100%",
|
||||||
aspectRatio: 1,
|
aspectRatio: 1,
|
||||||
},
|
},
|
||||||
|
poster: {
|
||||||
|
width: "100%",
|
||||||
|
aspectRatio: 9/6,
|
||||||
|
},
|
||||||
multipleImage: {
|
multipleImage: {
|
||||||
width: "49%",
|
width: "49%",
|
||||||
aspectRatio: 1,
|
aspectRatio: 1,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const VideoPlayer = ({ videosFiles, videoId, poster }) => {
|
|||||||
|
|
||||||
const onLoad = ()=>{
|
const onLoad = ()=>{
|
||||||
if(!viewer.data[videoId]) return 0;
|
if(!viewer.data[videoId]) return 0;
|
||||||
|
console.log(videoId + " loaded")
|
||||||
video.current.setPositionAsync(viewer.data[videoId].time*1000);
|
video.current.setPositionAsync(viewer.data[videoId].time*1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -25,16 +26,11 @@ const VideoPlayer = ({ videosFiles, videoId, poster }) => {
|
|||||||
ref={video}
|
ref={video}
|
||||||
style={styles.video}
|
style={styles.video}
|
||||||
source={{
|
source={{
|
||||||
uri: chosenVideo[0].link,
|
uri: chosenVideo[chosenVideo.length-1].link,
|
||||||
}}
|
}}
|
||||||
usePoster={true}
|
|
||||||
posterSource={poster ? {
|
|
||||||
uri: poster
|
|
||||||
} : ''}
|
|
||||||
useNativeControls
|
useNativeControls
|
||||||
|
shouldPlay={true}
|
||||||
resizeMode="contain"
|
resizeMode="contain"
|
||||||
isLooping
|
|
||||||
shouldPlay={false}
|
|
||||||
onPlaybackStatusUpdate={status => setStatus(() => status)}
|
onPlaybackStatusUpdate={status => setStatus(() => status)}
|
||||||
onLoad={onLoad}
|
onLoad={onLoad}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user