Skip to content

Commit

Permalink
fix iPad split screen (#8317)
Browse files Browse the repository at this point in the history
  • Loading branch information
enahum authored Nov 7, 2024
1 parent 6f381cf commit d7e5499
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions libraries/@mattermost/rnutils/ios/RNUtilsWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ import React

func getWindowSize() -> (CGSize?, CGSize?) {
guard let w = UIApplication.shared.delegate?.window, let window = w else { return (nil, nil) }
return (window.screen.bounds.size, window.frame.size)
return (window.screen.bounds.size, window.bounds.size)
}

func isRunningInFullScreen() -> Bool {
guard let w = UIApplication.shared.delegate?.window, let window = w else { return false }
let screenSize = window.screen.bounds.size.width
let frameSize = window.frame.size.width
let shouldBeConsideredFullScreen = frameSize >= (screenSize * 0.6)
return shouldBeConsideredFullScreen
let screenWidth = window.screen.bounds.size.width
let windowWidth = window.bounds.size.width
return windowWidth >= screenWidth * (2.0 / 3.0)
}

func isRunningInFullScreen(screen: CGSize?, frame: CGSize?) -> Bool {
guard let screenSize = screen?.width,
let frameSize = frame?.width else {return false}
let shouldBeConsideredFullScreen = frameSize >= (screenSize * 0.6)
return shouldBeConsideredFullScreen
func isRunningInFullScreen(screen: CGSize?, bounds: CGSize?) -> Bool {
guard let screenWidth = screen?.width,
let windowWidth = bounds?.width else {return false}
return windowWidth >= screenWidth * (2.0 / 3.0)
}

@objc public func captureEvents() {
Expand All @@ -53,21 +51,21 @@ import React

override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "frame" {
let (screen, frame) = getWindowSize()
guard let screen = screen, let frame = frame else {return}
isSplitView(screen: screen, frame: frame)
let (screen, bounds) = getWindowSize()
guard let screen = screen, let bounds = bounds else {return}
isSplitView(screen: screen, bounds: bounds)

delegate?.sendEvent(name: "DimensionsChanged", result: [
"width": frame.width,
"height": frame.height
"width": bounds.width,
"height": bounds.height
])
}
}

@objc func isSplitView(screen: CGSize, frame: CGSize) {
@objc func isSplitView(screen: CGSize, bounds: CGSize) {
if UIDevice.current.userInterfaceIdiom == .pad {
delegate?.sendEvent(name: "SplitViewChanged", result: [
"isSplit": !isRunningInFullScreen(screen: screen, frame: frame),
"isSplit": !isRunningInFullScreen(screen: screen, bounds: bounds),
"isTablet": UIDevice.current.userInterfaceIdiom == .pad,
])
}
Expand Down

0 comments on commit d7e5499

Please sign in to comment.