From d7e54999c9856c01ce8f438ce583040999e9ecd6 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Thu, 7 Nov 2024 08:30:54 +0800 Subject: [PATCH] fix iPad split screen (#8317) --- .../rnutils/ios/RNUtilsWrapper.swift | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/libraries/@mattermost/rnutils/ios/RNUtilsWrapper.swift b/libraries/@mattermost/rnutils/ios/RNUtilsWrapper.swift index 1851eda67..c9f800841 100644 --- a/libraries/@mattermost/rnutils/ios/RNUtilsWrapper.swift +++ b/libraries/@mattermost/rnutils/ios/RNUtilsWrapper.swift @@ -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() { @@ -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, ]) }