diff --git a/BUILD.gn b/BUILD.gn index c681d2ab2f1976b97c67999d9ce3b90ed4dee95b..ead92005589baca5ea87d1e2f4ada91c7adcb767 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", diff --git a/atomicservicesearch/interfaces/BUILD.gn b/atomicservicesearch/interfaces/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..02192e8df6640feb569e326b2a9402904a80260e --- /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" +} diff --git a/atomicservicesearch/interfaces/atomicservicesearch.cpp b/atomicservicesearch/interfaces/atomicservicesearch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79ad7ef0bbaeb3ddb7eae1c8c017aaa45856815e --- /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); +} diff --git a/atomicservicesearch/interfaces/atomicservicesearch.js b/atomicservicesearch/interfaces/atomicservicesearch.js new file mode 100644 index 0000000000000000000000000000000000000000..13301ece721c2aa2ff0f17b77f5034d0af8e7623 --- /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 }; diff --git a/atomicservicesearch/source/atomicservicesearch.ets b/atomicservicesearch/source/atomicservicesearch.ets new file mode 100644 index 0000000000000000000000000000000000000000..31d8b2b8d2d0246d864857739e65f3e3ac7ea4f4 --- /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; +} diff --git a/atomicservicesearch/test/.keep b/atomicservicesearch/test/.keep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/bundle.json b/bundle.json index ca80fc0637ffa0f48a4c7f0c945dba0714254b9a..92b2aee4afe4dcccdb74439dcce38c1660764e43 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",