11import { ScrollEventData } from '../scroll-view' ;
22import { textProperty } from '../text-base' ;
3- import { TextViewBase as TextViewBaseCommon } from './text-view-common' ;
3+ import { iosWritingToolsAllowedInputProperty , iosWritingToolsBehaviorProperty , TextViewBase as TextViewBaseCommon , WritingToolsAllowedInput , WritingToolsBehavior } from './text-view-common' ;
44import { editableProperty , hintProperty , placeholderColorProperty , _updateCharactersInRangeReplacementString } from '../editable-text-base' ;
55import { CoreTypes } from '../../core-types' ;
66import { CSSType } from '../core/view' ;
77import { Color } from '../../color' ;
88import { colorProperty , borderTopWidthProperty , borderRightWidthProperty , borderBottomWidthProperty , borderLeftWidthProperty , paddingTopProperty , paddingRightProperty , paddingBottomProperty , paddingLeftProperty , Length } from '../styling/style-properties' ;
9- import { iOSNativeHelper , layout } from '../../utils' ;
9+ import { layout , isRealDevice } from '../../utils' ;
10+ import { SDK_VERSION } from '../../utils/constants' ;
1011
1112import { profile } from '../../profiling' ;
12-
13- const majorVersion = iOSNativeHelper . MajorVersion ;
13+ export { WritingToolsAllowedInput , WritingToolsBehavior } from './text-view-common' ;
1414
1515@NativeClass
1616class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
@@ -70,6 +70,21 @@ class UITextViewDelegateImpl extends NSObject implements UITextViewDelegate {
7070 return owner . scrollViewDidScroll ( sv ) ;
7171 }
7272 }
73+
74+ public textViewWritingToolsWillBegin ( textView : UITextView ) : void {
75+ const owner = this . _owner ?. deref ( ) ;
76+ if ( owner ) {
77+ owner . isWritingToolsActive = true ;
78+ }
79+ }
80+
81+ public textViewWritingToolsDidEnd ( textView : UITextView ) : void {
82+ const owner = this . _owner ?. deref ( ) ;
83+ if ( owner ) {
84+ owner . isWritingToolsActive = false ;
85+ owner . textViewDidChange ( textView ) ;
86+ }
87+ }
7388}
7489
7590@NativeClass
@@ -92,8 +107,8 @@ export class TextView extends TextViewBaseCommon {
92107
93108 public _isEditing : boolean ;
94109
95- private _hintColor = majorVersion <= 12 || ! UIColor . placeholderTextColor ? UIColor . blackColor . colorWithAlphaComponent ( 0.22 ) : UIColor . placeholderTextColor ;
96- private _textColor = majorVersion <= 12 || ! UIColor . labelColor ? null : UIColor . labelColor ;
110+ private _hintColor = SDK_VERSION <= 12 || ! UIColor . placeholderTextColor ? UIColor . blackColor . colorWithAlphaComponent ( 0.22 ) : UIColor . placeholderTextColor ;
111+ private _textColor = SDK_VERSION <= 12 || ! UIColor . labelColor ? null : UIColor . labelColor ;
97112
98113 createNativeView ( ) {
99114 const textView = NoScrollAnimationUITextView . new ( ) ;
@@ -144,10 +159,12 @@ export class TextView extends TextViewBaseCommon {
144159 }
145160
146161 public textViewDidChange ( textView : UITextView ) : void {
147- if ( this . updateTextTrigger === 'textChanged' ) {
148- textProperty . nativeValueChange ( this , textView . text ) ;
162+ if ( ! this . isWritingToolsActive || this . enableWritingToolsEvents ) {
163+ if ( this . updateTextTrigger === 'textChanged' ) {
164+ textProperty . nativeValueChange ( this , textView . text ) ;
165+ }
166+ this . requestLayout ( ) ;
149167 }
150- this . requestLayout ( ) ;
151168 }
152169
153170 public textViewShouldChangeTextInRangeReplacementText ( textView : UITextView , range : NSRange , replacementString : string ) : boolean {
@@ -399,6 +416,52 @@ export class TextView extends TextViewBaseCommon {
399416 right : inset . right ,
400417 } ;
401418 }
419+
420+ [ iosWritingToolsBehaviorProperty . setNative ] ( value : WritingToolsBehavior ) {
421+ if ( SDK_VERSION >= 18 && isRealDevice ( ) ) {
422+ this . nativeTextViewProtected . writingToolsBehavior = this . _writingToolsBehaviorType ( value ) ;
423+ }
424+ }
425+
426+ [ iosWritingToolsAllowedInputProperty . setNative ] ( value : Array < WritingToolsAllowedInput > ) {
427+ if ( SDK_VERSION >= 18 && isRealDevice ( ) ) {
428+ let writingToolsInput = null ;
429+ for ( const inputType of value ) {
430+ writingToolsInput = ( writingToolsInput != null ? writingToolsInput : 0 ) + this . _writingToolsAllowedType ( inputType ) ;
431+ }
432+ if ( writingToolsInput === null ) {
433+ writingToolsInput = UIWritingToolsResultOptions . Default ;
434+ }
435+ this . nativeTextViewProtected . allowsEditingTextAttributes = true ;
436+ this . nativeTextViewProtected . allowedWritingToolsResultOptions = writingToolsInput ;
437+ }
438+ }
439+
440+ private _writingToolsBehaviorType ( value : WritingToolsBehavior ) {
441+ switch ( value ) {
442+ case WritingToolsBehavior . Complete :
443+ return UIWritingToolsBehavior . Complete ;
444+ case WritingToolsBehavior . Default :
445+ return UIWritingToolsBehavior . Default ;
446+ case WritingToolsBehavior . Limited :
447+ return UIWritingToolsBehavior . Limited ;
448+ case WritingToolsBehavior . None :
449+ return UIWritingToolsBehavior . None ;
450+ }
451+ }
452+
453+ private _writingToolsAllowedType ( value : WritingToolsAllowedInput ) {
454+ switch ( value ) {
455+ case WritingToolsAllowedInput . Default :
456+ return UIWritingToolsResultOptions . Default ;
457+ case WritingToolsAllowedInput . List :
458+ return UIWritingToolsResultOptions . List ;
459+ case WritingToolsAllowedInput . PlainText :
460+ return UIWritingToolsResultOptions . PlainText ;
461+ case WritingToolsAllowedInput . RichText :
462+ return UIWritingToolsResultOptions . RichText ;
463+ }
464+ }
402465}
403466
404467TextView . prototype . recycleNativeView = 'auto' ;
0 commit comments