From 786b03c3d47160b454cf5350473b8d7ae99c4f8f Mon Sep 17 00:00:00 2001 From: "@feng-yu4279" Date: Tue, 13 May 2025 16:06:13 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=BA=9F=E5=BC=83api=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- features/home/src/main/ets/view/CommentKeyboard.ets | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/home/src/main/ets/view/CommentKeyboard.ets b/features/home/src/main/ets/view/CommentKeyboard.ets index 16c3808..e8a3978 100644 --- a/features/home/src/main/ets/view/CommentKeyboard.ets +++ b/features/home/src/main/ets/view/CommentKeyboard.ets @@ -55,19 +55,19 @@ export struct CommentKeyboard { @Consume navDialogPageInfos: NavPathStack; aboutToAppear(): void { - window.getLastWindow(getContext(this)).then(win => { + window.getLastWindow(this.getUIContext().getHostContext()).then(win => { this.addKeyboardHeightListener(win); }); } aboutToDisappear(): void { - window.getLastWindow(getContext(this)).then(win => { + window.getLastWindow(this.getUIContext().getHostContext()).then(win => { this.removeKeyboardHeightListener(win); }); } getResourceString(resource: Resource): string { - return getContext(this).resourceManager.getStringSync(resource.id); + return this.getUIContext().getHostContext()!.resourceManager.getStringSync(resource.id); } addKeyboardHeightListener(win: window.Window) { @@ -354,7 +354,7 @@ export struct CommentKeyboard { .height( this.isEmojiKeyboardVisible ? this.keyboardHeight + this.frequentEmojiListHeight : - this.keyboardHeight + this.keyboardHeight ) } .backgroundColor(Color.White) -- Gitee From 8a6247f56c5c00a6bfd5e8f263bc25745d973a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=AF=E8=82=B2?= Date: Wed, 14 May 2025 07:27:27 +0000 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"=E5=BA=9F=E5=BC=83api=E6=9B=B4?= =?UTF-8?q?=E6=96=B0"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 786b03c3d47160b454cf5350473b8d7ae99c4f8f. --- features/home/src/main/ets/view/CommentKeyboard.ets | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/features/home/src/main/ets/view/CommentKeyboard.ets b/features/home/src/main/ets/view/CommentKeyboard.ets index e8a3978..16c3808 100644 --- a/features/home/src/main/ets/view/CommentKeyboard.ets +++ b/features/home/src/main/ets/view/CommentKeyboard.ets @@ -55,19 +55,19 @@ export struct CommentKeyboard { @Consume navDialogPageInfos: NavPathStack; aboutToAppear(): void { - window.getLastWindow(this.getUIContext().getHostContext()).then(win => { + window.getLastWindow(getContext(this)).then(win => { this.addKeyboardHeightListener(win); }); } aboutToDisappear(): void { - window.getLastWindow(this.getUIContext().getHostContext()).then(win => { + window.getLastWindow(getContext(this)).then(win => { this.removeKeyboardHeightListener(win); }); } getResourceString(resource: Resource): string { - return this.getUIContext().getHostContext()!.resourceManager.getStringSync(resource.id); + return getContext(this).resourceManager.getStringSync(resource.id); } addKeyboardHeightListener(win: window.Window) { @@ -354,7 +354,7 @@ export struct CommentKeyboard { .height( this.isEmojiKeyboardVisible ? this.keyboardHeight + this.frequentEmojiListHeight : - this.keyboardHeight + this.keyboardHeight ) } .backgroundColor(Color.White) -- Gitee From 7952245e3e51b4d20a2df763013518c8eb47abe1 Mon Sep 17 00:00:00 2001 From: "@feng-yu4279" Date: Wed, 14 May 2025 17:18:00 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/ets/view/CommentKeyboard.ets | 37 +++++++++++++++++++ .../src/main/ets/view/CommentSendDialog.ets | 2 + features/home/src/main/ets/view/Home.ets | 5 ++- .../src/main/ets/view/NavigationDialog.ets | 5 ++- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/features/home/src/main/ets/view/CommentKeyboard.ets b/features/home/src/main/ets/view/CommentKeyboard.ets index 16c3808..209a4a2 100644 --- a/features/home/src/main/ets/view/CommentKeyboard.ets +++ b/features/home/src/main/ets/view/CommentKeyboard.ets @@ -33,12 +33,14 @@ interface ImageInfo { resource: ResourceStr } +// [Start rich_editor_span] export interface RichEditorSpan { value?: string resourceValue?: ResourceStr type: 'text' | 'image' | 'builder' data?: User | ImageInfo } +// [End rich_editor_span] @Component export struct CommentKeyboard { @@ -48,12 +50,14 @@ export struct CommentKeyboard { { id: '0', avatar: $r('app.media.friend_1'), nickname: this.getResourceString($r('app.string.friend_nickname_1')) }, { id: '1', avatar: $r('app.media.friend_2'), nickname: this.getResourceString($r('app.string.friend_nickname_2')) }, ]; + // [StartExclude comment_keyboard] private builderSpans: RichEditorSpan[] = []; @State keyboardHeight: number = 0; @State isEmojiKeyboardVisible: boolean = false; @State isAtFriendListVisible: boolean = false; @Consume navDialogPageInfos: NavPathStack; + // [Start comment_keyboard1] aboutToAppear(): void { window.getLastWindow(getContext(this)).then(win => { this.addKeyboardHeightListener(win); @@ -77,18 +81,21 @@ export struct CommentKeyboard { this.keyboardHeight = px2vp(height); return; } + // [StartExclude close_keyboard] // if close keyboard, don't set keyboardHeight, avoid EmojiKeyboard height is 0 if (!this.isEmojiKeyboardVisible) { // handle keyboard close button click console.info('click soft keyboard close button'); this.navDialogPageInfos.pop(); } + // [EndExclude close_keyboard] }); } removeKeyboardHeightListener(win: window.Window) { win.off('keyboardHeightChange'); } + // [End comment_keyboard1] getOperateButtons(): OperateButton[] { return [ @@ -102,11 +109,13 @@ export struct CommentKeyboard { ]; } + // [Start comment_keyboard2] onAtButtonClick: (event?: ClickEvent) => void = event => { const controller = this.richEditorController; this.isAtFriendListVisible = true; controller.addTextSpan('@', { offset: controller.getCaretOffset() }); } + // [End comment_keyboard2] onEmojiButtonClick: (event: ClickEvent) => void = event => { this.isEmojiKeyboardVisible = !this.isEmojiKeyboardVisible; @@ -116,14 +125,19 @@ export struct CommentKeyboard { this.isEmojiKeyboardVisible = false; } + // [Start comment_keyboard3] onEmojiClick: (icon: Resource) => void = icon => { this.richEditorController.addImageSpan(icon, { offset: this.richEditorController.getCaretOffset(), imageStyle: { size: [20, 20] } }); + // [StartExclude onEmoji_click] this.isAtFriendListVisible = false; + // [EndExclude onEmoji_click] } + // [End comment_keyboard3] + // [Start comment_keyboard4] onSendComment: () => void = () => { let builderSpanIndex = 0; let richEditorSpan: RichEditorSpan; @@ -141,11 +155,17 @@ export struct CommentKeyboard { } richEditorSpans.push(richEditorSpan); }); + // [StartExclude rich_editor_content] console.info('richEditorContent', JSON.stringify(richEditorSpans)); this.navDialogPageInfos.pop(); this.navDialogPageInfos.pushPathByName('CommentSendDialog', richEditorSpans); + // [EndExclude rich_editor_content] } + // [End comment_keyboard4] + // [Start comment_keyboard5] + // features/home/src/main/ets/view/CommentKeyboard.ets + // [Start comment_keyboard6] onAtFriendClick: (friend: User) => void = friend => { const controller = this.richEditorController; const offset = controller.getCaretOffset(); @@ -159,13 +179,17 @@ export struct CommentKeyboard { }); this.setBuilderSpans(controller, friend); } + // [End comment_keyboard6] @Builder AtSpan(nickname: string) { Text(`@${nickname}`) .fontColor(0xFF133667) } + // [End comment_keyboard5] + // [EndExclude comment_keyboard] + // [Start comment_keyboard7] setBuilderSpans(controller: RichEditorController, friend: User) { const builderSpan: RichEditorSpan = { value: `@${friend.nickname}`, @@ -182,7 +206,9 @@ export struct CommentKeyboard { return this.isBuilderSpan(span) ? count + 1 : count; }, 0); } + // [End comment_keyboard7] + // [Start comment_keyboard8] aboutToDelete: (value: RichEditorDeleteValue) => boolean = value => { const controller = this.richEditorController; const span = value.richEditorDeleteSpans[0]; @@ -196,6 +222,7 @@ export struct CommentKeyboard { } return true; } + // [End comment_keyboard8] deleteBuilderSpan() { const controller = this.richEditorController; @@ -252,8 +279,10 @@ export struct CommentKeyboard { @Builder ToolBar() { Column() { + // [Start comment_keyboard9] RichEditor({ controller: this.richEditorController }) .customKeyboard(this.isEmojiKeyboardVisible ? this.EmojiKeyboard() : undefined) + // [StartExclude constraint_size] .constraintSize({ maxHeight: 120 }) .placeholder($r('app.string.comment_button_text')) .defaultFocus(true) @@ -262,6 +291,8 @@ export struct CommentKeyboard { .onDeleteComplete(this.onDeleteComplete) .onIMEInputComplete(this.onIMEInputComplete) .aboutToIMEInput(this.aboutToIMEInput) + // [EndExclude constraint_size] + // [End comment_keyboard9] Row({ space: 15 }) { ForEach(this.getOperateButtons(), (operateButton: OperateButton) => { Image(operateButton.icon) @@ -278,6 +309,7 @@ export struct CommentKeyboard { .borderRadius(20) } + // [Start comment_keyboard10] @Builder EmojiKeyboard() { Grid() { @@ -291,11 +323,14 @@ export struct CommentKeyboard { } .width('100%') .height(this.keyboardHeight + this.frequentEmojiListHeight) + // [StartExclude columns_template] .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr') .rowsGap(15) .padding(10) .scrollBar(BarState.Off) + // [EndExclude columns_template] } + // [End comment_keyboard10] @Builder FrequentEmojiList() { @@ -341,6 +376,7 @@ export struct CommentKeyboard { .align(Alignment.Start) } + // [Start comment_keyboard11] build() { NavigationDialog({ maskBackgroundColor: 'rgba(0, 0, 0, 0.1)' }) { Column() { @@ -360,4 +396,5 @@ export struct CommentKeyboard { .backgroundColor(Color.White) } } + // [End comment_keyboard11] } \ No newline at end of file diff --git a/features/home/src/main/ets/view/CommentSendDialog.ets b/features/home/src/main/ets/view/CommentSendDialog.ets index 3ed6aed..ecbe9c7 100644 --- a/features/home/src/main/ets/view/CommentSendDialog.ets +++ b/features/home/src/main/ets/view/CommentSendDialog.ets @@ -29,6 +29,7 @@ export struct CommentSendDialog { maskBackgroundColor: 'rgba(0, 0, 0, 0.3)', alignContent: Alignment.Center }) { + // [Start comment_send_dialog] Column() { Text($r('app.string.send_title')) .margin({ bottom: 20 }) @@ -50,6 +51,7 @@ export struct CommentSendDialog { }, (richEditorSpan: RichEditorSpan) => JSON.stringify(richEditorSpan)) } } + // [End comment_send_dialog] .backgroundColor(Color.White) .padding(24) .width('90%') diff --git a/features/home/src/main/ets/view/Home.ets b/features/home/src/main/ets/view/Home.ets index 2ff181e..2c7a5c6 100644 --- a/features/home/src/main/ets/view/Home.ets +++ b/features/home/src/main/ets/view/Home.ets @@ -84,9 +84,10 @@ export struct Home { onSelectedTabChange(index: number) { this.selectedTabIndex = index } - + // [Start home] build() { Navigation(this.navDialogPageInfos) { + // [StartExclude home] Tabs({ barPosition: BarPosition.End }) { ForEach(this.tabBars, (tabBar: TabBar, index) => { TabContent() { @@ -108,9 +109,11 @@ export struct Home { .onChange((index: number) => { this.onSelectedTabChange(index) }) + // [EndExclude home] } .hideTitleBar(true) .mode(NavigationMode.Stack) .navDestination(this.NavDialogPageMap) } + // [End home] } \ No newline at end of file diff --git a/features/home/src/main/ets/view/NavigationDialog.ets b/features/home/src/main/ets/view/NavigationDialog.ets index ebbfb4a..1d5502f 100644 --- a/features/home/src/main/ets/view/NavigationDialog.ets +++ b/features/home/src/main/ets/view/NavigationDialog.ets @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +// [Start navigation_dialog] @Component export struct NavigationDialog { @Consume navDialogPageInfos: NavPathStack; @@ -46,4 +46,5 @@ export struct NavigationDialog { .hideTitleBar(true) .expandSafeArea([SafeAreaType.KEYBOARD]) } -} \ No newline at end of file +} +// [End navigation_dialog] \ No newline at end of file -- Gitee