Fix text format menu on iOS 13.2

This commit is contained in:
Ali 2019-11-02 22:55:46 +04:00
parent da67ea139c
commit 636e66b048
4 changed files with 27 additions and 4 deletions

View File

@ -71,6 +71,8 @@ NS_ASSUME_NONNULL_BEGIN
//! @abstract The range of text currently selected. If length is zero, the range is the cursor location.
@property NSRange selectedRange;
@property (readonly) CGRect selectionRect;
#pragma mark - Placeholder
/**
@abstract Indicates if the receiver is displaying the placeholder text.

View File

@ -566,6 +566,15 @@
_textKitComponents.textView.selectedRange = selectedRange;
}
- (CGRect)selectionRect {
UITextRange *range = [_textKitComponents.textView selectedTextRange];
if (range != nil) {
return [_textKitComponents.textView firstRectForRange:range];
} else {
return [_textKitComponents.textView bounds];
}
}
#pragma mark - Placeholder
- (BOOL)isDisplayingPlaceholder
{

View File

@ -33,8 +33,6 @@ final class ChatTextInputMenu {
UIMenuItem(title: self.stringStrikethrough, action: Selector(("formatAttributesStrikethrough:"))),
UIMenuItem(title: self.stringUnderline, action: Selector(("formatAttributesUnderline:")))
]
UIMenuController.shared.isMenuVisible = true
UIMenuController.shared.update()
}
}
@ -74,9 +72,15 @@ final class ChatTextInputMenu {
self.state = .inactive
}
func format() {
func format(view: UIView, rect: CGRect) {
if self.state == .general {
self.state = .format
if #available(iOS 13.0, *) {
UIMenuController.shared.showMenu(from: view, rect: rect)
} else {
UIMenuController.shared.isMenuVisible = true
UIMenuController.shared.update()
}
}
}

View File

@ -1437,6 +1437,12 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
}
if let textInputNode = self.textInputNode, let presentationInterfaceState = self.presentationInterfaceState {
if case .format = self.inputMenu.state {
self.inputMenu.deactivate()
UIMenuController.shared.update()
}
let baseFontSize = max(17.0, presentationInterfaceState.fontSize.baseDisplaySize)
refreshChatTextInputTypingAttributes(textInputNode, theme: presentationInterfaceState.theme, baseFontSize: baseFontSize)
}
@ -1478,7 +1484,9 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
}
@objc func _showTextStyleOptions(_ sender: Any) {
self.inputMenu.format()
if let textInputNode = self.textInputNode {
self.inputMenu.format(view: textInputNode.view, rect: textInputNode.selectionRect.insetBy(dx: 0.0, dy: -1.0))
}
}
@objc func formatAttributesBold(_ sender: Any) {