From 99b5a5b27537eca302c1a24a27cd5946971f9bea Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 13 Sep 2024 21:39:57 +0100 Subject: [PATCH] add modal that lets you pick photo or video --- .../filmCamera_stroke2_corner0_rounded.svg | 1 + src/components/icons/FilmCamera.tsx | 5 + src/view/com/composer/Composer.tsx | 6 +- .../com/composer/photos/OpenCameraBtn.tsx | 123 +++++++++++++++--- 4 files changed, 118 insertions(+), 17 deletions(-) create mode 100644 assets/icons/filmCamera_stroke2_corner0_rounded.svg create mode 100644 src/components/icons/FilmCamera.tsx diff --git a/assets/icons/filmCamera_stroke2_corner0_rounded.svg b/assets/icons/filmCamera_stroke2_corner0_rounded.svg new file mode 100644 index 0000000000..184e132040 --- /dev/null +++ b/assets/icons/filmCamera_stroke2_corner0_rounded.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/components/icons/FilmCamera.tsx b/src/components/icons/FilmCamera.tsx new file mode 100644 index 0000000000..7320ccc754 --- /dev/null +++ b/src/components/icons/FilmCamera.tsx @@ -0,0 +1,5 @@ +import {createSinglePathSVG} from './TEMPLATE' + +export const FilmCamera_Stroke2_Corner0_Rounded = createSinglePathSVG({ + path: 'M2 5a1 1 0 0 1 1-1h13a1 1 0 0 1 1 1v2.523l3.629-1.451A1 1 0 0 1 22 7v10a1 1 0 0 1-1.371.928L17 16.477V19a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V5Zm2 1v12h11v-3a1 1 0 0 1 1.371-.928L20 15.523V8.477l-3.629 1.451A1 1 0 0 1 15 9V6H4Zm5.5 4.5a1.5 1.5 0 1 0 0 3 1.5 1.5 0 0 0 0-3ZM6 12a3.5 3.5 0 1 1 7 0 3.5 3.5 0 0 1-7 0Z', +}) diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index dfdfb3ebdf..0f149e7dd3 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -807,7 +807,11 @@ export const ComposePost = observer(function ComposePost({ disabled={!canSelectImages} setError={setError} /> - + void } -export function OpenCameraBtn({gallery, disabled}: Props) { +export function OpenCameraBtn({gallery, disabled, selectVideo}: Props) { const {track} = useAnalytics() const {_} = useLingui() const {requestCameraAccessIfNeeded} = useCameraPermission() const [mediaPermissionRes, requestMediaPermission] = MediaLibrary.usePermissions({granularPermissions: ['photo']}) const t = useTheme() + const control = Dialog.useDialogControl() const onPressTakePicture = useCallback(async () => { track('Composer:CameraOpened') @@ -49,7 +62,7 @@ export function OpenCameraBtn({gallery, disabled}: Props) { await MediaLibrary.createAssetAsync(img.path) } gallery.add(img) - } catch (err: any) { + } catch (err) { // ignore logger.warn('Error using camera', {error: err}) } @@ -61,23 +74,101 @@ export function OpenCameraBtn({gallery, disabled}: Props) { requestMediaPermission, ]) + const onPressTakeVideo = useCallback(async () => { + try { + const response = await launchCameraAsync({ + mediaTypes: MediaTypeOptions.Videos, + quality: 0.8, + videoMaxDuration: VIDEO_MAX_DURATION, + exif: false, + presentationStyle: UIImagePickerPresentationStyle.PAGE_SHEET, + }) + + if (!response.canceled && response.assets[0]) { + selectVideo(response.assets[0]) + } + } catch (err) { + // ignore + logger.warn('Error using camera', {error: err}) + } + }, [selectVideo]) + const shouldShowCameraButton = isNative || isMobileWeb if (!shouldShowCameraButton) { return null } + if (isMobileWeb) { + return ( + + ) + } + return ( - + <> + + + + + + + + + + ) }