Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

# Upcoming

### 🔄 Changed
### 🐞 Fixed
- Fix crash when opening message overlay in iPad with a TabBar [#627](https://github.com/GetStream/stream-chat-swiftui/pull/627)

# [4.65.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.65.0)
_October 18, 2024_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
currentSnapshot: currentSnapshot,
popInAnimationInProgress: !popIn
)
.offset(y: spacing > 0 ? screenHeight - currentSnapshot.size.height : 0)
.offset(y: overlayOffsetY)
} else {
Color.gray.opacity(0.4)
}
Expand Down Expand Up @@ -290,7 +290,16 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {

return originY - spacing
}


private var overlayOffsetY: CGFloat {
if isIPad && UITabBar.appearance().isHidden == false {
// When using iPad with TabBar, this hard coded value makes
// sure that the overlay is in the correct position.
return 20
}
return spacing > 0 ? screenHeight - currentSnapshot.size.height : 0
}

private var spacing: CGFloat {
let divider: CGFloat = isIPad ? 2 : 1
let spacing = (UIScreen.main.bounds.height - screenHeight) / divider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public struct BottomLeftView<Content: View>: View {

/// Returns the top most view controller.
func topVC() -> UIViewController? {
// TODO: Refactor ReactionsOverlayView to use a background blur, instead of a snapshot.
/// Since the current approach is too error-prone and dependent of the app's hierarchy,

let keyWindow = UIApplication.shared.windows.filter { $0.isKeyWindow }.first

if var topController = keyWindow?.rootViewController {
Expand All @@ -92,10 +95,16 @@ func topVC() -> UIViewController? {
if UIDevice.current.userInterfaceIdiom == .pad {
let children = topController.children
if !children.isEmpty {
let splitVC = children[0]
let sideVCs = splitVC.children
if sideVCs.count > 1 {
topController = sideVCs[1]
if let splitVC = children[0] as? UISplitViewController,
let contentVC = splitVC.viewControllers.last {
topController = contentVC
return topController
} else if let tabVC = children[0] as? UITabBarController,
let selectedVC = tabVC.selectedViewController {
// If the selectedVC is split view, we need to grab the content view of it
// other wise, the selectedVC is already the content view.
let selectedContentVC = selectedVC.children.first?.children.last?.children.first
topController = selectedContentVC ?? selectedVC
return topController
}
}
Expand Down
12 changes: 3 additions & 9 deletions Sources/StreamChatSwiftUI/Utils/SnapshotCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,9 @@ public class DefaultSnapshotCreator: SnapshotCreator {
}

func makeSnapshot(from view: UIView) -> UIImage {
let currentSnapshot: UIImage?
UIGraphicsBeginImageContext(view.frame.size)
if let currentGraphicsContext = UIGraphicsGetCurrentContext() {
view.layer.render(in: currentGraphicsContext)
currentSnapshot = UIGraphicsGetImageFromCurrentImageContext()
} else {
currentSnapshot = images.snapshot
let renderer = UIGraphicsImageRenderer(size: view.bounds.size)
return renderer.image { _ in
view.drawHierarchy(in: view.bounds, afterScreenUpdates: true)
}
UIGraphicsEndImageContext()
return currentSnapshot ?? images.snapshot
}
}
Loading