From 63bef47bffd2893f3013a02f71383c9c0a27881f Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 24 Jun 2021 18:20:15 -0400 Subject: Fix moment comment count, Add video support --- src/components/moments/MomentPost.tsx | 47 +++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'src/components/moments/MomentPost.tsx') diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index 6eccf5ab..f030c41e 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -12,6 +12,7 @@ import { View, } from 'react-native'; import Animated, {EasingNode} from 'react-native-reanimated'; +import Video from 'react-native-video'; import {useDispatch, useSelector, useStore} from 'react-redux'; import {headerBarOptions} from '../../routes'; import {MomentContext} from '../../screens/profile/IndividualMoment'; @@ -72,6 +73,12 @@ const MomentPost: React.FC = ({ const imageRef = useRef(null); const {keyboardVisible} = useContext(MomentContext); + const isVideo = !( + moment.moment_url.endsWith('jpg') || + moment.moment_url.endsWith('JPG') || + moment.moment_url.endsWith('PNG') || + moment.moment_url.endsWith('png') + ); /* * Load tags on initial render to pass tags data to moment header and content @@ -178,17 +185,26 @@ const MomentPost: React.FC = ({ - + {isVideo ? ( + + + ) : ( + + )} {visible && ( @@ -233,7 +249,11 @@ const MomentPost: React.FC = ({ /> )} - + {!hideText && ( @@ -281,8 +301,9 @@ const MomentPost: React.FC = ({ }; const styles = StyleSheet.create({ - image: { + media: { zIndex: 0, + flex: 1, }, imageContainer: { height: SCREEN_HEIGHT, -- cgit v1.2.3-70-g09d2 From a6bc1f1a06a08bd842ba0b3bd00a88cea9bd9971 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Thu, 24 Jun 2021 18:50:00 -0400 Subject: Fix video layout while viewing --- src/components/moments/MomentPost.tsx | 36 ++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/components/moments/MomentPost.tsx') diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index f030c41e..770cdcee 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -133,13 +133,15 @@ const MomentPost: React.FC = ({ * determine if image must be displayed in full screen or not */ useEffect(() => { - Image.getSize( - moment.moment_url, - (w, h) => { - setAspectRatio(w / h); - }, - (err) => console.log(err), - ); + if (!isVideo) { + Image.getSize( + moment.moment_url, + (w, h) => { + setAspectRatio(w / h); + }, + (err) => console.log(err), + ); + } }, []); /* @@ -186,15 +188,31 @@ const MomentPost: React.FC = ({ {isVideo ? ( - + ) : ( -- cgit v1.2.3-70-g09d2 From 4bab63b7b0c24043749e78cbb4d639e8a4047bad Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 25 Jun 2021 16:40:35 -0400 Subject: Add logic to pause video when not visible --- src/components/moments/MomentPost.tsx | 3 ++- src/screens/profile/IndividualMoment.tsx | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src/components/moments/MomentPost.tsx') diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index 770cdcee..e6bb5405 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -72,7 +72,7 @@ const MomentPost: React.FC = ({ const [momentTagId, setMomentTagId] = useState(''); const imageRef = useRef(null); - const {keyboardVisible} = useContext(MomentContext); + const {keyboardVisible, currentVisibleMomentId} = useContext(MomentContext); const isVideo = !( moment.moment_url.endsWith('jpg') || moment.moment_url.endsWith('JPG') || @@ -213,6 +213,7 @@ const MomentPost: React.FC = ({ const {width, height} = response.naturalSize; setAspectRatio(width / height); }} + paused={moment.moment_id !== currentVisibleMomentId} /> ) : ( diff --git a/src/screens/profile/IndividualMoment.tsx b/src/screens/profile/IndividualMoment.tsx index ca31ad5b..7944c336 100644 --- a/src/screens/profile/IndividualMoment.tsx +++ b/src/screens/profile/IndividualMoment.tsx @@ -1,7 +1,7 @@ import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import React, {useEffect, useRef, useState} from 'react'; -import {FlatList, Keyboard} from 'react-native'; +import {FlatList, Keyboard, ViewToken} from 'react-native'; import {useSelector} from 'react-redux'; import {MomentPost, TabsGradient} from '../../components'; import {AVATAR_DIM} from '../../constants'; @@ -17,6 +17,7 @@ import {isIPhoneX} from '../../utils'; type MomentContextType = { keyboardVisible: boolean; scrollTo: (index: number) => void; + currentVisibleMomentId: string | undefined; }; export const MomentContext = React.createContext({} as MomentContextType); @@ -48,6 +49,18 @@ const IndividualMoment: React.FC = ({route}) => { ); const initialIndex = momentData.findIndex((m) => m.moment_id === moment_id); const [keyboardVisible, setKeyboardVisible] = useState(false); + const [currentVisibleMomentId, setCurrentVisibleMomentId] = useState< + string | undefined + >(); + // https://stackoverflow.com/a/57502343 + const viewabilityConfigCallback = useRef( + (info: {viewableItems: ViewToken[]; changed: ViewToken[]}) => { + const index = info.viewableItems[0].index; + if (index !== null) { + setCurrentVisibleMomentId(momentData[index].moment_id); + } + }, + ); useEffect(() => { const showKeyboard = () => setKeyboardVisible(true); @@ -74,6 +87,7 @@ const IndividualMoment: React.FC = ({route}) => { value={{ keyboardVisible, scrollTo, + currentVisibleMomentId, }}> = ({route}) => { keyExtractor={(item, _) => item.moment_id} showsVerticalScrollIndicator={false} initialScrollIndex={initialIndex} + onViewableItemsChanged={viewabilityConfigCallback.current} onScrollToIndexFailed={(info) => { setTimeout(() => { scrollRef.current?.scrollToIndex({ -- cgit v1.2.3-70-g09d2 From acc7081036177e036bd7f43c7975939d33e91f2c Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 25 Jun 2021 17:05:14 -0400 Subject: Cleanup ref types --- src/components/common/MomentTags.tsx | 14 +++++--------- src/components/moments/MomentPost.tsx | 12 +++++++++++- src/components/taggs/TaggDraggable.tsx | 4 ++-- 3 files changed, 18 insertions(+), 12 deletions(-) (limited to 'src/components/moments/MomentPost.tsx') diff --git a/src/components/common/MomentTags.tsx b/src/components/common/MomentTags.tsx index 4afacddb..d8a70353 100644 --- a/src/components/common/MomentTags.tsx +++ b/src/components/common/MomentTags.tsx @@ -1,4 +1,5 @@ -import React, {createRef, MutableRefObject, useEffect, useState} from 'react'; +import React, {createRef, RefObject, useEffect, useState} from 'react'; +import {Image, View} from 'react-native'; import {MomentTagType, ProfilePreviewType} from '../../types'; import TaggDraggable from '../taggs/TaggDraggable'; import Draggable from './Draggable'; @@ -7,7 +8,7 @@ interface MomentTagsProps { editing: boolean; tags: MomentTagType[]; setTags: (tag: MomentTagType[]) => void; - imageRef: MutableRefObject; + imageRef: RefObject; deleteFromList?: (user: ProfilePreviewType) => void; } @@ -21,14 +22,9 @@ const MomentTags: React.FC = ({ const [offset, setOffset] = useState([0, 0]); const [imageDimensions, setImageDimensions] = useState([0, 0]); const [maxZIndex, setMaxZIndex] = useState(1); - const [draggableRefs, setDraggableRefs] = useState< - React.MutableRefObject[] - >([]); + const [draggableRefs, setDraggableRefs] = useState[]>([]); - const updateTagPosition = ( - ref: React.MutableRefObject, - userId: string, - ) => { + const updateTagPosition = (ref: RefObject, userId: string) => { if (ref !== null && ref.current !== null) { ref.current.measure( ( diff --git a/src/components/moments/MomentPost.tsx b/src/components/moments/MomentPost.tsx index e6bb5405..7d0752d5 100644 --- a/src/components/moments/MomentPost.tsx +++ b/src/components/moments/MomentPost.tsx @@ -1,5 +1,13 @@ import {useNavigation} from '@react-navigation/native'; -import React, {useContext, useEffect, useRef, useState} from 'react'; +import React, { + createRef, + LegacyRef, + MutableRefObject, + useContext, + useEffect, + useRef, + useState, +} from 'react'; import { Image, KeyboardAvoidingView, @@ -72,6 +80,7 @@ const MomentPost: React.FC = ({ const [momentTagId, setMomentTagId] = useState(''); const imageRef = useRef(null); + const videoRef = useRef