mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Allow tapping the avatar in the room member bottom sheet to view it fullscreen (#5989)
* Extract a shared helper for loading a media preview The four screens that show a fullscreen avatar each had their own copy of the same load-and-wrap logic. Move it to MediaPreviewItem.load, with the mime type as a parameter defaulting to JPEG, and leave each screen's loading indicator where it is. Signed-off-by: Daniel Anderson <daniel.anderson@toptal.com> * Only dismiss a QuickLook preview that is still presented UIKit forwards dismiss() up the presentation chain when the receiver has nothing presented, so dismissing the avatar view was dismissing the profile details sheet also. Signed-off-by: Daniel Anderson <daniel.anderson@toptal.com> * Allow tapping the avatar in the room member bottom sheet to view it fullscreen Signed-off-by: Daniel Anderson <daniel.anderson@toptal.com> --------- Signed-off-by: Daniel Anderson <daniel.anderson@toptal.com>
This commit is contained in:
@@ -83,6 +83,8 @@ private struct MediaPreviewViewController: UIViewControllerRepresentable {
|
||||
dismissalObserver = dismissalPublisher.sink { [weak self] _ in
|
||||
// Dispatching on main.async with weak self we avoid doing an extra dismiss if the view is presented on top of another modal
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
// Only dismiss a preview we still have up, UIKit forwards dismiss() to an ancestor otherwise.
|
||||
guard self?.presentedViewController != nil else { return }
|
||||
self?.dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
@@ -163,6 +165,16 @@ class MediaPreviewItem: NSObject, QLPreviewItem {
|
||||
self.file = file
|
||||
previewItemTitle = title
|
||||
}
|
||||
|
||||
/// Loads the media at the given URL, guessing at a JPEG for callers such as avatars that don't know the real mime type.
|
||||
static func load(from url: URL, title: String?, mimeType: String = "image/jpeg", using mediaProvider: MediaProviderProtocol) async -> MediaPreviewItem? {
|
||||
guard let mediaSource = try? MediaSourceProxy(url: url, mimeType: mimeType),
|
||||
case let .success(file) = await mediaProvider.loadFileFromSource(mediaSource) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return MediaPreviewItem(file: file, title: title)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
Reference in New Issue
Block a user