TypeScript
fix(mobile): gallery images shrink back into their thumbnail on close (#21481)
oliver0e3c79567b66
diff --git a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swiftindex 57fa2a7c643..e6977ee71cd 100644--- a/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift+++ b/apps/mobile/modules/t3-native-controls/ios/T3NativeControlsModule.swift@@ -52,11 +52,14 @@ public final class T3NativeControlsModule: Module {identifier: identifier, promise: promise)}.runOnQueue(.main)- AsyncFunction("presentFiles") { (urls: [URL], titles: [String], selectedIndex: Int, identifier: String, promise: Promise) in- guard !urls.isEmpty, urls.count == titles.count, urls.indices.contains(selectedIndex) else {+ AsyncFunction("presentFiles") { (urls: [URL], titles: [String], selectedIndex: Int, sourceIdentifiers: [String], identifier: String, promise: Promise) in+ guard !urls.isEmpty, urls.count == titles.count, urls.count == sourceIdentifiers.count,+ urls.indices.contains(selectedIndex)+ else {throw URLError(.badURL)}- let file = try self.makeFilePresentation(sourceIdentifier: "", identifier: identifier, promise: promise)+ let file = try self.makeFilePresentation(sourceIdentifiers: sourceIdentifiers, identifier: identifier,+ promise: promise)guard let presenter = self.appContext?.utilities?.currentViewController() else {file.dismiss()return@@ -241,13 +244,13 @@ public final class T3NativeControlsModule: Module {if videoPresentation?.identifier == identifier { videoPresentation?.dismiss() }}- private func makeFilePresentation(sourceIdentifier: String, identifier: String,+ private func makeFilePresentation(sourceIdentifiers: [String], identifier: String,promise: Promise) throws -> T3NativeFilePresentation {guard filePresentation == nil, videoPresentation == nil,appContext?.utilities?.currentViewController() != nilelse { throw URLError(.cannotLoadFromNetwork) }let file = T3NativeFilePresentation(identifier: identifier, sources: presentationSources,- sourceIdentifier: sourceIdentifier) { [weak self] error in+ sourceIdentifiers: sourceIdentifiers) { [weak self] error inself?.filePresentation = nilif let error { promise.reject(error) } else { promise.resolve(nil) }}@@ -257,7 +260,7 @@ public final class T3NativeControlsModule: Module {private func presentFile(url: URL, title: String, sourceIdentifier: String,identifier: String, promise: Promise) throws {- let file = try makeFilePresentation(sourceIdentifier: sourceIdentifier, identifier: identifier, promise: promise)+ let file = try makeFilePresentation(sourceIdentifiers: [sourceIdentifier], identifier: identifier, promise: promise)guard let presenter = appContext?.utilities?.currentViewController() else { file.dismiss(); return }file.present(url: url, title: title, from: presenter)}diff --git a/apps/mobile/modules/t3-native-controls/ios/T3NativeFilePresentation.swift b/apps/mobile/modules/t3-native-controls/ios/T3NativeFilePresentation.swiftindex 5c3e7f2bf6f..641a1f4b346 100644--- a/apps/mobile/modules/t3-native-controls/ios/T3NativeFilePresentation.swift+++ b/apps/mobile/modules/t3-native-controls/ios/T3NativeFilePresentation.swift@@ -24,16 +24,17 @@ final class T3NativeFilePresentation: NSObject, QLPreviewControllerDataSource,private var controller: UIViewController?private let completion: (Error?) -> Voidprivate weak var sources: T3PresentationSources?- private let sourceIdentifier: String+ private let sourceIdentifiers: [String]private var items: [FilePreviewItem] = []private var loading: Task<Void, Never>?private var dismissRequested = falseprivate var finished = false- init(identifier: String, sources: T3PresentationSources, sourceIdentifier: String, completion: @escaping (Error?) -> Void) {+ init(identifier: String, sources: T3PresentationSources, sourceIdentifiers: [String],+ completion: @escaping (Error?) -> Void) {self.identifier = identifierself.sources = sources- self.sourceIdentifier = sourceIdentifier+ self.sourceIdentifiers = sourceIdentifiersself.completion = completionsuper.init()}@@ -107,14 +108,21 @@ final class T3NativeFilePresentation: NSObject, QLPreviewControllerDataSource,items[index]}+ private func sourceView(for item: QLPreviewItem) -> UIView? {+ guard !UIAccessibility.isReduceMotionEnabled,+ let index = items.firstIndex(where: { $0 === item }),+ sourceIdentifiers.indices.contains(index)+ else { return nil }+ return sources?.view(for: sourceIdentifiers[index])+ }+func previewController(_ controller: QLPreviewController, transitionViewFor item: QLPreviewItem) -> UIView? {- guard !UIAccessibility.isReduceMotionEnabled else { return nil }- return sources?.view(for: sourceIdentifier)+ sourceView(for: item)}func previewController(_ controller: QLPreviewController, frameFor item: QLPreviewItem,inSourceView view: AutoreleasingUnsafeMutablePointer<UIView?>) -> CGRect {- guard !UIAccessibility.isReduceMotionEnabled, let source = sources?.view(for: sourceIdentifier) else { return .zero }+ guard let source = sourceView(for: item) else { return .zero }view.pointee = sourcereturn source.bounds}diff --git a/apps/mobile/src/components/FilePreview.ios.tsx b/apps/mobile/src/components/FilePreview.ios.tsxindex fa27733b77c..ed5c6e56ee8 100644--- a/apps/mobile/src/components/FilePreview.ios.tsx+++ b/apps/mobile/src/components/FilePreview.ios.tsx@@ -15,6 +15,7 @@ const NativeControls = requireNativeModule<{uris: readonly string[],names: readonly string[],selectedIndex: number,+ sourceIdentifiers: readonly string[],identifier: string,): Promise<void>;dismissFile(identifier: string): Promise<void>;@@ -44,6 +45,7 @@ function NativeFilePreview(props: {0,gallery.findIndex((item) => item.uri === uri),),+ gallery.map((item) => item.sourceIdentifier ?? ""),identifier,): NativeControls.presentFile(uri, name ?? "Preview", sourceIdentifier ?? "", identifier);