mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
24 lines
836 B
Swift
24 lines
836 B
Swift
//
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
|
//
|
|
|
|
// Based on https://stackoverflow.com/questions/1823317/get-the-current-first-responder-without-using-a-private-api/11768282#11768282
|
|
extension UIResponder {
|
|
private weak static var firstResponder: UIResponder?
|
|
|
|
@objc
|
|
public class func currentFirstResponder() -> UIResponder? {
|
|
firstResponder = nil
|
|
|
|
// If target (`to:`) is nil, the app sends the message to the first responder,
|
|
// from whence it progresses up the responder chain until it is handled.
|
|
UIApplication.shared.sendAction(#selector(setSelfAsFirstResponder(sender:)), to: nil, from: nil, for: nil)
|
|
|
|
return firstResponder
|
|
}
|
|
|
|
@objc
|
|
private func setSelfAsFirstResponder(sender: AnyObject) {
|
|
UIResponder.firstResponder = self
|
|
}
|
|
}
|