diff --git a/entry/src/main/ets/model/KeyboardController.ets b/entry/src/main/ets/model/KeyboardController.ets index 806388556c1a6c8435080234f3db3cfc206b0a78..c4268c9674d0754d2517296d62385b1e13d0b3f2 100644 --- a/entry/src/main/ets/model/KeyboardController.ets +++ b/entry/src/main/ets/model/KeyboardController.ets @@ -25,14 +25,18 @@ export class KeyboardController { keyBoardType: string = Constants.NUMBER_KEYBOARD; isUpperCase: boolean = false; + // [Start onInput_start] onInput(value: string | Resource): string { + // [StartExclude onInput_start] if (typeof value === 'string') { this.text = this.text.substring(0, this.leftCaretPos) + value + this.text.substring(this.rightCaretPos); this.targetCaretPos = this.leftCaretPos + value.length; return this.text; } + // [EndExclude onInput_start] switch (value.id) { + // [StartExclude onInput_start] case $r('app.string.keyboardButton_delete').id: if (this.rightCaretPos === this.leftCaretPos && this.leftCaretPos > 0) { this.leftCaretPos--; @@ -44,9 +48,11 @@ export class KeyboardController { this.text = ''; this.targetCaretPos = 0; break; + // [EndExclude onInput_start] case $r('app.string.keyboardButton_finish').id: this.textInputController?.stopEditing(); break; + // [StartExclude onInput_start] case $r('app.string.tabButton_english_text').id: this.keyBoardType = Constants.ENGLISH_KEYBOARD; break; @@ -61,21 +67,25 @@ export class KeyboardController { case $r('app.media.arrowshape_up_fill').id: this.isUpperCase = !this.isUpperCase; break; + // [EndExclude onInput_start] } return this.text; } + // [End onInput_start] onPaste(value: string) { this.text = this.text.substring(0, this.leftCaretPos) + value + this.text.substring(this.rightCaretPos); this.targetCaretPos = this.leftCaretPos + value.length; } + // [Start textInputController_start] onChange(value: string) { this.text = value; if (this.keyBoardType !== Constants.SYSTEM_KEYBOARD) { this.textInputController?.caretPosition(this.targetCaretPos); } } + // [End textInputController_start] setCaretPosition(start: number, end: number) { this.leftCaretPos = start; @@ -87,6 +97,7 @@ export class KeyboardController { this.targetCaretPos = this.leftCaretPos; } + // [Start changeAvoidHeight_start] changeAvoidHeight(value: number) { let event: emitter.InnerEvent = { eventId: Constants.AVOID_EVENT_ID @@ -98,4 +109,5 @@ export class KeyboardController { }; emitter.emit(event, eventData); } + // [End changeAvoidHeight_start] } \ No newline at end of file diff --git a/entry/src/main/ets/pages/MainPage.ets b/entry/src/main/ets/pages/MainPage.ets index 2d37216d3e495ba502aa6f4d3ce87ea66d88db44..b493c50e3baa1251cd56dbcf5521cbdfd149e37a 100644 --- a/entry/src/main/ets/pages/MainPage.ets +++ b/entry/src/main/ets/pages/MainPage.ets @@ -17,6 +17,7 @@ import { emitter } from '@kit.BasicServicesKit'; import { Constants } from '../constants/Constants'; import { TextInputComponent } from '../view/TextInputComponent'; +// [Start MainPage_start] @Entry @Component struct MainPage { @@ -41,6 +42,7 @@ struct MainPage { build() { Navigation() { Column() { + // [StartExclude MainPage_start] Image($r('app.media.arkui_background')) .height($r('app.float.main_page_image_height')) .width('100%') @@ -48,14 +50,18 @@ struct MainPage { .padding({ left: $r('app.float.main_page_margin'), right: $r('app.float.main_page_margin') }) TextInputComponent() + // [EndExclude MainPage_start] } + .padding({ bottom: this.bottomPadding }) + // [StartExclude MainPage_start] .height('100%') .justifyContent(FlexAlign.End) - .padding({ bottom: this.bottomPadding }) .expandSafeArea([SafeAreaType.KEYBOARD, SafeAreaType.SYSTEM]) + // [EndExclude MainPage_start] } .mode(NavigationMode.Stack) .titleMode(NavigationTitleMode.Full) .title($r('app.string.main_page_title')) } -} \ No newline at end of file +} +// [End MainPage_start] \ No newline at end of file diff --git a/entry/src/main/ets/view/CustomKeyboard.ets b/entry/src/main/ets/view/CustomKeyboard.ets index 531c8b9cae93532eb334c0bbeef15bd58582bc6d..db0d18ea9b3d7109c9da24c700c02acfa5f7895a 100644 --- a/entry/src/main/ets/view/CustomKeyboard.ets +++ b/entry/src/main/ets/view/CustomKeyboard.ets @@ -18,17 +18,24 @@ import { KeyboardController } from '../model/KeyboardController'; import { EnglishKeyboard } from './EnglishKeyboard'; import { NumberKeyboard } from './NumberKeyboard'; +// [Start CustomKeyboard_start] +// [Start avoidHeight_start] @Component export struct CustomKeyboard { + // [StartExclude avoidHeight_start] + // [StartExclude CustomKeyboard_start] @Consume isCustomKeyboardAttach: boolean; @Consume inputText: string; @Consume keyBoardController: KeyboardController; @Consume systemKeyboardHeight: number; @Consume customKeyboardHeight: number; @Consume bottomRectHeight: number; - + // [EndExclude avoidHeight_start] + // [EndExclude CustomKeyboard_start] build() { Column() { + // [StartExclude avoidHeight_start] + // [StartExclude CustomKeyboard_start] NumberKeyboard() .visibility(this.keyBoardController.keyBoardType === Constants.NUMBER_KEYBOARD ? Visibility.Visible : Visibility.None) @@ -38,17 +45,27 @@ export struct CustomKeyboard { .visibility(this.keyBoardController.keyBoardType === Constants.ENGLISH_KEYBOARD ? Visibility.Visible : Visibility.None) .margin({ top: $r('app.float.keyboard_margin_top') }) + // [EndExclude CustomKeyboard_start] + // [EndExclude avoidHeight_start] } + // [StartExclude CustomKeyboard_start] .onAreaChange((oldValue: Area, newValue: Area) => { this.customKeyboardHeight = Number(newValue.height); let avoidHeight: number = (this.isCustomKeyboardAttach ? this.customKeyboardHeight : this.systemKeyboardHeight) - this.bottomRectHeight; this.keyBoardController.changeAvoidHeight(avoidHeight); }) + // [StartExclude avoidHeight_start] .padding({ left: $r('app.float.keyboard_padding'), right: $r('app.float.keyboard_padding') }) + // [EndExclude CustomKeyboard_start] .height($r('app.float.keyboard_total_height')) + // [StartExclude CustomKeyboard_start] .width('100%') .backgroundColor($r('app.color.keyboard_background_color')) + // [EndExclude CustomKeyboard_start] + // [EndExclude avoidHeight_start] } } +// [End CustomKeyboard_start] +// [End avoidHeight_start] diff --git a/entry/src/main/ets/view/EnglishKeyboard.ets b/entry/src/main/ets/view/EnglishKeyboard.ets index f2bc1d4109d07aa57c397ddec0d9f89dc3d9df64..69c864a98145186b675b6f4c866c0533be262243 100644 --- a/entry/src/main/ets/view/EnglishKeyboard.ets +++ b/entry/src/main/ets/view/EnglishKeyboard.ets @@ -61,10 +61,12 @@ export struct EnglishKeyboard { } } +// [Start EnglishButton_start] @Component struct EnglishButton { - @Prop item: Menu; @Consume inputText: string; + // [StartExclude EnglishButton_start] + @Prop item: Menu; @Consume keyBoardController: KeyboardController; getEnglishText(item: Menu): string | Resource { @@ -74,9 +76,12 @@ struct EnglishButton { return item.text; } } + // [EndExclude EnglishButton_start] build() { - Button({ type: ButtonType.Normal }) { + Button({ type: ButtonType.Normal }) + // [StartExclude EnglishButton_start] + { if (typeof this.getEnglishText(this.item) === 'string' || (this.getEnglishText(this.item) as Resource).type !== Constants.RESOURCE_TYPE_MEDIA) { Text(this.getEnglishText(this.item)) @@ -93,8 +98,10 @@ struct EnglishButton { .padding(0) .width(this.item.width) .height(this.item.height) + // [EndExclude EnglishButton_start] .onClick(() => { this.inputText = this.keyBoardController.onInput(this.getEnglishText(this.item)); }) } -} \ No newline at end of file +} +// [End EnglishButton_start] \ No newline at end of file diff --git a/entry/src/main/ets/view/NumberKeyboard.ets b/entry/src/main/ets/view/NumberKeyboard.ets index 56e8ebf6923eaef86d65da6ea11b9d5cf5f2bca7..f11ee3b28dc2e16aa226658960be8b995aa060b6 100644 --- a/entry/src/main/ets/view/NumberKeyboard.ets +++ b/entry/src/main/ets/view/NumberKeyboard.ets @@ -17,6 +17,7 @@ import { Menu, numberKeyboardData } from '../viewmodel/MenuModel'; import { KeyboardController } from '../model/KeyboardController'; import { Constants } from '../constants/Constants'; +// [Start NumberKeyboard_start] @Component export struct NumberKeyboard { @Consume inputText: string; @@ -54,4 +55,5 @@ export struct NumberKeyboard { .rowsGap($r('app.float.number_keyboard_grid_gap')) .columnsGap($r('app.float.number_keyboard_grid_gap')) } -} \ No newline at end of file +} +// [End NumberKeyboard_start] \ No newline at end of file diff --git a/entry/src/main/ets/view/TextInputComponent.ets b/entry/src/main/ets/view/TextInputComponent.ets index 80a1f857155b414535914991787c1305cd2fb37c..973e0fa752b10f1cd643e15366fb4e79a43fde40 100644 --- a/entry/src/main/ets/view/TextInputComponent.ets +++ b/entry/src/main/ets/view/TextInputComponent.ets @@ -18,12 +18,14 @@ import { KeyboardController } from '../model/KeyboardController'; import { CustomKeyboard } from './CustomKeyboard'; import { TabView } from './TabView'; +// [Start TextInputComponent_start] @Component export struct TextInputComponent { + @Provide inputText: string = ''; + // [StartExclude TextInputComponent_start] @Provide keyBoardController: KeyboardController = new KeyboardController(); @Provide isCustomKeyboardAttach: boolean = true; @Provide isTabViewShow: boolean = false; - @Provide inputText: string = ''; @Provide systemKeyboardHeight: number = 0; @Provide customKeyboardHeight: number = 0; @Provide bottomRectHeight: number = 0; @@ -45,23 +47,36 @@ export struct TextInputComponent { }) }) } - + // [EndExclude TextInputComponent_start] + // [Start customKeyboard_start] build() { Column() { + // [Start TextInput_start] + // [Start switchover_start] TextInput({ placeholder: $r('app.string.textInput_placeholder_custom'), text: this.inputText, controller: this.textInputController }) + // [StartExclude TextInput_start] + // [StartExclude TextInputComponent_start] + // [StartExclude customKeyboard_start] + // [StartExclude switchover_start] .margin({ top: $r('app.float.main_page_margin_top'), left: $r('app.float.main_page_margin'), right: $r('app.float.main_page_margin') }) + // [EndExclude switchover_start] + // [EndExclude customKeyboard_start] .customKeyboard(this.isCustomKeyboardAttach ? this.customKeyboard() : null) + // [End switchover_start] + // [StartExclude customKeyboard_start] + // [EndExclude TextInput_start] .onTextSelectionChange((start: number, end: number) => { this.keyBoardController.setCaretPosition(start, end); }) + // [StartExclude TextInput_start] .onBlur(() => { this.isTabViewShow = false; this.keyBoardController.changeAvoidHeight(0); @@ -82,11 +97,17 @@ export struct TextInputComponent { .height($r('app.float.main_page_textInput_height')) TabView() .visibility(this.isTabViewShow ? Visibility.Visible : Visibility.Hidden) + // [EndExclude customKeyboard_start] + // [EndExclude TextInputComponent_start] } } - + // [StartExclude TextInputComponent_start] @Builder customKeyboard() { CustomKeyboard() } -} \ No newline at end of file + // [EndExclude TextInputComponent_start] +} +// [EndExclude TextInput_start] +// [End TextInput_start] +// [End customKeyboard_start] \ No newline at end of file