From b83407f1f45bc9a0def370ddb94b83beec3c3323 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Tue, 1 Aug 2023 14:35:10 +0300 Subject: [PATCH] Add video support Signed-off-by: Nikolaos Karaolidis --- android/app/src/main/AndroidManifest.xml | 30 +++++ src/components/memes/memeEditor.tsx | 116 +++++++++++------- src/components/memes/memeViewItem.tsx | 52 +++++--- .../memes/memesList/memesGridItem.tsx | 43 +++++-- .../memes/memesList/memesListItem.tsx | 23 +++- .../memes/memesList/memesMasonryItem.tsx | 53 +++++--- src/hooks/index.ts | 1 + src/hooks/useMemeDimensions.ts | 56 +++++++++ src/screens/memeView.tsx | 44 ++++--- src/screens/memes.tsx | 12 +- src/screens/tags.tsx | 10 +- src/types/dimensions.ts | 1 + src/utilities/filesystem.ts | 75 ++++++----- 13 files changed, 358 insertions(+), 158 deletions(-) create mode 100644 src/hooks/index.ts create mode 100644 src/hooks/useMemeDimensions.ts diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index cb64fb0..2df2526 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -28,6 +28,21 @@ + + + + + + + + + + + + + + + @@ -37,6 +52,21 @@ + + + + + + + + + + + + + + + diff --git a/src/components/memes/memeEditor.tsx b/src/components/memes/memeEditor.tsx index 5bbeca6..7e36d63 100644 --- a/src/components/memes/memeEditor.tsx +++ b/src/components/memes/memeEditor.tsx @@ -1,13 +1,20 @@ -import React, { useState } from 'react'; +import React, { useMemo } from 'react'; import { HelperText, Text, TextInput, useTheme } from 'react-native-paper'; import { Image, LayoutAnimation } from 'react-native'; import { useSafeAreaFrame } from 'react-native-safe-area-context'; import { LoadingView, MemeFail, MemeTagSelector } from '..'; -import { getFilenameFromUri, validateMemeTitle } from '../../utilities'; -import { Dimensions, StagingMeme } from '../../types'; +import { + getFilenameFromUri, + getMemeTypeFromMimeType, + validateMemeTitle, +} from '../../utilities'; +import { StagingMeme } from '../../types'; +import { useMemeDimensions } from '../../hooks'; +import { MEME_TYPE } from '../../database'; +import Video from 'react-native-video'; const memeEditorStyles = { - image: { + media: { marginBottom: 15, borderRadius: 5, }, @@ -26,6 +33,7 @@ const memeEditorStyles = { const MemeEditor = ({ uri, mimeType, + loading, setLoading, error, setError, @@ -44,7 +52,59 @@ const MemeEditor = ({ const { width } = useSafeAreaFrame(); const { colors } = useTheme(); - const [dimensions, setDimensions] = useState(); + const { dimensions } = useMemeDimensions( + uri, + mimeType, + useMemo( + () => () => { + setLoading(false); + LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut); + }, + [setLoading], + ), + useMemo(() => (errorIn: Error) => setError(errorIn), [setError]), + ); + + const mediaComponent = useMemo(() => { + if (!mimeType || !dimensions) return <>; + + const dimensionStyles = { + width: width * 0.92, + height: Math.max( + Math.min((width * 0.92) / dimensions.aspectRatio, 500), + 100, + ), + }; + + const memeType = getMemeTypeFromMimeType(mimeType); + if (!memeType) return <>; + + switch (memeType) { + case MEME_TYPE.IMAGE: + case MEME_TYPE.GIF: { + return ( + + ); + } + case MEME_TYPE.VIDEO: { + return ( +