|
@@ -104,7 +104,11 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
@end
|
|
|
|
|
|
|
|
|
-@interface YYTextView () <UIScrollViewDelegate, UIAlertViewDelegate, YYTextDebugTarget, YYTextKeyboardObserver> {
|
|
|
+@interface YYTextView () <UIScrollViewDelegate,
|
|
|
+#if !TARGET_OS_VISION
|
|
|
+UIAlertViewDelegate,
|
|
|
+#endif
|
|
|
+YYTextDebugTarget, YYTextKeyboardObserver> {
|
|
|
|
|
|
YYTextRange *_selectedTextRange; /// nonnull
|
|
|
YYTextRange *_markedTextRange;
|
|
@@ -636,6 +640,14 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
|
|
|
if (self.isFirstResponder || _containerView.isFirstResponder) {
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+#if TARGET_OS_VISION
|
|
|
+ UIMenuController *menu = [UIMenuController sharedMenuController];
|
|
|
+ [menu update];
|
|
|
+ if (!_state.showingMenu || !menu.menuVisible) {
|
|
|
+ _state.showingMenu = YES;
|
|
|
+ [menu showMenuFromView:_selectionView rect:CGRectStandardize(rect)];
|
|
|
+ }
|
|
|
+#else
|
|
|
UIMenuController *menu = [UIMenuController sharedMenuController];
|
|
|
[menu setTargetRect:CGRectStandardize(rect) inView:_selectionView];
|
|
|
[menu update];
|
|
@@ -643,6 +655,7 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
_state.showingMenu = YES;
|
|
|
[menu setMenuVisible:YES animated:YES];
|
|
|
}
|
|
|
+#endif
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -652,7 +665,11 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
if (_state.showingMenu) {
|
|
|
_state.showingMenu = NO;
|
|
|
UIMenuController *menu = [UIMenuController sharedMenuController];
|
|
|
+#if TARGET_OS_VISION
|
|
|
+ [menu hideMenu];
|
|
|
+#else
|
|
|
[menu setMenuVisible:NO animated:YES];
|
|
|
+#endif
|
|
|
}
|
|
|
if (_containerView.isFirstResponder) {
|
|
|
_state.ignoreFirstResponder = YES;
|
|
@@ -733,7 +750,11 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
if (CGRectGetMinY(inter) > CGRectGetMinY(bounds)) { // keyboard below self.top
|
|
|
|
|
|
UIEdgeInsets originalContentInset = self.contentInset;
|
|
|
+#if TARGET_OS_VISION
|
|
|
+ UIEdgeInsets originalScrollIndicatorInsets = self.verticalScrollIndicatorInsets;
|
|
|
+#else
|
|
|
UIEdgeInsets originalScrollIndicatorInsets = self.scrollIndicatorInsets;
|
|
|
+#endif
|
|
|
if (_insetModifiedByKeyboard) {
|
|
|
originalContentInset = _originalContentInset;
|
|
|
originalScrollIndicatorInsets = _originalScrollIndicatorInsets;
|
|
@@ -744,7 +765,11 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
if (!_insetModifiedByKeyboard) {
|
|
|
_insetModifiedByKeyboard = YES;
|
|
|
_originalContentInset = self.contentInset;
|
|
|
+#if TARGET_OS_VISION
|
|
|
+ _originalScrollIndicatorInsets = self.verticalScrollIndicatorInsets;
|
|
|
+#else
|
|
|
_originalScrollIndicatorInsets = self.scrollIndicatorInsets;
|
|
|
+#endif
|
|
|
}
|
|
|
UIEdgeInsets newInset = originalContentInset;
|
|
|
UIEdgeInsets newIndicatorInsets = originalScrollIndicatorInsets;
|
|
@@ -1575,6 +1600,9 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
|
|
|
/// Returns the `root` view controller (returns nil if not found).
|
|
|
- (UIViewController *)_getRootViewController {
|
|
|
+#if TARGET_OS_VISION
|
|
|
+ return self.yy_viewController;
|
|
|
+#else
|
|
|
UIViewController *ctrl = nil;
|
|
|
UIApplication *app = YYTextSharedApplication();
|
|
|
if (!ctrl) ctrl = app.keyWindow.rootViewController;
|
|
@@ -1587,6 +1615,7 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
}
|
|
|
if (!ctrl.view.window) return nil;
|
|
|
return ctrl;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
/// Clear the undo and redo stack, and capture current state to undo stack.
|
|
@@ -1677,6 +1706,9 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
/// Show undo alert if it can undo or redo.
|
|
|
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
|
|
|
- (void)_showUndoRedoAlert NS_EXTENSION_UNAVAILABLE_IOS(""){
|
|
|
+#if TARGET_OS_VISION
|
|
|
+ return;
|
|
|
+#else
|
|
|
_state.firstResponderBeforeUndoAlert = self.isFirstResponder;
|
|
|
__weak typeof(self) _self = self;
|
|
|
NSArray *strings = [self _localizedUndoStrings];
|
|
@@ -1744,6 +1776,7 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
#pragma clang diagnostic pop
|
|
|
}
|
|
|
}
|
|
|
+#endif
|
|
|
}
|
|
|
#endif
|
|
|
|
|
@@ -2169,7 +2202,7 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
|
|
|
[_inputDelegate selectionWillChange:self];
|
|
|
[_inputDelegate textWillChange:self];
|
|
|
- _innerText = text;
|
|
|
+ _innerText = text;
|
|
|
[self _parseText];
|
|
|
_selectedTextRange = [YYTextRange rangeWithRange:NSMakeRange(0, _innerText.length)];
|
|
|
[_inputDelegate textDidChange:self];
|
|
@@ -2741,7 +2774,7 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
|
|
[self _endTouchTracking];
|
|
|
[self _hideMenu];
|
|
|
-
|
|
|
+
|
|
|
if (!_state.swallowTouch) [super touchesCancelled:touches withEvent:event];
|
|
|
}
|
|
|
|
|
@@ -3208,6 +3241,7 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
|
|
|
#pragma mark - @protocol UIALertViewDelegate
|
|
|
|
|
|
+#if !TARGET_OS_VISION
|
|
|
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
|
|
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
|
|
|
if (title.length == 0) return;
|
|
@@ -3219,6 +3253,7 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
}
|
|
|
[self _restoreFirstResponderAfterUndoAlert];
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
#pragma mark - @protocol UIKeyInput
|
|
|
|
|
@@ -3455,12 +3490,16 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
_lastTypeRange = _selectedTextRange.asRange;
|
|
|
}
|
|
|
|
|
|
+#if TARGET_OS_VISION
|
|
|
+
|
|
|
+#else
|
|
|
- (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection forRange:(YYTextRange *)range {
|
|
|
if (!range) return;
|
|
|
range = [self _correctedTextRange:range];
|
|
|
[_innerText yy_setBaseWritingDirection:(NSWritingDirection)writingDirection range:range.asRange];
|
|
|
[self _commitUpdate];
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
- (NSString *)textInRange:(YYTextRange *)range {
|
|
|
range = [self _correctedTextRange:range];
|
|
@@ -3468,6 +3507,9 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
return [_innerText.string substringWithRange:range.asRange];
|
|
|
}
|
|
|
|
|
|
+#if TARGET_OS_VISION
|
|
|
+
|
|
|
+#else
|
|
|
- (UITextWritingDirection)baseWritingDirectionForPosition:(YYTextPosition *)position inDirection:(UITextStorageDirection)direction {
|
|
|
[self _updateIfNeeded];
|
|
|
position = [self _correctedTextPosition:position];
|
|
@@ -3487,6 +3529,7 @@ typedef NS_ENUM(NSUInteger, YYTextMoveDirection) {
|
|
|
|
|
|
return UITextWritingDirectionNatural;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
- (YYTextPosition *)beginningOfDocument {
|
|
|
return [YYTextPosition positionWithOffset:0];
|