/* * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file * @kit ArkUI */ /*** if arkts 1.2 */ import { KeyboardOptions, PasteEvent } from './richEditor'; import { CaretStyle, DeleteValue, EditMenuOptions, EditableTextOnChangeCallback, InsertValue, AutoCapitalizationMode,EditableTextChangeValue,KeyboardAppearance } from './textCommon'; import { BarState, CopyOptions, FontStyle, FontWeight, LineBreakStrategy, TextContentStyle, TextAlign, TextOverflow, TextHeightAdaptivePolicy, WordBreak, EllipsisMode } from './enums'; import { EnterKeyType, SubmitEvent, ContentType } from './textInput'; import { Dimension, Font, Length, LengthMetrics, ResourceColor, ResourceStr } from './units'; import { InputCounterOptions, TextContentControllerBase, SelectionOptions, TextDecorationOptions, CommonMethod, Callback, Optional, Bindable } from './common'; import { CustomBuilder } from './builder'; import { Resource } from '../../global/resource'; /*** endif */ /** * Provides the method of switching the cursor position. * * @extends TextContentControllerBase * @since 8 */ /** * Provides the method of switching the cursor position. * * @extends TextContentControllerBase * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * Provides the method of switching the cursor position. * * @extends TextContentControllerBase * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since arkts {'1.1':'11','1.2':'20'} * @arkts 1.1&1.2 */ declare class TextAreaController extends TextContentControllerBase { /** * constructor. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 8 */ /** * constructor. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * constructor. * A constructor used to create a TextAreaController object. * * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since arkts {'1.1':'11','1.2':'20'} * @arkts 1.1&1.2 */ constructor(); /** * Called when the position of the insertion cursor is set. * * @param { number } value * @syscap SystemCapability.ArkUI.ArkUI.Full * @since 8 */ /** * Called when the position of the insertion cursor is set. * * @param { number } value * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * Called when the position of the insertion cursor is set. * * @param { number } value - Length from the start of the string to the position where the caret is located. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since arkts {'1.1':'11','1.2':'20'} * @arkts 1.1&1.2 */ caretPosition(value: number): void; /** * Text selection is achieved by specifying the start and end positions of the text. * * @param { number } selectionStart - The start position of the selected text. * @param { number } selectionEnd - The end position of the selected text. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @since 10 */ /** * Text selection is achieved by specifying the start and end positions of the text. * * @param { number } selectionStart - The start position of the selected text. * @param { number } selectionEnd - The end position of the selected text. * @syscap SystemCapability.ArkUI.ArkUI.Full * @crossplatform * @atomicservice * @since 11 */ /** * Text selection is achieved by specifying the start and end positions of the text. * *
NOTE:
*
If selectionMenuHidden is set to true or a 2-in-1 device is used,
* calling setTextSelection does not display the context menu even when options is set to MenuPolicy.SHOW.
*
If the selected text contains an emoji,
* the emoji is selected when its start position is within the text selection range.
*
NOTE:
*
When only the placeholder attribute is set, the text selection handle is still available.
*
The caret stays at the beginning of the placeholder text when the handle is released.
*
NOTE:
*
You are advised to bind the state variable to the text in real time through the onChange event,
* so as to prevent display errors when the component is updated.
*
NOTE:
*
To set vertical alignment for the text, use the align attribute.
*
The align attribute alone does not control the horizontal position of the text.
*
In other words, Alignment.TopStart, Alignment.Top, and Alignment.TopEnd produce the same effect,
* top-aligning the text; Alignment.Start, Alignment.Center, and Alignment.End produce the same effect,
* centered-aligning the text vertically; Alignment.BottomStart, Alignment.Bottom,
* and Alignment.BottomEnd produce the same effect, bottom-aligning the text.
*
When textAlign is set to TextAlign.JUSTIFY, the text in the last line is horizontally aligned with the start edge.
*
Since API version 11, textAlign can be set to TextAlign.JUSTIFY.
*
NOTE:
*
Since API version 12, this API can be used to set the text handle color, which is the same as the caret color.
*
NOTE:
*
If the value is too large, the text may be clipped depending on the font.
*
For the number type, the value range is [100, 900], at an interval of 100. The default value is 400.
*
A larger value indicates a heavier font weight.
*
For the string type, only strings that represent a number, for example, "400",
* and the following enumerated values of FontWeight are supported: "bold", "bolder", "lighter", "regular", and "medium".
*
NOTE:
*
The 'HarmonyOS Sans' font and registered custom fonts are supported for applications.
*
Only the 'HarmonyOS Sans' font is supported for widgets.
*
NOTE:
*
In inline style, the effect of truncating text according to maxLines only applies when textOverflow is set.
*
Text is clipped at the transition between words.
*
To clip text in the middle of a word, set wordBreak to WordBreak.BREAK_ALL.
*
If overflow is set to TextOverflow.None, TextOverflow.Clip, or TextOverflow.Ellipsis,
* this attribute must be used with maxLines for the settings to take effect.
*
TextOverflow.None produces the same effect as TextOverflow.Clip.
*
NOTE:
*
Only inputs that comply with the regular expression can be displayed.
*
Other inputs are filtered out.
*
The specified regular expression can match single characters, but not strings.
*
NOTE:
*
In this callback, if cursor operations are performed,
* you need to adjust the cursor logic based on the previewText parameter
* to make sure it works seamlessly under the preview display scenario.
*
NOTE:
*
If this attribute is set to CopyOptions.None, the text can only be pasted;
* all other actions, such as copying, cutting, and sharing, are disabled.
*
Dragging is not allowed when CopyOptions.None is set.
*
NOTE:
*
By default, there is no maximum number of characters.
*
When the maximum number of characters is reached,
* no more characters can be entered, and the border turns red.
*
NOTE:
*
options can be set only when value is set to true,
* in which case a character counter is displayed below the text box.
*
This attribute must be used together with maxlength.
*
The character counter is displayed in this format: Number of characters entered/Character limit.
*
It is visible when the number of characters entered is greater than
* the character limit multiplied by the threshold percentage value.
*
If options is not set, the text box border and character counter subscript turn red
* when the number of characters entered reaches the limit.
*
If value is set to true and options is set,
* the text box border and character counter subscript turn red
* and the text box shakes when the number of characters entered reaches the limit,
* provided that the value of thresholdPercentage is valid.
*
If highlightBorder is set to false, the text box border does not turn red.
*
By default, highlightBorder is set to true.
*
The character counter is not displayed for text boxes in inline input style.
*
NOTE:
*
The inline input style is only available for the TextAreaType.Normal type.
*
NOTE:
*
true:
*
The system text selection menu does not appear under the following circumstances: clicking the text box cursor,
* long-pressing the text box, double-tapping the text box, triple-tapping the text box, or right-clicking the text box.
*
false:
*
The system text selection menu appears under the following circumstances: clicking the text box cursor,
* long-pressing the text box, double-tapping the text box, triple-tapping the text box, or right-clicking the text box.
*
NOTE:
*
For the string type, numeric string values with optional units, for example, "10" or "10fp", are supported.
*
For the setting to take effect, this attribute must be used together with maxFontSize and maxLines,or layout constraint settings.
*
When the adaptive font size is used, the fontSize settings do not take effect.
*
NOTE:
*
For the string type, numeric string values with optional units, for example, "10" or "10fp", are supported.
*
For the setting to take effect, this attribute must be used together with minFontSize and maxLines, or layout constraint settings.
*
When the adaptive font size is used, the fontSize settings do not take effect.
*
NOTE:
*
The undefined type is supported.
*
A value less than 0 is handled as 0.
*
A value greater than 1 is handled as 1.
*
Abnormal values are ineffective by default.
*
NOTE:
*
The undefined type is supported.
*
A value less than 0 is handled as 0.
*
A value greater than 1 is handled as 1.
*
Abnormal values are ineffective by default.
*
NOTE:
*
A value less than 1 is handled as 1.
*
Abnormal values are ineffective by default.
*
NOTE:
*
A value less than 1 is handled as 1.
*
Abnormal values are ineffective by default.
*
NOTE: *
NOTE:
*
Sets the maximum number of lines that can be displayed.
*
When textOverflow is set, text is truncated if the content exceeds this limit.
*
When textOverflow is not set, in inline style,
* the text is scrollable if the content exceeds the limit while the text box is focused;
* maxLines does not apply when the text box is not focused.
*
In non-inline style, the text is truncated according to the number of lines.
*
Default value: 3 with the inline style; +∞ with the non-inline style,
* indicating that there is no maximum number of lines.
*
NOTE:
*
This attribute does not take effect for the placeholder text.
*
The component does not support the clip attribute.
*
Therefore, setting this attribute does not affect text clipping.
*
NOTE:
*
This attribute takes effect when wordBreak is not set to breakAll. Hyphens are not supported.
*
NOTE:
*
When a custom keyboard is set, activating the text box opens the specified custom component,
* instead of the system input method.
*
The custom keyboard's height can be set through the height attribute of the custom component's root node,
* and its width is fixed at the default value.
*
The custom keyboard is presented by overlaying the original screen,
* which is not compressed or lifted if avoid mode is not enabled or avoidance is not needed for the text box.
*
The custom keyboard cannot obtain the focus, but it blocks gesture events.
*
By default, the custom keyboard is closed when the input component loses the focus.
*
You can also use the TextAreaController.stopEditing API to close the keyboard.
*
When a custom keyboard is set, the text box does not support camera input, even when the device supports.
*
When setting a custom keyboard, you can bind the onKeyPrelme event to prevent input from the physical keyboard.
*
NOTE:
*
If the value specified is a percentage or 0, the default value is used.
*
For the string type, numeric string values with optional units, for example, "10" or "10fp", are supported.
*
If the value specified is a negative value, the text is compressed.
*
A negative value too small may result in the text being compressed to 0 and no content being displayed.
*
NOTE:
*
If the value specified is less than or equal to 0, the default value 0 is used.
*
NOTE:
*
If the value is less than or equal to 0, the line height is not limited and the font size is adaptive.
*
If the value is of the number type, the unit fp is used.
*
NOTE:
*
It returns true if the text is inserted; returns false otherwise.
*
This callback is not triggered for pre-edit or candidate word operations.
*
It is available only for system input methods.
*
NOTE:
*
It is available only for system input methods.
*
NOTE:
*
It returns true if the text is deleted; returns false otherwise.
*
This callback is not called for text preview.
*
It is available only for system input methods.
*
NOTE:
*
It is available only for system input methods.
*
NOTE:
*
Preview text is in a temporary state and does not support text interception.
*
As such, it does not trigger onWillInsert, onDidInsert, onWillDelete, or onDidDelete callbacks.
*
NOTE:
*
To enable haptic feedback,
*
you must declare the ohos.permission.VIBRATE permission under requestPermissions in the module.json5 file of the project.
*
* "requestPermissions": [
* {
* "name": "ohos.permission.VIBRATE",
* }
* ]
*
*
NOTE:
*
For the settings to work, overflow must be set to TextOverflow.Ellipsis and maxLines must be specified.
*
Setting ellipsisMode alone does not take effect.
*
EllipsisMode.START and EllipsisMode.CENTER take effect only when maxLines is set to 1.
*
NOTE:
*
This callback is triggered after onWillInsert and onWillDelete, but before onDidInsert and onDidDelete.
*