From 2b8b524bd747ded38e2ebe3f477a40feb9972fd5 Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 7 Oct 2024 11:58:41 -0700 Subject: [PATCH 1/5] add dimensions to response on ios --- .../ShareViewController.swift | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/Share-with-Bluesky/ShareViewController.swift b/modules/Share-with-Bluesky/ShareViewController.swift index 2acbb6187b..79f081737f 100644 --- a/modules/Share-with-Bluesky/ShareViewController.swift +++ b/modules/Share-with-Bluesky/ShareViewController.swift @@ -1,4 +1,5 @@ import UIKit +import AVKit let IMAGE_EXTENSIONS: [String] = ["png", "jpg", "jpeg", "gif", "heic"] let MOVIE_EXTENSIONS: [String] = ["mov", "mp4", "m4v"] @@ -119,16 +120,11 @@ class ShareViewController: UIViewController { private func handleVideos(items: [NSItemProvider]) async { let firstItem = items.first - if let dataUri = try? await firstItem?.loadItem(forTypeIdentifier: "public.movie") as? URL { - let ext = String(dataUri.lastPathComponent.split(separator: ".").last ?? "mp4") - if let tempUrl = getTempUrl(ext: ext) { - let data = try? Data(contentsOf: dataUri) - try? data?.write(to: tempUrl) - - if let encoded = tempUrl.absoluteString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed), - let url = URL(string: "\(self.appScheme)://intent/compose?videoUri=\(encoded)") { - _ = self.openURL(url) - } + if let dataUrl = try? await firstItem?.loadItem(forTypeIdentifier: "public.movie") as? URL { + let ext = String(dataUrl.lastPathComponent.split(separator: ".").last ?? "mp4") + if let videoUriInfo = saveVideoWithInfo(dataUrl), + let url = URL(string: "\(self.appScheme)://intent/compose?videoUri=\(videoUriInfo)") { + _ = self.openURL(url) } } @@ -152,6 +148,20 @@ class ShareViewController: UIViewController { } catch {} return nil } + + private func saveVideoWithInfo(_ dataUrl: URL) -> String? { + let ext = String(dataUrl.lastPathComponent.split(separator: ".").last ?? "mp4") + guard let tempUrl = getTempUrl(ext: ext), + let track = AVURLAsset(url: dataUrl).tracks(withMediaType: AVMediaType.video).first else { + return nil + } + let size = track.naturalSize.applying(track.preferredTransform) + + let data = try? Data(contentsOf: dataUrl) + try? data?.write(to: tempUrl) + + return "\(tempUrl.absoluteString)|\(size.width)||\(size.height)" + } private func completeRequest() { self.extensionContext?.completeRequest(returningItems: nil) From cab67f59269a5e7dc0d8eaadd40d7620670a9c0d Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 7 Oct 2024 12:07:34 -0700 Subject: [PATCH 2/5] update passing the info to composer --- src/lib/hooks/useIntentHandler.ts | 3 ++- src/state/shell/composer/index.tsx | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/hooks/useIntentHandler.ts b/src/lib/hooks/useIntentHandler.ts index ce1d474d31..98ba4ec026 100644 --- a/src/lib/hooks/useIntentHandler.ts +++ b/src/lib/hooks/useIntentHandler.ts @@ -93,9 +93,10 @@ export function useComposeIntent() { // Whenever a video URI is present, we don't support adding images right now. if (videoUri) { + const [uri, width, height] = videoUri.split('|') openComposer({ text: text ?? undefined, - videoUri, + videoUri: {uri, width: Number(width), height: Number(height)}, }) return } diff --git a/src/state/shell/composer/index.tsx b/src/state/shell/composer/index.tsx index 1c3aa6a81d..770b0789ed 100644 --- a/src/state/shell/composer/index.tsx +++ b/src/state/shell/composer/index.tsx @@ -38,7 +38,7 @@ export interface ComposerOpts { openEmojiPicker?: (pos: DOMRect | undefined) => void text?: string imageUris?: {uri: string; width: number; height: number; altText?: string}[] - videoUri?: string + videoUri?: {uri: string; width: number; height: number} } type StateContext = ComposerOpts | undefined From 287e9867b2bb2076f12d74504eb18b015ce3f970 Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 7 Oct 2024 12:08:44 -0700 Subject: [PATCH 3/5] update asset --- src/view/com/composer/Composer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/com/composer/Composer.tsx b/src/view/com/composer/Composer.tsx index 94c02767ea..0189ca9a85 100644 --- a/src/view/com/composer/Composer.tsx +++ b/src/view/com/composer/Composer.tsx @@ -218,7 +218,7 @@ export const ComposePost = ({ // Whenever we receive an initial video uri, we should immediately run compression if necessary useEffect(() => { if (initVideoUri) { - selectVideo({uri: initVideoUri} as ImagePickerAsset) + selectVideo(initVideoUri) } }, [initVideoUri, selectVideo]) From a0f5b2c7da61140e6b19ae019934e3ec8ffc1eb6 Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 7 Oct 2024 12:49:26 -0700 Subject: [PATCH 4/5] add android --- .../ExpoReceiveAndroidIntentsModule.kt | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt b/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt index c88442057c..abae882b48 100644 --- a/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt +++ b/modules/expo-receive-android-intents/android/src/main/java/xyz/blueskyweb/app/exporeceiveandroidintents/ExpoReceiveAndroidIntentsModule.kt @@ -2,6 +2,7 @@ package xyz.blueskyweb.app.exporeceiveandroidintents import android.content.Intent import android.graphics.Bitmap +import android.media.MediaMetadataRetriever import android.net.Uri import android.os.Build import android.provider.MediaStore @@ -143,7 +144,10 @@ class ExpoReceiveAndroidIntentsModule : Module() { appContext.currentActivity?.contentResolver?.openInputStream(uri)?.use { it.copyTo(out) } - "bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}".toUri().let { + + val info = getVideoInfo(uri) ?: return + + "bluesky://intent/compose?videoUri=${URLEncoder.encode(file.path, "UTF-8")}|${info["width"]}|${info["height"]}".toUri().let { val newIntent = Intent(Intent.ACTION_VIEW, it) appContext.currentActivity?.startActivity(newIntent) } @@ -166,6 +170,24 @@ class ExpoReceiveAndroidIntentsModule : Module() { ) } + private fun getVideoInfo(uri: Uri): Map? { + val retriever = MediaMetadataRetriever() + retriever.setDataSource(appContext.currentActivity, uri) + + val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)?.toIntOrNull() + val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)?.toIntOrNull() + + if (width == null || height == null) { + return null + } + + return mapOf( + "width" to width, + "height" to height, + "path" to uri.path.toString(), + ) + } + private fun createFile(extension: String): File = File.createTempFile(extension, "temp.$extension", appContext.currentActivity?.cacheDir) // We will pas the width and height to the app here, since getting measurements From ee700eea6335a5c6c5b27b4f557048ab7905badb Mon Sep 17 00:00:00 2001 From: Hailey Date: Mon, 7 Oct 2024 15:26:58 -0700 Subject: [PATCH 5/5] run update extensions --- modules/Share-with-Bluesky/ShareViewController.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/Share-with-Bluesky/ShareViewController.swift b/modules/Share-with-Bluesky/ShareViewController.swift index 79f081737f..a7af2b19cd 100644 --- a/modules/Share-with-Bluesky/ShareViewController.swift +++ b/modules/Share-with-Bluesky/ShareViewController.swift @@ -151,16 +151,20 @@ class ShareViewController: UIViewController { private func saveVideoWithInfo(_ dataUrl: URL) -> String? { let ext = String(dataUrl.lastPathComponent.split(separator: ".").last ?? "mp4") - guard let tempUrl = getTempUrl(ext: ext), - let track = AVURLAsset(url: dataUrl).tracks(withMediaType: AVMediaType.video).first else { + guard let tempUrl = getTempUrl(ext: ext) else { return nil } - let size = track.naturalSize.applying(track.preferredTransform) let data = try? Data(contentsOf: dataUrl) try? data?.write(to: tempUrl) - return "\(tempUrl.absoluteString)|\(size.width)||\(size.height)" + guard let track = AVURLAsset(url: dataUrl).tracks(withMediaType: AVMediaType.video).first else { + _ = try? FileManager().removeItem(at: tempUrl) + return nil + } + + let size = track.naturalSize.applying(track.preferredTransform) + return "\(tempUrl.absoluteString)|\(size.width)|\(size.height)" } private func completeRequest() {