diff options
| author | Ivan Chen <ivan@tagg.id> | 2021-06-25 20:58:56 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-25 20:58:56 -0400 |
| commit | 5480267b285812c094246bb941c6deaf83f53ff5 (patch) | |
| tree | 17f2e23576c000bcc90d840d14b8abc3bb9bec24 /src/screens/profile | |
| parent | 981051448fee6197544383e535fea7a72827d41d (diff) | |
| parent | dcf45600b6e2be7820ed2d8c0f44603624f1e719 (diff) | |
Merge pull request #475 from IvanIFChen/tma948-video-playback
[TMA-948] Viewing Videos
Diffstat (limited to 'src/screens/profile')
| -rw-r--r-- | src/screens/profile/CaptionScreen.tsx | 8 | ||||
| -rw-r--r-- | src/screens/profile/IndividualMoment.tsx | 118 | ||||
| -rw-r--r-- | src/screens/profile/MomentCommentsScreen.tsx | 5 |
3 files changed, 48 insertions, 83 deletions
diff --git a/src/screens/profile/CaptionScreen.tsx b/src/screens/profile/CaptionScreen.tsx index d53570cb..364b81a3 100644 --- a/src/screens/profile/CaptionScreen.tsx +++ b/src/screens/profile/CaptionScreen.tsx @@ -13,7 +13,7 @@ import { TouchableWithoutFeedback, View, } from 'react-native'; -import {MentionInput} from 'react-native-controlled-mentions'; +import {MentionInputControlled} from '../../components'; import {Button, normalize} from 'react-native-elements'; import Video from 'react-native-video'; import {useDispatch, useSelector} from 'react-redux'; @@ -237,16 +237,16 @@ const CaptionScreen: React.FC<CaptionScreenProps> = ({route, navigation}) => { <Image style={styles.media} source={{uri: mediaUri}} - resizeMode={'cover'} + resizeMode={'contain'} /> )} - <MentionInput + <MentionInputControlled containerStyle={styles.text} placeholder="Write something....." placeholderTextColor="gray" value={caption} onChange={setCaption} - partTypes={mentionPartTypes('blue')} + partTypes={mentionPartTypes('blue', 'caption')} /> <TouchableOpacity onPress={() => diff --git a/src/screens/profile/IndividualMoment.tsx b/src/screens/profile/IndividualMoment.tsx index f8113aba..a322b1e9 100644 --- a/src/screens/profile/IndividualMoment.tsx +++ b/src/screens/profile/IndividualMoment.tsx @@ -1,28 +1,16 @@ -import {BlurView} from '@react-native-community/blur'; import {RouteProp} from '@react-navigation/native'; import {StackNavigationProp} from '@react-navigation/stack'; import React, {useEffect, useRef, useState} from 'react'; -import {FlatList, Keyboard, StyleSheet} from 'react-native'; +import {FlatList, Keyboard, ViewToken} from 'react-native'; import {useSelector} from 'react-redux'; -import {IndividualMomentTitleBar, MomentPost} from '../../components'; -import {AVATAR_DIM} from '../../constants'; +import {MomentPost, TabsGradient} from '../../components'; import {MainStackParams} from '../../routes'; import {RootState} from '../../store/rootreducer'; import {MomentPostType} from '../../types'; -import { - isIPhoneX, - normalize, - SCREEN_HEIGHT, - StatusBarHeight, -} from '../../utils'; - -/** - * Individual moment view opened when user clicks on a moment tile - */ type MomentContextType = { keyboardVisible: boolean; - scrollTo: (index: number) => void; + currentVisibleMomentId: string | undefined; }; export const MomentContext = React.createContext({} as MomentContextType); @@ -39,10 +27,7 @@ interface IndividualMomentProps { navigation: IndividualMomentNavigationProp; } -const IndividualMoment: React.FC<IndividualMomentProps> = ({ - route, - navigation, -}) => { +const IndividualMoment: React.FC<IndividualMomentProps> = ({route}) => { const { userXId, screenType, @@ -57,6 +42,18 @@ const IndividualMoment: React.FC<IndividualMomentProps> = ({ ); 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); @@ -69,70 +66,39 @@ const IndividualMoment: React.FC<IndividualMomentProps> = ({ }; }, []); - const scrollTo = (index: number) => { - // TODO: make this dynamic - const offset = isIPhoneX() ? -(AVATAR_DIM + 100) : -(AVATAR_DIM + 160); - scrollRef.current?.scrollToIndex({ - index: index, - viewOffset: offset, - }); - }; - return ( <MomentContext.Provider value={{ keyboardVisible, - scrollTo, + currentVisibleMomentId, }}> - <BlurView - blurType="light" - blurAmount={30} - reducedTransparencyFallbackColor="white" - style={styles.contentContainer}> - <IndividualMomentTitleBar - style={styles.header} - close={() => navigation.goBack()} - title={moment_category} - /> - <FlatList - ref={scrollRef} - data={momentData} - contentContainerStyle={styles.listContentContainer} - renderItem={({item, index}) => ( - <MomentPost - moment={item} - userXId={userXId} - screenType={screenType} - index={index} - /> - )} - keyExtractor={(item, _) => item.moment_id} - showsVerticalScrollIndicator={false} - initialScrollIndex={initialIndex} - onScrollToIndexFailed={() => { - // TODO: code below does not work, index resets to 0 - // const wait = new Promise((resolve) => setTimeout(resolve, 500)); - // wait.then(() => { - // console.log('scrolling to ', initialIndex); - // scrollRef.current?.scrollToIndex({index: initialIndex}); - // }); - }} - /> - </BlurView> + <FlatList + ref={scrollRef} + data={momentData} + renderItem={({item}) => ( + <MomentPost + key={item.moment_id} + moment={item} + userXId={userXId} + screenType={screenType} + /> + )} + keyExtractor={(item, _) => item.moment_id} + showsVerticalScrollIndicator={false} + initialScrollIndex={initialIndex} + onViewableItemsChanged={viewabilityConfigCallback.current} + onScrollToIndexFailed={(info) => { + setTimeout(() => { + scrollRef.current?.scrollToIndex({ + index: info.index, + }); + }, 500); + }} + pagingEnabled + /> + <TabsGradient /> </MomentContext.Provider> ); }; -const styles = StyleSheet.create({ - contentContainer: { - paddingTop: StatusBarHeight, - flex: 1, - }, - header: { - height: normalize(70), - }, - listContentContainer: { - paddingBottom: SCREEN_HEIGHT * 0.2, - }, -}); export default IndividualMoment; diff --git a/src/screens/profile/MomentCommentsScreen.tsx b/src/screens/profile/MomentCommentsScreen.tsx index 7dfe8ae9..402e5f44 100644 --- a/src/screens/profile/MomentCommentsScreen.tsx +++ b/src/screens/profile/MomentCommentsScreen.tsx @@ -48,9 +48,8 @@ const MomentCommentsScreen: React.FC<MomentCommentsScreenProps> = ({route}) => { React.useState(true); //Keeps track of the current comments object in focus so that the application knows which comment to post a reply to - const [commentTapped, setCommentTapped] = useState< - CommentType | CommentThreadType | undefined - >(); + const [commentTapped, setCommentTapped] = + useState<CommentType | CommentThreadType | undefined>(); useEffect(() => { navigation.setOptions({ |
