From c1ea426e4613dcfe15811303e80c7b56c3a9a928 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 01:56:46 +0000 Subject: [PATCH 01/13] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20atomicservicesearch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atomicservicesearch/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 atomicservicesearch/.keep diff --git a/atomicservicesearch/.keep b/atomicservicesearch/.keep new file mode 100644 index 0000000..e69de29 -- Gitee From babf0da616bb5ee0df33b314befa9902a72333f5 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 01:57:01 +0000 Subject: [PATCH 02/13] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20interfaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atomicservicesearch/interfaces/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 atomicservicesearch/interfaces/.keep diff --git a/atomicservicesearch/interfaces/.keep b/atomicservicesearch/interfaces/.keep new file mode 100644 index 0000000..e69de29 -- Gitee From fcfdb5420569584555aad88e2977b55e98801c9e Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 01:57:15 +0000 Subject: [PATCH 03/13] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20source?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atomicservicesearch/source/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 atomicservicesearch/source/.keep diff --git a/atomicservicesearch/source/.keep b/atomicservicesearch/source/.keep new file mode 100644 index 0000000..e69de29 -- Gitee From 0cd6e57596cceee5e80416f2300c0562d5aed238 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 01:58:05 +0000 Subject: [PATCH 04/13] add atomicservicesearch/interfaces/atomicservicesearch.js. Signed-off-by: jiyu --- .../interfaces/atomicservicesearch.js | 378 ++++++++++++++++++ 1 file changed, 378 insertions(+) create mode 100644 atomicservicesearch/interfaces/atomicservicesearch.js diff --git a/atomicservicesearch/interfaces/atomicservicesearch.js b/atomicservicesearch/interfaces/atomicservicesearch.js new file mode 100644 index 0000000..13301ec --- /dev/null +++ b/atomicservicesearch/interfaces/atomicservicesearch.js @@ -0,0 +1,378 @@ +​/* + * Copyright (c) 2025 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. + */ + +if (!("finalizeConstruction" in ViewPU.prototype)) { + Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { }); +} + +const OperationType = requireNapi('arkui.advanced.SubHeader') +const TEXT_SIZE_BODY1 = { "id": -1, "type": -1, params: [`sys.float.ohos_id_text_size_body1`], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; +const TEXT_COLOR_SECONDARY = { "id": -1, "type": -1, params: [`sys.color.ohos_id_color_text_secondary`], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; +const ICON_COLOR_SECONDARY = { "id": -1, "type": 10001, params: ['sys.color.ohos_id_color_secondary'], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; +const TEXT_BOX_COLOR = { "id": -1, "type": -1, params: [`sys.color.ohos_id_color_text_field_sub_bg`], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; +const TEXT_COLOR_PRIMARY = { "id": -1, "type": -1, params: [`sys.color.ohos_id_color_text_primary`], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; +const FUNCTION_ICON_COLOR = { "id": -1, "type": -1, params: [`sys.color.ohos_id_color_primary`], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; +const EFFECT_COLOR = { "id": -1, "type": -1, params: [`sys.color.ohos_id_color_click_effect`], "bundleName": "__harDefaultBundleName__", "moduleName": "__harDefaultModuleName__" }; + +export class AtomicServiceSearch extends ViewPU { + constructor(parent, params, __localStorage, elmtId = -1, paramsLambda = undefined, extraInfo) { + super(parent, __localStorage, elmtId, extraInfo); + if (typeof paramsLambda === "function") { + this.paramsGenerator_ = paramsLambda; + } + this.__isFunction1Pressed = new ObservedPropertySimplePU(false, this, "isFunction1Pressed"); + this.__isFunction2Pressed = new ObservedPropertySimplePU(false, this, "isFunction2Pressed"); + this.__isSearchPressed = new ObservedPropertySimplePU(false, this, "isSearchPressed"); + this.__changeValue = new ObservedPropertySimplePU('', this, "changeValue"); + this.__showImage = new ObservedPropertySimplePU(true, this, "showImage"); + this.__hint = new SynchedPropertyObjectOneWayPU(params.hint, this, "hint"); + this.select = undefined; + this.operationType = OperationType.BUTTON; + this.operationItem = undefined; + this.onSearch = undefined; + this.controller = new SearchController(); + this.setInitiallyProvidedValue(params); + this.declareWatch("changeValue", this.onParamsChange); + this.finalizeConstruction(); + } + setInitiallyProvidedValue(params) { + if (params.isFunction1Pressed !== undefined) { + this.isFunction1Pressed = params.isFunction1Pressed; + } + if (params.isFunction2Pressed !== undefined) { + this.isFunction2Pressed = params.isFunction2Pressed; + } + if (params.isSearchPressed !== undefined) { + this.isSearchPressed = params.isSearchPressed; + } + if (params.changeValue !== undefined) { + this.changeValue = params.changeValue; + } + if (params.showImage !== undefined) { + this.showImage = params.showImage; + } + if (params.hint === undefined) { + this.__hint.set('Search'); + } + if (params.select !== undefined) { + this.select = params.select; + } + if (params.operationType !== undefined) { + this.operationType = params.operationType; + } + if (params.operationItem !== undefined) { + this.operationItem = params.operationItem; + } + if (params.onSearch !== undefined) { + this.onSearch = params.onSearch; + } + if (params.controller !== undefined) { + this.controller = params.controller; + } + } + updateStateVars(params) { + this.__hint.reset(params.hint); + } + purgeVariableDependenciesOnElmtId(rmElmtId) { + this.__isFunction1Pressed.purgeDependencyOnElmtId(rmElmtId); + this.__isFunction2Pressed.purgeDependencyOnElmtId(rmElmtId); + this.__isSearchPressed.purgeDependencyOnElmtId(rmElmtId); + this.__changeValue.purgeDependencyOnElmtId(rmElmtId); + this.__showImage.purgeDependencyOnElmtId(rmElmtId); + this.__hint.purgeDependencyOnElmtId(rmElmtId); + } + aboutToBeDeleted() { + this.__isFunction1Pressed.aboutToBeDeleted(); + this.__isFunction2Pressed.aboutToBeDeleted(); + this.__isSearchPressed.aboutToBeDeleted(); + this.__changeValue.aboutToBeDeleted(); + this.__showImage.aboutToBeDeleted(); + this.__hint.aboutToBeDeleted(); + SubscriberManager.Get().delete(this.id__()); + this.aboutToBeDeletedInternal(); + } + get isFunction1Pressed() { + return this.__isFunction1Pressed.get(); + } + set isFunction1Pressed(newValue) { + this.__isFunction1Pressed.set(newValue); + } + get isFunction2Pressed() { + return this.__isFunction2Pressed.get(); + } + set isFunction2Pressed(newValue) { + this.__isFunction2Pressed.set(newValue); + } + get isSearchPressed() { + return this.__isSearchPressed.get(); + } + set isSearchPressed(newValue) { + this.__isSearchPressed.set(newValue); + } + get changeValue() { + return this.__changeValue.get(); + } + set changeValue(newValue) { + this.__changeValue.set(newValue); + } + get showImage() { + return this.__showImage.get(); + } + set showImage(newValue) { + this.__showImage.set(newValue); + } + get hint() { + return this.__hint.get(); + } + set hint(newValue) { + this.__hint.set(newValue); + } + + aboutToAppear() { + if (this.operationType !== OperationType.BUTTON) { + this.operationItem = []; + } + } + + onParamsChange() { + this.showImage = this.changeValue.length === 0 ? true : false; + } + + renderSearch(parent = null) { + this.renderSelect.bind(this)(); + this.observeComponentCreation2((elmtId, isInitialRender) => { + Search.create({ value: this.changeValue, placeholder: this.hint, controller: this.controller }); + Search.backgroundColor(Color.Transparent); + Search.placeholderFont({ size: TEXT_SIZE_BODY1, weight: 400 }); + Search.textFont({ size: TEXT_SIZE_BODY1, weight: 400 }); + Search.fontColor(TEXT_COLOR_SECONDARY); + Search.searchIcon({ color: ICON_COLOR_SECONDARY }); + Search.onSubmit(this.onSearch?.onSubmit); + Search.onChange(this.onSearch?.onChange); + Search.onCopy(this.onSearch?.onCopy); + Search.onCut(this.onSearch?.onCut); + Search.onPaste(this.onSearch?.onPaste); + Search.onTextSelectionChange(this.onSearch?.onTextSelectionChange); + Search.onContentScroll(this.onSearch?.onContentScroll); + Search.onEditChange(this.onSearch?.onEditChange); + Search.onWillInsert(this.onSearch?.onWillInsert); + Search.onDidInsert(this.onSearch?.onDidInsert); + Search.onWillDelete(this.onSearch?.onWillDelete); + Search.onDidDelete(this.onSearch?.onDidDelete); + Search.onTouch((event) => { + if (event && event.type === TouchType.Down) { + this.isSearchPressed = true; + } + else if (event && event.type === TouchType.Up) { + this.isSearchPressed = false; + } + }); + }, Search); + Search.pop(); + } + + renderSelect(parent = null) { + this.observeComponentCreation2((elmtId, isInitialRender) => { + If.create(); + if (typeof this.select !== 'undefined' && this.select.options.length !== 0) { + this.ifElseBranchUpdateFunction(0, () => { + this.observeComponentCreation2((elmtId, isInitialRender) => { + Row.create(); + Row.flexShrink(0); + }, Row); + this.observeComponentCreation2((elmtId, isInitialRender) => { + Select.create(this.select?.options); + Select.value(this.select?.value); + Select.selected(this.select?.selected); + Select.onSelect(this.select?.onSelect); + Select.font({ size: TEXT_SIZE_BODY1, weight: 500 }); + Select.fontColor(TEXT_COLOR_PRIMARY); + Select.selectedOptionFont({ size: 16, weight: 400 }); + Select.menuAlign(MenuAlignType.START, { dx: 0, dy: 0 }); + Select.optionFont({ size: 16, weight: 400 }); + Select.backgroundColor(Color.Transparent); + Select.arrowPosition(ArrowPosition.END); + Select.constraintSize({ minHeight: 36 }); + Select.padding({ left: 6 }); + Select.margin({ left: 2 }); + Select.height(36); + Select.space(2); + }, Select); + Select.pop(); + this.renderDivider.bind(this)(); + Row.pop(); + }); + } + else { + this.ifElseBranchUpdateFunction(1, () => { + }); + } + }, If); + If.pop(); + } + + renderDivider(parent = null) { + this.observeComponentCreation2((elmtId, isInitialRender) => { + Divider.create(); + Divider.vertical(true); + Divider.height(20); + Divider.color(Color.Black); + Divider.opacity(0.6); + Divider.margin({ left: 2, right: -2 }); + }, Divider); + } + + renderFunction(item, independentOrNot, parent = null) { + this.observeComponentCreation2((elmtId, isInitialRender) => { + Row.create(); + Row.width(independentOrNot ? 40 : 36); + Row.height(independentOrNot ? 40 : 36); + Row.padding(0); + Row.flexShrink(0); + Row.borderRadius(20); + Row.onClick(item.action); + Row.alignItems(VerticalAlign.Center); + Row.justifyContent(FlexAlign.Center); + Row.margin(independentOrNot ? 0 : { left: 8, right: 2 }); + Row.backgroundColor(independentOrNot ? + (this.isFunction2Pressed ? EFFECT_COLOR : Color.Transparent) : + (this.isFunction1Pressed ? EFFECT_COLOR : Color.Transparent)); + Row.onTouch((event) => { + if (event && event.type === TouchType.Down) { + if (independentOrNot) { + this.isFunction2Pressed = true; + } + else { + this.isFunction1Pressed = true; + } + } + else if (event && event.type === TouchType.Up) { + if (independentOrNot) { + this.isFunction2Pressed = false; + } + else { + this.isFunction1Pressed = false; + } + } + }); + }, Row); + this.observeComponentCreation2((elmtId, isInitialRender) => { + Image.create(item.value); + Image.width(24); + Image.height(24); + Image.fillColor(FUNCTION_ICON_COLOR); + Image.objectFit(ImageFit.Contain); + Image.position(independentOrNot ? { top: 8, right: 8 } : { top: 6, right: 6 }); + }, Image); + Row.pop(); + } + + initialRender() { + this.observeComponentCreation2((elmtId, isInitialRender) => { + Row.create(); + }, Row); + this.observeComponentCreation2((elmtId, isInitialRender) => { + Flex.create({ + direction: FlexDirection.Row, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Start + }); + Flex.height(40); + Flex.borderRadius(20); + Flex.backgroundColor((typeof this.operationItem !== 'undefined' && this.operationItem?.length >= 2) ? + Color.Transparent : (this.isSearchPressed ? EFFECT_COLOR : TEXT_BOX_COLOR)); + }, Flex); + this.observeComponentCreation2((elmtId, isInitialRender) => { + If.create(); + if (typeof this.operationItem === 'undefined' || this.operationItem?.length === 0) { + this.ifElseBranchUpdateFunction(0, () => { + this.renderSearch.bind(this)(); + }); + } + else if (typeof this.operationItem !== 'undefined' && this.operationItem?.length === 1) { + this.ifElseBranchUpdateFunction(1, () => { + this.renderSearch.bind(this)(); + this.observeComponentCreation2((elmtId, isInitialRender) => { + If.create(); + if (this.showImage) { + this.ifElseBranchUpdateFunction(0, () => { + this.renderFunction.bind(this)(this.operationItem[0], false); + }); + } + else + { + this.ifElseBranchUpdateFunction(1, () => { + }); + } + }, If); + If.pop(); + }); + } + else if (typeof this.operationItem !== 'undefined' && this.operationItem?.length >= 2) { + this.ifElseBranchUpdateFunction(2, () => { + this.observeComponentCreation2((elmtId, isInitialRender) => { + Flex.create({ + direction: FlexDirection.Row, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceBetween + }); + Flex.height(40); + Flex.borderRadius(20); + Flex.backgroundColor(this.isSearchPressed ? EFFECT_COLOR : TEXT_BOX_COLOR); + }, Flex); + this.renderSearch.bind(this)(); + this.observeComponentCreation2((elmtId, isInitialRender) => { + If.create(); + if (this.showImage) { + this.ifElseBranchUpdateFunction(0, () => { + this.renderFunction.bind(this)(this.operationItem[0], false); + }); + } + else { + this.ifElseBranchUpdateFunction(1, () => { + }); + } + }, If); + If.pop(); + Flex.pop(); + this.observeComponentCreation2((elmtId, isInitialRender) => { + Row.create(); + Row.width(40); + Row.height(40); + Row.padding(0); + Row.flexShrink(0); + Row.borderRadius(20); + Row.margin({ left: 8 }); + Row.backgroundColor(TEXT_BOX_COLOR); + }, Row); + this.renderFunction.bind(this)(this.operationItem[1], true); + Row.pop(); + }); + } + else { + this.ifElseBranchUpdateFunction(3, () => { + }); + } + }, If); + If.pop(); + Flex.pop(); + Row.pop(); + } + rerender() { + this.updateDirtyElements(); + } +} + +export default { AtomicServiceSearch }; -- Gitee From a1f20e5c8062b2fb46962db5ef9468bc18b09af1 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 01:59:01 +0000 Subject: [PATCH 05/13] add atomicservicesearch/interfaces/atomicservicesearch.cpp. Signed-off-by: jiyu --- .../interfaces/atomicservicesearch.cpp | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 atomicservicesearch/interfaces/atomicservicesearch.cpp diff --git a/atomicservicesearch/interfaces/atomicservicesearch.cpp b/atomicservicesearch/interfaces/atomicservicesearch.cpp new file mode 100644 index 0000000..79ad7ef --- /dev/null +++ b/atomicservicesearch/interfaces/atomicservicesearch.cpp @@ -0,0 +1,54 @@ +​/* + * Copyright (c) 2025 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. + */ + +#include "native_engine/native_engine.h" + +#include "napi/native_api.h" +#include "napi/native_node_api.h" + +extern const char _binary_atomicservicesearch_abc_start[]; +extern const char _binary_atomicservicesearch_abc_end[]; + +// Napi get abc code function +extern "C" __attribute__((visibility("default"))) +void NAPI_atomicservice_AtomicServiceSearch_GetABCCode(const char **buf, int *buflen) +{ + if (buf != nullptr) { + *buf = _binary_atomicservicesearch_abc_start; + } + if (buflen != nullptr) { + *buflen = _binary_atomicservicesearch_abc_end - _binary_atomicservicesearch_abc_start; + } +} + +/* + * Module define + */ +static napi_module AtomicServiceSearchModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_modname = "atomicservice.AtomicServiceSearch", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +/* + * Module registerfunction + */ +extern "C" __attribute__((constructor)) void AtomicServiceSearchRegisterModule(void) +{ + napi_module_register(&AtomicServiceSearchModule); +} -- Gitee From 3860578cf90bd15822e6acab3d4d02ab2d8681e0 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 01:59:30 +0000 Subject: [PATCH 06/13] add atomicservicesearch/interfaces/BUILD.gn. Signed-off-by: jiyu --- atomicservicesearch/interfaces/BUILD.gn | 57 +++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 atomicservicesearch/interfaces/BUILD.gn diff --git a/atomicservicesearch/interfaces/BUILD.gn b/atomicservicesearch/interfaces/BUILD.gn new file mode 100644 index 0000000..02192e8 --- /dev/null +++ b/atomicservicesearch/interfaces/BUILD.gn @@ -0,0 +1,57 @@ +​# Copyright (c) 2025 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. + +import("//build/config/components/ets_frontend/es2abc_config.gni") +import("//build/ohos.gni") +import("//foundation/arkui/advanced_ui_component/atomicservice_config.gni") + +es2abc_gen_abc("gen_atomicservicesearch_abc") { + src_js = rebase_path("atomicservicesearch.js") + dst_file = rebase_path(target_out_dir + "/atomicservicesearch.abc") + in_puts = [ "atomicservicesearch.js" ] + out_puts = [ target_out_dir + "/atomicservicesearch.abc" ] + extra_args = [ "--module" ] +} + +gen_js_obj("atomicservicesearch_abc") { + input = get_label_info(":gen_atomicservicesearch_abc", "target_out_dir") + + "/atomicservicesearch.abc" + output = target_out_dir + "/atomicservicesearch_abc.o" + dep = ":gen_atomicservicesearch_abc" +} + +gen_obj("atomicservicesearch_abc_preview") { + input = get_label_info(":gen_atomicservicesearch_abc", "target_out_dir") + + "/atomicservicesearch.abc" + output = target_out_dir + "/atomicservicesearch_abc.c" + snapshot_dep = [ ":gen_atomicservicesearch_abc" ] +} + +ohos_shared_library("atomicservicesearch") { + sources = [ "atomicservicesearch.cpp" ] + + if (use_mingw_win || use_mac || use_linux) { + deps = [ ":gen_obj_src_atomicservicesearch_abc_preview" ] + } else { + deps = [ ":atomicservicesearch_abc" ] + } + + external_deps = [ + "hilog:libhilog", + "napi:ace_napi", + ] + + relative_install_dir = "module/atomicservice" + subsystem_name = "arkui" + part_name = "advanced_ui_component" +} -- Gitee From 0abae724bc43168b475ac079fc2a014d12c6a434 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 02:00:00 +0000 Subject: [PATCH 07/13] add atomicservicesearch/source/atomicservicesearch.ets. Signed-off-by: jiyu --- .../source/atomicservicesearch.ets | 219 ++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 atomicservicesearch/source/atomicservicesearch.ets diff --git a/atomicservicesearch/source/atomicservicesearch.ets b/atomicservicesearch/source/atomicservicesearch.ets new file mode 100644 index 0000000..31d8b2b --- /dev/null +++ b/atomicservicesearch/source/atomicservicesearch.ets @@ -0,0 +1,219 @@ +​/* + * Copyright (c) 2024 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. + */ +import { OperationType, SelectOptions, OperationOption } from '@ohos.arkui.advanced.SubHeader'; + +const TEXT_SIZE_BODY1: Resource = $r(`sys.float.ohos_id_text_size_body1`); +const TEXT_COLOR_SECONDARY = $r(`sys.color.ohos_id_color_text_secondary`); +const ICON_COLOR_SECONDARY = $r('sys.color.ohos_id_color_secondary'); +const TEXT_BOX_COLOR = $r(`sys.color.ohos_id_color_text_field_sub_bg`); +const TEXT_COLOR_PRIMARY = $r(`sys.color.ohos_id_color_text_primary`); +const FUNCTION_ICON_COLOR = $r(`sys.color.ohos_id_color_primary`); +const EFFECT_COLOR = $r(`sys.color.ohos_id_color_click_effect`); + +@Component +export struct AtomicServiceSearch { + @State private isFunction1Pressed: boolean = false; + @State private isFunction2Pressed: boolean = false; + @State private isSearchPressed: boolean = false; + @Watch('onParamsChange') @State private changeValue: string = ''; + @State private showImage: boolean = true; + private controller: SearchController = new SearchController(); + hint?: ResourceStr = 'Search'; + select?: SelectOptions; + operationType?: OperationType = OperationType.BUTTON; + operationItem?: Array; + onSearch?: onSearchEvent; + + aboutToAppear(): void { + if (this.operationType !== OperationType.BUTTON) { + this.operationItem = []; + } + } + + private onParamsChange(): void { + this.showImage = this.changeValue.length === 0 ? true : false; + } + + @Builder + renderSearch() { + this.renderSelect(); + Search({ value: this.changeValue, placeholder: this.hint, controller: this.controller }) + .backgroundColor(Color.Transparent) + .placeholderFont({ size: TEXT_SIZE_BODY1, weight: 400 }) + .textFont({ size: TEXT_SIZE_BODY1, weight: 400 }) + .fontColor(TEXT_COLOR_SECONDARY) + .searchIcon({ color: ICON_COLOR_SECONDARY }) + .onSubmit(this.onSearch?.onSubmit) + .onChange(this.onSearch?.onChange) + .onCopy(this.onSearch?.onCopy) + .onCut(this.onSearch?.onCut) + .onPaste(this.onSearch?.onPaste) + .onTextSelectionChange(this.onSearch?.onTextSelectionChange) + .onContentScroll(this.onSearch?.onContentScroll) + .onEditChange(this.onSearch?.onEditChange) + .onWillInsert(this.onSearch?.onWillInsert) + .onDidInsert(this.onSearch?.onDidInsert) + .onWillDelete(this.onSearch?.onWillDelete) + .onDidDelete(this.onSearch?.onDidDelete) + .onTouch((event?: TouchEvent) => { + if (event && event.type === TouchType.Down) { + this.isSearchPressed = true; + } else if (event && event.type === TouchType.Up) { + this.isSearchPressed = false; + } + }) + } + + @Builder + renderSelect() { + if (typeof this.select !== 'undefined' && this.select.options.length !== 0) { + Row() { + Select(this.select?.options) + .value(this.select?.value) + .selected(this.select?.selected) + .onSelect(this.select?.onSelect) + .font({ size: TEXT_SIZE_BODY1, weight: 500 }) + .fontColor(TEXT_COLOR_PRIMARY) + .selectedOptionFont({ size: 16, weight: 400 }) + .menuAlign(MenuAlignType.START, { dx: 0, dy: 0 }) + .optionFont({ size: 16, weight: 400 }) + .backgroundColor(Color.Transparent) + .arrowPosition(ArrowPosition.END) + .constraintSize({ minHeight: 36 }) + .padding({ left: 6 }) + .margin({ left: 2 }) + .height(36) + .space(2) + this.renderDivider(); + } + .flexShrink(0) + } + } + + @Builder + renderDivider() { + Divider() + .vertical(true) + .height(22) + .color(Color.Black) + .opacity(0.6) + .margin({ left: 2, right: -2 }) + } + + @Builder + renderFunction(item: OperationOption, independentOrNot: boolean) { + Row() { + Image(item.value) + .width(24) + .height(24) + .fillColor(FUNCTION_ICON_COLOR) + .objectFit(ImageFit.Contain) + .position(independentOrNot ? { top: 8, right: 8 } : { top: 6, right: 6 }) + } + .width(40) + .height(40) + .padding(0) + .flexShrink(0) + .borderRadius(20) + .onClick(item.action) + .alignItems(VerticalAlign.Center) + .justifyContent(FlexAlign.Center) + .margin(independentOrNot ? 0 : { left: 8, right: 2 }) + .backgroundColor(independentOrNot ? + (this.isFunction2Pressed ? EFFECT_COLOR : Color.Transparent) : + (this.isFunction1Pressed ? EFFECT_COLOR : Color.Transparent) + ) + .onTouch((event?: TouchEvent) => { + if (event && event.type === TouchType.Down) { + if (independentOrNot) { + this.isFunction2Pressed = true; + } else { + this.isFunction1Pressed = true; + } + } else if (event && event.type === TouchType.Up) { + if (independentOrNot) { + this.isFunction2Pressed = false; + } else { + this.isFunction1Pressed = false; + } + } + }) + } + + build() { + Row() { + Flex({ + direction: FlexDirection.Row, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.Start + }) { + if (typeof this.operationItem === 'undefined' || this.operationItem?.length === 0) { + this.renderSearch(); + } + else if (typeof this.operationItem !== 'undefined' && this.operationItem?.length === 1) { + this.renderSearch(); + if (this.showImage) { + this.renderFunction(this.operationItem[0], false); + } + } + else if (typeof this.operationItem !== 'undefined' && this.operationItem?.length >= 2) { + Flex({ + direction: FlexDirection.Row, + alignItems: ItemAlign.Center, + justifyContent: FlexAlign.SpaceBetween + }) { + this.renderSearch(); + if (this.showImage) { + this.renderFunction(this.operationItem[0], false); + } + } + .height(40) + .borderRadius(20) + .backgroundColor(this.isSearchPressed ? EFFECT_COLOR : TEXT_BOX_COLOR) + + Row() { + this.renderFunction(this.operationItem[1], true); + } + .width(40) + .height(40) + .padding(0) + .flexShrink(0) + .borderRadius(20) + .margin({ left: 8 }) + .backgroundColor(TEXT_BOX_COLOR) + } + } + .height(40) + .borderRadius(20) + .backgroundColor((typeof this.operationItem !== 'undefined' && this.operationItem?.length >= 2) ? + Color.Transparent : (this.isSearchPressed ? EFFECT_COLOR : TEXT_BOX_COLOR)) + } + } +} + +export interface onSearchEvent { + onSubmit?: (value: string) => void; + onChange?: EditableTextOnChangeCallback; + onCopy?: (value: string) => void; + onCut?: (value: string) => void; + onPaste?: (value: string, event: PasteEvent) => void; + onTextSelectionChange?: (selectionStart: number, selectionEnd: number) => void; + onContentScroll?: (totalOffsetX: number, totalOffsetY: number) => void; + onEditChange?: Callback; + onWillInsert?: Callback; + onDidInsert?: Callback; + onWillDelete?: Callback; + onDidDelete?: Callback; +} -- Gitee From 51c2102c18424bd20e3c00dadbd7e699489762d0 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 02:00:32 +0000 Subject: [PATCH 08/13] update BUILD.gn. Signed-off-by: jiyu --- BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/BUILD.gn b/BUILD.gn index c681d2a..ead9200 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -14,6 +14,7 @@ group("advanced_ui_component") { deps = [ "atomicservicenavigation/interfaces:atomicservicenavigation", + "atomicservicesearch/interfaces:atomicservicesearch", "atomicservicetabs/interfaces:atomicservicetabs", "atomicserviceweb/interfaces:atomicserviceweb", "innerfullscreenlaunchcomponent/interfaces:innerfullscreenlaunchcomponent", -- Gitee From ed0a5ff0e5ba4852bb3dd36803b5510ff94818d7 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 02:00:51 +0000 Subject: [PATCH 09/13] update bundle.json. Signed-off-by: jiyu --- bundle.json | 1 + 1 file changed, 1 insertion(+) diff --git a/bundle.json b/bundle.json index ca80fc0..92b2aee 100644 --- a/bundle.json +++ b/bundle.json @@ -26,6 +26,7 @@ "build": { "sub_component": [ "//foundation/arkui/advanced_ui_component/atomicservicenavigation/interfaces:atomicservicenavigation", + "//foundation/arkui/advanced_ui_component/atomicservicesearch/interfaces:atomicservicesearch", "//foundation/arkui/advanced_ui_component/atomicservicetabs/interfaces:atomicservicetabs", "//foundation/arkui/advanced_ui_component/atomicserviceweb/interfaces:atomicserviceweb", "//foundation/arkui/advanced_ui_component/innerfullscreenlaunchcomponent/interfaces:innerfullscreenlaunchcomponent", -- Gitee From 80961b54e7330fc11c1c2c9c509161a6ad79b07c Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 02:01:12 +0000 Subject: [PATCH 10/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20at?= =?UTF-8?q?omicservicesearch/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atomicservicesearch/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 atomicservicesearch/.keep diff --git a/atomicservicesearch/.keep b/atomicservicesearch/.keep deleted file mode 100644 index e69de29..0000000 -- Gitee From d782e74db04c5bf04caa675007c0e05f52dfe343 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 02:01:22 +0000 Subject: [PATCH 11/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20at?= =?UTF-8?q?omicservicesearch/source/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atomicservicesearch/source/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 atomicservicesearch/source/.keep diff --git a/atomicservicesearch/source/.keep b/atomicservicesearch/source/.keep deleted file mode 100644 index e69de29..0000000 -- Gitee From 9fbaf0634070e52fab5dc18b4246ed3009eafc2a Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 02:01:35 +0000 Subject: [PATCH 12/13] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20at?= =?UTF-8?q?omicservicesearch/interfaces/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atomicservicesearch/interfaces/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 atomicservicesearch/interfaces/.keep diff --git a/atomicservicesearch/interfaces/.keep b/atomicservicesearch/interfaces/.keep deleted file mode 100644 index e69de29..0000000 -- Gitee From 07898a45282aac3309f86e8001d9598976f92f87 Mon Sep 17 00:00:00 2001 From: jiyu Date: Thu, 16 Jan 2025 02:06:14 +0000 Subject: [PATCH 13/13] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- atomicservicesearch/test/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 atomicservicesearch/test/.keep diff --git a/atomicservicesearch/test/.keep b/atomicservicesearch/test/.keep new file mode 100644 index 0000000..e69de29 -- Gitee