Files
mattermost-mobile/ios/Mattermost/Modules/SplitViewModule.swift
Elias Nahum d61fbd3180 Various fixes (#7161)
* Save message draft when post input is unmounted

* Fix switch CRT on/off

* Handle iPad on Stage Manager

* iOS Share Extension to use LRU cache instead of file cache

* Support building android as aab

* use handleReconnect instead of appEntry on handleCRTToggled

* show skin tone selector tutorial after running all interactions

* Update app/actions/remote/preference.ts

Co-authored-by: Daniel Espino García <larkox@gmail.com>

* fix lint

---------

Co-authored-by: Daniel Espino García <larkox@gmail.com>
2023-02-24 13:02:05 +02:00

79 lines
2.6 KiB
Swift

import Foundation
@objc(SplitViewModule)
class SplitViewModule: RCTEventEmitter {
var hasListeners = false
@objc
override static func requiresMainQueueSetup() -> Bool {
return true
}
@objc
override func supportedEvents() -> [String]! {
return ["SplitViewChanged"]
}
@objc
override func startObserving() {
hasListeners = true
NotificationCenter.default.addObserver(self,
selector: #selector(isSplitView), name: NSNotification.Name.RCTUserInterfaceStyleDidChange,
object: nil)
}
@objc
override func stopObserving() {
hasListeners = false
NotificationCenter.default.removeObserver(self,
name: NSNotification.Name.RCTUserInterfaceStyleDidChange,
object: nil)
}
@objc 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
}
@objc func isSplitView() {
if hasListeners && UIDevice.current.userInterfaceIdiom == .pad {
sendEvent(withName: "SplitViewChanged", body: [
"isSplitView": !isRunningInFullScreen(),
"isTablet": UIDevice.current.userInterfaceIdiom == .pad,
])
}
}
@objc(isRunningInSplitView:withRejecter:)
func isRunningInSplitView(resolve:@escaping RCTPromiseResolveBlock, reject:RCTPromiseRejectBlock) -> Void {
DispatchQueue.main.async { [weak self] in
resolve([
"isSplitView": !(self?.isRunningInFullScreen() ?? false),
"isTablet": UIDevice.current.userInterfaceIdiom == .pad,
])
}
}
@objc(unlockOrientation)
func unlockOrientation() {
DispatchQueue.main.async {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.allowRotation = true
UIDevice.current.setValue(UIInterfaceOrientation.unknown.rawValue, forKey: "orientation")
}
}
@objc(lockPortrait)
func lockPortrait() {
DispatchQueue.main.async {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.allowRotation = false
UIDevice.current.setValue(UIInterfaceOrientation.unknown.rawValue, forKey: "orientation")
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
}
}