diff --git a/Blink.xcodeproj/project.pbxproj b/Blink.xcodeproj/project.pbxproj index e5f40a43e..62d385e69 100644 --- a/Blink.xcodeproj/project.pbxproj +++ b/Blink.xcodeproj/project.pbxproj @@ -4868,7 +4868,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 809; + CURRENT_PROJECT_VERSION = 819; DEAD_CODE_STRIPPING = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; @@ -4918,7 +4918,7 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 809; + CURRENT_PROJECT_VERSION = 819; DEAD_CODE_STRIPPING = NO; DEFINES_MODULE = YES; ENABLE_BITCODE = NO; diff --git a/Blink/KBTracker.swift b/Blink/KBTracker.swift index 99bbab229..15ee396cb 100644 --- a/Blink/KBTracker.swift +++ b/Blink/KBTracker.swift @@ -89,12 +89,13 @@ class KBObserver: NSObject, UIInteraction { let kbEndFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect, kbEndFrame != self.kbScreenFrame else { +// print("!!! will show", notification.userInfo) return } self.kbScreenFrame = kbEndFrame self.view?.setNeedsLayout() - + NotificationCenter.default.post(name: NSNotification.Name(rawValue: LayoutManagerBottomInsetDidUpdate), object: nil) } @objc private func _keyboardWillHide(notification: Notification) { @@ -105,14 +106,17 @@ class KBObserver: NSObject, UIInteraction { let kbEndFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect, kbEndFrame != self.kbScreenFrame else { +// print("!!! will hide", notification.userInfo) return } self.kbScreenFrame = kbEndFrame self.view?.setNeedsLayout() + NotificationCenter.default.post(name: NSNotification.Name(rawValue: LayoutManagerBottomInsetDidUpdate), object: nil) } @objc private func _keyboardWillChangeFrame(notification: Notification) { + return guard let screen = notification.object as? UIScreen, let view = self.view, @@ -120,6 +124,7 @@ class KBObserver: NSObject, UIInteraction { let kbEndFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect, kbEndFrame != self.kbScreenFrame else { +// print("!!! change frame", notification.userInfo) return } @@ -292,86 +297,21 @@ class KBTracker: NSObject { } @objc private func _keyboardDidChangeFrame(_ notification: Notification) { -// debugPrint("_keyboardDidChangeFrame", notification.userInfo); -// debugPrint("_keyboardDidChangeFrame"); - guard let userInfo = notification.userInfo, - let kbFrameEnd = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect, - let kbFrameBegin = userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as? CGRect //, -// let kbFrameCenterBegin = userInfo["UIKeyboardCenterBeginUserInfoKey"] as? CGRect, -// let isLocal = userInfo[UIResponder.keyboardIsLocalUserInfoKey] as? Bool + let _ = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect, + let _ = userInfo[UIResponder.keyboardFrameBeginUserInfoKey] as? CGRect //, else { return } - - let screenMaxY = UIScreen.main.bounds.size.height - - var bottomInset: CGFloat = 0 - let idiom = UIDevice.current.userInterfaceIdiom - if !isHardwareKB, let fr = self.input?.spaceController?.trackingKBFrame { - bottomInset = screenMaxY - CGRectGetMinY(fr) - - - if idiom == UIUserInterfaceIdiom.pad { - - - if kbFrameBegin.isEmpty { -// kbTraits.isFloatingKB = true -// kbDevice = .in6_5 -// kbTraits.isPortrait = true -// print("floating_frame", fr, kbFrameEnd, kbFrameBegin) - bottomInset = 0 - } - } - } - - - -// -// // kb frame in screen coordinates -// if (kbFrameEnd.origin.x == 0 && kbFrameEnd.width == screenWidth && kbFrameEnd.height > 0) { -// if kbMaxY >= screenMaxY { -// bottomInset = screenMaxY - kbMinY -// } -// -// if (bottomInset < 30) { -// bottomInset = 0 -// } -// } -// -// if isLocal && idiom == .pad { -// let isFloating = kbFrameEnd.origin.y > 0 && kbFrameEnd.origin.x > 0 || kbFrameEnd == .zero -// -// if !kbTraits.isFloatingKB && isFloating { -// kbDevice = .in6_5 -// kbTraits.isPortrait = true -// } else if kbTraits.isFloatingKB && !isFloating && !kbTraits.isHKBAttached { -// kbDevice = .detect() -// } -// kbTraits.isFloatingKB = isFloating -// } - - // if bottomInset == 0 && _kbTraits.isFloatingKB, - // let safeInsets = superview?.safeAreaInsets { - // bottomInset = _kbView.intrinsicContentSize.height + safeInsets.bottom - // } - if isHardwareKB { if kbTraits.isFloatingKB { kbDevice = .detect() } kbTraits.isFloatingKB = false - bottomInset = 0 - - if !hideSmartKeysWithHKB && idiom == .phone, - let safeInsets = input?.kbView.superview?.safeAreaInsets { - bottomInset = (input?.kbView.intrinsicContentSize.height ?? 0) + safeInsets.bottom; - } } - LayoutManager.updateMainWindowKBBottomInset(bottomInset); } @objc private func _keyboardWillShow(_ notification: Notification) { diff --git a/Blink/LayoutManager.h b/Blink/LayoutManager.h index 6d0bd9c0a..f51db738a 100644 --- a/Blink/LayoutManager.h +++ b/Blink/LayoutManager.h @@ -43,8 +43,8 @@ extern NSString *LayoutManagerBottomInsetDidUpdate; + (BKLayoutMode) deviceDefaultLayoutMode; + (UIEdgeInsets) buildSafeInsetsForController:(UIViewController *)ctrl andMode:(BKLayoutMode) mode; + (NSString *) layoutModeToString:(BKLayoutMode)mode; -+ (CGFloat) mainWindowKBBottomInset; -+ (void) updateMainWindowKBBottomInset:(CGFloat) bottomInset; +//+ (CGFloat) mainWindowKBBottomInset; +//+ (void) updateMainWindowKBBottomInset:(CGFloat) bottomInset; @end diff --git a/Blink/LayoutManager.m b/Blink/LayoutManager.m index a77925266..2bfb4b835 100644 --- a/Blink/LayoutManager.m +++ b/Blink/LayoutManager.m @@ -35,31 +35,9 @@ #import -CGFloat __mainWindowKBBottomInset = 0; - NSString * LayoutManagerBottomInsetDidUpdate = @"LayoutManagerBottomInsetDidUpdate"; -NSTimer *__debounceTimer = nil; - -@implementation LayoutManager { - -} -+ (CGFloat) mainWindowKBBottomInset { - return __mainWindowKBBottomInset; -} - -+ (void) updateMainWindowKBBottomInset:(CGFloat) bottomInset { - if (__mainWindowKBBottomInset == bottomInset) { - return; - } - - __mainWindowKBBottomInset = bottomInset; - [__debounceTimer invalidate]; - - __debounceTimer = [NSTimer scheduledTimerWithTimeInterval:0.6 repeats:NO block:^(NSTimer * _Nonnull timer) { - [NSNotificationCenter.defaultCenter postNotificationName:LayoutManagerBottomInsetDidUpdate object:nil]; - }]; -} +@implementation LayoutManager + (BKLayoutMode) deviceDefaultLayoutMode { DeviceInfo *device = [DeviceInfo shared]; @@ -92,10 +70,19 @@ + (UIEdgeInsets) buildSafeInsetsForController:(UIViewController *)ctrl andMode:( return window.safeAreaInsets; } + SpaceController *spaceCtrl = nil; + UIViewController *parent = ctrl.parentViewController; + while (parent) { + if ([parent isKindOfClass:[SpaceController class]]) { + spaceCtrl = (SpaceController *)parent; + break; + } + parent = parent.parentViewController; + } + UIEdgeInsets deviceMargins = window.safeAreaInsets;// UIEdgeInsetsZero;// ctrl.viewDeviceSafeMargins; BOOL fullScreen = CGRectEqualToRect(mainScreen.bounds, window.bounds); - CGRect windowRect = [window.coordinateSpace convertRect:window.bounds toCoordinateSpace:mainScreen.coordinateSpace]; UIEdgeInsets result = UIEdgeInsetsZero; @@ -156,9 +143,7 @@ + (UIEdgeInsets) buildSafeInsetsForController:(UIViewController *)ctrl andMode:( } } - CGFloat relative = __mainWindowKBBottomInset - (CGRectGetMaxY(mainScreen.bounds) - CGRectGetMaxY(windowRect)); - - result.bottom = MAX(result.bottom, relative); + result.bottom = MAX(result.bottom, [spaceCtrl bottomInset]); return result; } diff --git a/Blink/SpaceController.swift b/Blink/SpaceController.swift index 79459c920..17824b68a 100644 --- a/Blink/SpaceController.swift +++ b/Blink/SpaceController.swift @@ -65,17 +65,11 @@ class SpaceController: UIViewController { private weak var _termViewToFocus: TermView? = nil var stuckKeyCode: KeyCode? = nil - private var _kbTrackerView = UIView() private var _kbObserver = KBObserver() private var _snippetsVC: SnippetsViewController? = nil private var _blinkMenu: BlinkMenu? = nil private var _bottomTapAreaView = UIView() - - public var trackingKBFrame: CGRect? { - self.view.window?.screen.coordinateSpace.convert(_kbTrackerView.frame, from: self.view.coordinateSpace) - } - var safeFrame: CGRect { _overlay.frame } @@ -88,20 +82,10 @@ class SpaceController: UIViewController { return } - if let bottomInset = _kbObserver.bottomInset { - var insets = UIEdgeInsets.zero - insets.bottom = bottomInset - _overlay.frame = view.bounds.inset(by: insets) - } else { - if window.screen === UIScreen.main { - var insets = UIEdgeInsets.zero - insets.bottom = LayoutManager.mainWindowKBBottomInset() - _overlay.frame = view.bounds.inset(by: insets) - } else { - _overlay.frame = view.bounds - } - } - + let bottomInset = _kbObserver.bottomInset ?? 0 + var insets = UIEdgeInsets.zero + insets.bottom = bottomInset + _overlay.frame = view.bounds.inset(by: insets) _snippetsVC?.view.frame = _overlay.frame if let menu = _blinkMenu { @@ -127,7 +111,6 @@ class SpaceController: UIViewController { } } } - self.view.sendSubviewToBack(_kbTrackerView); let windowBounds = window.bounds _bottomTapAreaView.frame = CGRect(x: windowBounds.width * 0.5 - 250, y: windowBounds.height - 18, width: 250 * 2, height: 18) // _bottomTapAreaView.backgroundColor = UIColor.red @@ -179,6 +162,10 @@ class SpaceController: UIViewController { view.setNeedsLayout() } + @objc public func bottomInset() -> CGFloat { + _kbObserver.bottomInset ?? 0 + } + @objc private func _setupAppearance() { self.view.tintColor = .cyan switch BLKDefaults.keyboardStyle() { @@ -228,16 +215,6 @@ class SpaceController: UIViewController { _viewportsController.setViewControllers([term], direction: .forward, animated: false) } - _kbTrackerView.translatesAutoresizingMaskIntoConstraints = false; - - self.view.addSubview(_kbTrackerView) - - _kbTrackerView.leadingAnchor.constraint(equalTo: self.view.keyboardLayoutGuide.leadingAnchor).isActive = true; - _kbTrackerView.widthAnchor.constraint(equalTo: self.view.keyboardLayoutGuide.widthAnchor).isActive = true; - _kbTrackerView.heightAnchor.constraint(equalTo: self.view.keyboardLayoutGuide.heightAnchor).isActive = true; - _kbTrackerView.bottomAnchor.constraint(equalTo: self.view.keyboardLayoutGuide.bottomAnchor).isActive = true; -// _kbTrackerView.backgroundColor = UIColor.yellow - self.view.addInteraction(_kbObserver) self.view.addSubview(_bottomTapAreaView) @@ -254,33 +231,11 @@ class SpaceController: UIViewController { } -// public override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { -// super.viewWillTransition(to: size, with: coordinator) -// if view.window?.isKeyWindow == true { -// DispatchQueue.main.async { -// KBTracker.shared.attach(input: KBTracker.shared.input) -// input?.sync(traits: kbTraits, device: kbDevice, hideSmartKeysWithHKB: hideSmartKeysWithHKB) -// self.currentTerm()?.termDevice.view?.webView?.kbView.reset() -// SmarterTermInput.shared.contentView()?.reloadInputViews() -// } -// } -// } - func showAlert(msg: String) { let ctrl = UIAlertController(title: "Error", message: msg, preferredStyle: .alert) ctrl.addAction(UIAlertAction(title: "Ok", style: .default)) self.present(ctrl, animated: true) } - -// override var editingInteractionConfiguration: UIEditingInteractionConfiguration { -// // IOS ISSUE: editingInteractionConfiguration doesn't called anymore in iOS/PadOS 16.... -// // Moved attach to focus. -// DispatchQueue.main.async { -// self._attachHUD() -// } -// return .default -// return .none -// } deinit { NotificationCenter.default.removeObserver(self) @@ -1082,28 +1037,11 @@ extension SpaceController { DispatchQueue.main.async { _ = KBTracker.shared.input?.resignFirstResponder(); -// if UIApplication.shared.supportsMultipleScenes { -// -// var opened: UISceneSession? = nil -// for session in UIApplication.shared.openSessions { -// if session.configuration.name == "whatsnew" { -// opened = session -// break -// } -// } -// let options = UIWindowScene.ActivationRequestOptions() -// options.preferredPresentationStyle = .prominent -// options.requestingScene = self.view.window?.windowScene; -// -// let activity = NSUserActivity(activityType: "com.blink.whatsnew") -// -// UIApplication.shared.requestSceneSessionActivation(opened, userActivity: activity, options: options) -// } else { - // Reset version when opening. - WhatsNewInfo.setNewVersion() - let root = UIHostingController(rootView: GridView(rowsProvider: RowsViewModel(baseURL: XCConfig.infoPlistWhatsNewURL()))) - self.present(root, animated: true, completion: nil) -// } + // Reset version when opening. + WhatsNewInfo.setNewVersion() + let root = UIHostingController(rootView: GridView(rowsProvider: RowsViewModel(baseURL: XCConfig.infoPlistWhatsNewURL()))) + self.present(root, animated: true, completion: nil) + } }