diff --git a/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/TestAbility/pages/Index.ets b/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/TestAbility/pages/Index.ets index 6e4f9e86b15bacc6f0f90d09d5c11c5317990ebe..e0f639f1e1aa9284b4bcccb59b9223cbcc9ef150 100644 --- a/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/TestAbility/pages/Index.ets +++ b/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/TestAbility/pages/Index.ets @@ -18,6 +18,7 @@ import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry import { Hypium } from '@ohos/hypium'; import hilog from '@ohos.hilog'; import testsuite from '../../test/List.test' +import {MessageManager,Callback} from '../../test/MessageManager.ets'; @Entry @Component @@ -103,6 +104,47 @@ struct SliderExample { this.textColorResource = eventData.data.textColorResource; } + messageManager:MessageManager = new MessageManager() + onPageShow() { + console.info('search onPageShow') + globalThis.value = { + name:'messageManager',message:this.messageManager + } + let callback:Callback = (message:any) => { + console.error('message = ' + message.name + "--" + message.value) + if (message.name == 'caretWidthResource') { + this.caretWidthResource = message.value + } + if (message.name == 'caretColorResource') { + this.caretColorResource = message.value + } + if (message.name == 'leftSearchIconColorResource') { + this.leftSearchIconColorResource = message.value + } + if (message.name == 'searchSrcPathResource') { + this.searchSrcPathResource = message.value + } + if (message.name == 'rightCancelIconColorResource') { + this.rightCancelIconColorResource = message.value + } + if (message.name == 'rightIconSrcPathResource') { + this.rightIconSrcPathResource = message.value + } + if (message.name == 'searchButtonFontSizeResource') { + this.searchButtonFontSizeResource = message.value + } + if (message.name == 'searchButtonFontColorResource') { + this.searchButtonFontColorResource = message.value + } + if (message.name == 'textColorResource') { + this.textColorResource = message.value + } + + + } + this.messageManager.registerCallback(callback) + } + aboutToAppear(){ var stateChangeEvent = { eventId: 183, @@ -316,4 +358,4 @@ struct SliderExample { .width('100%') .height('100%') } -} \ No newline at end of file +} diff --git a/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/test/MessageManager.ets b/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/test/MessageManager.ets new file mode 100644 index 0000000000000000000000000000000000000000..6756c056b6554e8f2d5841b898ba901d600f4c19 --- /dev/null +++ b/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/test/MessageManager.ets @@ -0,0 +1,54 @@ +/** + * Copyright (c) 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. + */ +export interface Callback { + (message:any):void +} + +export class MessageManager { + callback:Callback + callbacks:Map = new Map() + + constructor() { + + } + + registerCallback(callback:Callback , type?:string) { + if (type == undefined) { + console.error('registerCallback callback set') + this.callback = callback + return + } + this.callbacks.set(type,callback) + } + + notify(message:any, type?:string) { + if (type == undefined) { + this.callback(message) + return + } + + let tmpCallback:Callback = this.callbacks.get(type) + if (tmpCallback === undefined) { + console.error('callbacks has no callback for type ' + type) + return + } + tmpCallback(message) + } + + clear() { + this.callbacks.clear() + this.callback = null + } +} diff --git a/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/test/Search.ets b/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/test/Search.ets index fc5d012dbd60f76e2d7cdf8e99f71a1b3ae38170..8419b16e7ab5316f3e48e158730fb89ee87a2f83 100644 --- a/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/test/Search.ets +++ b/arkui/ace_ets_components_ux/ace_ets_component_search/src/main/ets/test/Search.ets @@ -16,6 +16,7 @@ import { describe, beforeEach, afterEach, it, expect } from '@ohos/hypium' import events_emitter from '@ohos.events.emitter'; import Utils from './Utils.ets'; +import {MessageManager,Callback} from './MessageManager'; let emitKey = "emitUserAgent"; export default function search() { @@ -298,21 +299,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_CaretStyle_0600]: " + JSON.stringify(newJson)); let caretWidthResource = $r('sys.float.ohos_id_text_margin_vertical'); - try { - var eventData = { - data: { - "caretWidthResource": caretWidthResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_CaretStyle_0600] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_CaretStyle_0600] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'caretWidthResource',value:caretWidthResource}); await Utils.sleep(2000); let strJson = getInspectorByKey('searchTestResource'); @@ -660,21 +647,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_CaretStyle_1600]: " + JSON.stringify(newJson)); let caretColorResource = $r('sys.color.ohos_id_color_connected'); - try { - var eventData = { - data: { - "caretColorResource": caretColorResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_CaretStyle_1600] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_CaretStyle_1600] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'caretColorResource',value:caretColorResource}); await Utils.sleep(2000); let strJson = getInspectorByKey('searchTestResource'); @@ -1456,21 +1429,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_SearchIcon_1700]: " + JSON.stringify(newJson)); let leftSearchIconColorResource = $r('sys.color.ohos_id_color_connected'); - try { - var eventData = { - data: { - "leftSearchIconColorResource": leftSearchIconColorResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_SearchIcon_1700] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_SearchIcon_1700] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'leftSearchIconColorResource',value:leftSearchIconColorResource}); await Utils.sleep(2000); let strJson = getInspectorByKey('searchTestResource'); @@ -1794,21 +1753,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_SearchIcon_2600]: " + JSON.stringify(newJson)); let searchSrcPathResource = $r('sys.media.ohos_app_icon'); - try { - var eventData = { - data: { - "searchSrcPathResource": searchSrcPathResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_SearchIcon_2600] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_SearchIcon_2600] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'searchSrcPathResource',value:searchSrcPathResource}); await Utils.sleep(2000); let strJson = getInspectorByKey('searchTestResource'); @@ -2746,21 +2691,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_CancelButton_2200]: " + JSON.stringify(newJson)); let rightCancelIconColorResource = $r('sys.color.ohos_id_color_connected'); - try { - var eventData = { - data: { - "rightCancelIconColorResource": rightCancelIconColorResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_CancelButton_2200] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_CancelButton_2200] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'rightCancelIconColorResource',value:rightCancelIconColorResource}); await Utils.sleep(2000); let strJson = getInspectorByKey('searchTestResource'); @@ -3084,21 +3015,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_CancelButton_3100]: " + JSON.stringify(newJson)); let rightIconSrcPathResource = $r('sys.media.ohos_app_icon'); - try { - var eventData = { - data: { - "rightIconSrcPathResource": rightIconSrcPathResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_CancelButton_3100] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_CancelButton_3100] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'rightIconSrcPathResource',value:rightIconSrcPathResource}); await Utils.sleep(2000); let strJson = getInspectorByKey('searchTestResource'); @@ -3484,21 +3401,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_SearchButton_0700]: " + JSON.stringify(newJson)); let searchButtonFontSizeResource = $r('sys.float.ohos_id_text_paragraph_margin_m'); - try { - var eventData = { - data: { - "searchButtonFontSizeResource": searchButtonFontSizeResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_SearchButton_0700] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_SearchButton_0700] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'searchButtonFontSizeResource',value:searchButtonFontSizeResource}); await Utils.sleep(5000); let strJson = getInspectorByKey('searchTestResource'); @@ -3846,21 +3749,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_SearchButton_1700]: " + JSON.stringify(newJson)); let searchButtonFontColorResource = $r('sys.color.ohos_id_color_connected'); - try { - var eventData = { - data: { - "searchButtonFontColorResource": searchButtonFontColorResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_SearchButton_1700] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_SearchButton_1700] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'searchButtonFontColorResource',value:searchButtonFontColorResource}); await Utils.sleep(2000); let strJson = getInspectorByKey('searchTestResource'); @@ -4180,21 +4069,7 @@ export default function search() { console.info("[ArkUI_Stage_Search_FontColor_0500]: " + JSON.stringify(newJson)); let textColorResource = $r('sys.color.ohos_id_color_connected'); - try { - var eventData = { - data: { - "textColorResource": textColorResource - } - } - var innerEvent = { - eventId: 183, - priority: events_emitter.EventPriority.LOW - } - console.info("[ArkUI_Stage_Search_FontColor_0500] start to publish emit"); - events_emitter.emit(innerEvent, eventData); - } catch (err) { - console.log("[ArkUI_Stage_Search_FontColor_0500] change component data error: " + err.message); - } + globalThis.value.message.notify({name:'textColorResource',value:textColorResource}); await Utils.sleep(2000); let strJson = getInspectorByKey('searchTestResource'); @@ -4325,4 +4200,4 @@ export default function search() { done(); }); }) -} \ No newline at end of file +}