Skip to content

Commit

Permalink
Merge branch 'issue-1811-cursor' into ios-17
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Aug 16, 2023
2 parents 9a5bc78 + 812b171 commit f301dd8
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
12 changes: 12 additions & 0 deletions Blink/KBTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,13 @@ class KBObserver: NSObject, UIInteraction {
// print("!!! change frame", notification.userInfo)
return
}

KBTracker.shared.detectHardwareKBWithSoftwareKBHeight(height: kbEndFrame.height)


self.kbScreenFrame = kbEndFrame
self.view?.setNeedsLayout()
NotificationCenter.default.post(name: NSNotification.Name(rawValue: LayoutManagerBottomInsetDidUpdate), object: nil)
}

}
Expand All @@ -144,6 +148,14 @@ class KBTracker: NSObject {

private(set) var input: SmarterTermInput? = nil

@objc var detectHardwareKBWithHeight = true

func detectHardwareKBWithSoftwareKBHeight(height: CGFloat) {
if detectHardwareKBWithHeight {
KBTracker.shared.isHardwareKB = height < 150
}
}

@objc var isHardwareKB: Bool = true {
didSet {
let oldValue = kbTraits.isHKBAttached;
Expand Down
47 changes: 30 additions & 17 deletions Blink/SmarterKeys/SmarterTermInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,27 @@
import UIKit
import Combine


class CaretHider {
var _cancelable: AnyCancellable? = nil
weak var _view: UIView?

init(view: UIView) {
_view = view;
_cancelable = view.layer.publisher(for: \.sublayers).sink { (layers) in
if let caretView = view.value(forKeyPath: "caretView") as? UIView {
caretView.isHidden = true
}

if let floatingView = view.value(forKeyPath: "floatingCaretView") as? UIView {
floatingView.isHidden = true
if #available(iOS 17.0, *) {
let cursorView = view.subviews.first(where: { v in
v.classForCoder.description().hasSuffix("CursorView")
})
cursorView?.layer.sublayers?.first?.isHidden = true
} else {
if let caretView = view.value(forKeyPath: "caretView") as? UIView {
caretView.isHidden = true
}

if let floatingView = view.value(forKeyPath: "floatingCaretView") as? UIView {
floatingView.isHidden = true
}
}
}
}
Expand All @@ -55,12 +63,19 @@ class CaretHider {
return
}

if let caretView = view.value(forKeyPath: "caretView") as? UIView {
caretView.isHidden = false
}

if let floatingView = view.value(forKeyPath: "floatingCaretView") as? UIView {
floatingView.isHidden = false
if #available(iOS 17.0, *) {
let cursorView = view.subviews.first(where: { v in
v.classForCoder.description().hasSuffix("CursorView")
})
cursorView?.layer.sublayers?.first?.isHidden = false
} else {
if let caretView = view.value(forKeyPath: "caretView") as? UIView {
caretView.isHidden = false
}

if let floatingView = view.value(forKeyPath: "floatingCaretView") as? UIView {
floatingView.isHidden = false
}
}
}
}
Expand Down Expand Up @@ -124,19 +139,18 @@ class CaretHider {
false
}


private var _caretHider: CaretHider? = nil


override func ready() {
super.ready()
reportLang()

// device?.focus()
kbView.isHidden = false
kbView.invalidateIntrinsicContentSize()

if let v = selectionView() {
_caretHider = CaretHider(view: v)
}
hideCaret()
}

func reset() {
Expand Down Expand Up @@ -366,7 +380,6 @@ class CaretHider {
commandPressTimestamp = 0
}

// var commandPresses: Int = 0
var commandPressTimestamp: TimeInterval = 0
}

Expand Down
6 changes: 5 additions & 1 deletion KB/Native/Views/KBWebViewBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ - (KeyCommand *)_modifiersCommand:(UIKeyModifierFlags) flags {
}

- ( UIView * _Nullable )selectionView {
return [self.scrollView.subviews.firstObject valueForKeyPath:@"interactionAssistant.selectionView"];
if (@available(iOS 17, *)) {
return self.scrollView.subviews.firstObject;
} else {
return [self.scrollView.subviews.firstObject valueForKeyPath:@"interactionAssistant.selectionView"];
}
}

- (UIEditingInteractionConfiguration)editingInteractionConfiguration {
Expand Down

0 comments on commit f301dd8

Please sign in to comment.