fix an issue where media gallery detail view was not displayed properly

pull/874/head
Ryan ZHAO 1 year ago
parent edb623d49b
commit 96c6965f44

@ -535,7 +535,8 @@ public class MediaGalleryViewModel {
threadVariant: SessionThread.Variant,
interactionId: Int64,
selectedAttachmentId: String,
options: [MediaGalleryOption]
options: [MediaGalleryOption],
useTransitioningDelegate: Bool = true
) -> UIViewController? {
// Load the data for the album immediately (needed before pushing to the screen so
// transitions work nicely)
@ -563,52 +564,14 @@ public class MediaGalleryViewModel {
let navController: MediaGalleryNavigationController = MediaGalleryNavigationController()
navController.viewControllers = [pageViewController]
navController.modalPresentationStyle = .fullScreen
navController.transitioningDelegate = pageViewController
return navController
}
@ViewBuilder
public static func createDetailViewSwiftUI(
for threadId: String,
threadVariant: SessionThread.Variant,
interactionId: Int64,
selectedAttachmentId: String,
options: [MediaGalleryOption]
) -> some View {
// Load the data for the album immediately (needed before pushing to the screen so
// transitions work nicely)
let viewModel: MediaGalleryViewModel = MediaGalleryViewModel(
threadId: threadId,
threadVariant: threadVariant,
isPagedData: false,
mediaType: .media
)
let _ = viewModel.loadAndCacheAlbumData(for: interactionId, in: threadId)
let _ = viewModel.replaceAlbumObservation(toObservationFor: interactionId)
if
!viewModel.albumData.isEmpty,
let initialItem: Item = viewModel.albumData[interactionId]?.first(where: { item -> Bool in
item.attachment.id == selectedAttachmentId
})
{
let pageViewController: MediaPageViewController = MediaPageViewController(
viewModel: viewModel,
initialItem: initialItem,
options: options
)
let navController = MediaGalleryNavigationController_SwiftUI(
viewControllers: [pageViewController],
transitioningDelegate: pageViewController
)
navController
}
else {
EmptyView()
if useTransitioningDelegate {
navController.transitioningDelegate = pageViewController
}
return navController
}
public static func createMediaTileViewController(
threadId: String,
threadVariant: SessionThread.Variant,

@ -7,10 +7,9 @@ import SessionUtilitiesKit
import SessionMessagingKit
struct MessageInfoView: View {
@Environment(\.viewController) private var viewControllerHolder: UIViewController?
@EnvironmentObject var host: HostWrapper
@State var index = 1
@State var showingAttachmentFullScreen = false
static private let cornerRadius: CGFloat = 17
@ -20,8 +19,6 @@ struct MessageInfoView: View {
return [.failed, .failedToSync].contains(messageViewModel.state)
}
var dismiss: (() -> Void)?
var body: some View {
NavigationView {
ZStack (alignment: .topLeading) {
@ -120,15 +117,7 @@ struct MessageInfoView: View {
}
Button {
self.viewControllerHolder?.present(style: .fullScreen) {
MediaGalleryViewModel.createDetailViewSwiftUI(
for: messageViewModel.threadId,
threadVariant: messageViewModel.threadVariant,
interactionId: messageViewModel.id,
selectedAttachmentId: attachment.id,
options: [ .sliderEnabled ]
)
}
self.showMediaFullScreen(attachment: attachment)
} label: {
ZStack {
Circle()
@ -324,7 +313,7 @@ struct MessageInfoView: View {
Button(
action: {
actions[index].work()
dismiss?()
dismiss()
},
label: {
HStack(spacing: Values.largeSpacing) {
@ -366,6 +355,23 @@ struct MessageInfoView: View {
}
}
}
private func showMediaFullScreen(attachment: Attachment) {
if let mediaGalleryView = MediaGalleryViewModel.createDetailViewController(
for: messageViewModel.threadId,
threadVariant: messageViewModel.threadVariant,
interactionId: messageViewModel.id,
selectedAttachmentId: attachment.id,
options: [ .sliderEnabled ],
useTransitioningDelegate: false
) {
self.host.controller?.present(mediaGalleryView, animated: true)
}
}
func dismiss() {
self.host.controller?.navigationController?.popViewController(animated: true)
}
}
struct MessageBubble: View {
@ -519,7 +525,6 @@ final class MessageInfoViewController: SessionHostingViewController<MessageInfoV
)
super.init(rootView: messageInfoView)
rootView.dismiss = dismiss
}
@MainActor required dynamic init?(coder aDecoder: NSCoder) {
@ -532,10 +537,6 @@ final class MessageInfoViewController: SessionHostingViewController<MessageInfoV
let customTitleFontSize = Values.largeFontSize
setNavBarTitle("message_info_title".localized(), customFontSize: customTitleFontSize)
}
func dismiss() {
self.navigationController?.popViewController(animated: true)
}
}
struct MessageInfoView_Previews: PreviewProvider {

@ -3,7 +3,11 @@
import SwiftUI
import SessionUIKit
public class SessionHostingViewController<Content>: UIHostingController<Content> where Content : View {
public class HostWrapper: ObservableObject {
public weak var controller: UIViewController?
}
public class SessionHostingViewController<Content>: UIHostingController<ModifiedContent<Content,SwiftUI._EnvironmentKeyWritingModifier<HostWrapper?>>> where Content : View {
public override var preferredStatusBarStyle: UIStatusBarStyle {
return ThemeManager.currentTheme.statusBarStyle
}
@ -14,7 +18,7 @@ public class SessionHostingViewController<Content>: UIHostingController<Content>
result.themeTextColor = .textPrimary
result.textAlignment = .center
result.alpha = 1
return result
}()
@ -24,17 +28,28 @@ public class SessionHostingViewController<Content>: UIHostingController<Content>
result.themeTextColor = .textPrimary
result.textAlignment = .center
result.alpha = 0
return result
}()
public init(rootView:Content) {
let container = HostWrapper()
let modified = rootView.environmentObject(container) as! ModifiedContent<Content, _EnvironmentKeyWritingModifier<HostWrapper?>>
super.init(rootView: modified)
container.controller = self
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public override func viewDidLoad() {
super.viewDidLoad()
navigationItem.backButtonTitle = ""
view.themeBackgroundColor = .backgroundPrimary
ThemeManager.applyNavigationStylingIfNeeded(to: self)
setNeedsStatusBarAppearanceUpdate()
}
@ -42,18 +57,41 @@ public class SessionHostingViewController<Content>: UIHostingController<Content>
let container = UIView()
navBarTitleLabel.text = title
crossfadeLabel.text = title
if let customFontSize = customFontSize {
navBarTitleLabel.font = .boldSystemFont(ofSize: customFontSize)
crossfadeLabel.font = .boldSystemFont(ofSize: customFontSize)
}
container.addSubview(navBarTitleLabel)
container.addSubview(crossfadeLabel)
navBarTitleLabel.pin(to: container)
crossfadeLabel.pin(to: container)
navigationItem.titleView = container
}
internal func setUpNavBarSessionHeading() {
let headingImageView = UIImageView(
image: UIImage(named: "SessionHeading")?
.withRenderingMode(.alwaysTemplate)
)
headingImageView.themeTintColor = .textPrimary
headingImageView.contentMode = .scaleAspectFit
headingImageView.set(.width, to: 150)
headingImageView.set(.height, to: Values.mediumFontSize)
navigationItem.titleView = headingImageView
}
internal func setUpNavBarSessionIcon() {
let logoImageView = UIImageView()
logoImageView.image = #imageLiteral(resourceName: "SessionGreen32")
logoImageView.contentMode = .scaleAspectFit
logoImageView.set(.width, to: 32)
logoImageView.set(.height, to: 32)
navigationItem.titleView = logoImageView
}
}

Loading…
Cancel
Save