提交 ca5d21c6 编写于 作者: Z zhangrao

add compont

Signed-off-by: Nzhangrao <zhangrao@huawei.com>
上级 32c8174f
...@@ -20,7 +20,7 @@ import prompt from '@system.prompt' ...@@ -20,7 +20,7 @@ import prompt from '@system.prompt'
@Entry @Entry
@Preview @Preview
@Component @Component
struct AppearExample { struct AppearExample {
@State isShow: boolean = true @State isShow: boolean = true
@State appearFlag: boolean = false @State appearFlag: boolean = false
@State disAppearFlag: boolean = false @State disAppearFlag: boolean = false
...@@ -40,7 +40,7 @@ struct AppearExample { ...@@ -40,7 +40,7 @@ struct AppearExample {
console.info("[appear] page stateChangCallBack"); console.info("[appear] page stateChangCallBack");
if (eventData != null) { if (eventData != null) {
console.info("[appear] page state change called:" + JSON.stringify(eventData)); console.info("[appear] page state change called:" + JSON.stringify(eventData));
if(eventData.data.isShow != null) { if (eventData.data.isShow != null) {
this.isShow = eventData.data.isShow; this.isShow = eventData.data.isShow;
} }
} }
...@@ -60,7 +60,7 @@ struct AppearExample { ...@@ -60,7 +60,7 @@ struct AppearExample {
this.changeAppear = 'Show Text' this.changeAppear = 'Show Text'
console.info('appearFlag current action state is: ' + this.appearFlag); console.info('appearFlag current action state is: ' + this.appearFlag);
prompt.showToast({ message: 'The text is shown', duration: 2000 }) prompt.showToast({ message: 'The text is shown', duration: 2000 })
try{ try {
var backData = { var backData = {
data: { data: {
"ACTION": this.appearFlag, "ACTION": this.appearFlag,
...@@ -72,7 +72,7 @@ struct AppearExample { ...@@ -72,7 +72,7 @@ struct AppearExample {
} }
console.info("appearFlag start to emit action state") console.info("appearFlag start to emit action state")
events_emitter.emit(backEvent, backData) events_emitter.emit(backEvent, backData)
}catch{ } catch {
console.info("appearFlag emit action state err: " + JSON.stringify(err.message)) console.info("appearFlag emit action state err: " + JSON.stringify(err.message))
} }
}) })
...@@ -81,7 +81,7 @@ struct AppearExample { ...@@ -81,7 +81,7 @@ struct AppearExample {
this.changeAppear = 'Hide Text' this.changeAppear = 'Hide Text'
console.info('disAppearFlag current action state is: ' + this.disAppearFlag); console.info('disAppearFlag current action state is: ' + this.disAppearFlag);
prompt.showToast({ message: 'The text is hidden', duration: 2000 }) prompt.showToast({ message: 'The text is hidden', duration: 2000 })
try{ try {
var backData = { var backData = {
data: { data: {
"ACTION": this.disAppearFlag, "ACTION": this.disAppearFlag,
...@@ -93,7 +93,7 @@ struct AppearExample { ...@@ -93,7 +93,7 @@ struct AppearExample {
} }
console.info("disAppearFlag start to emit action state") console.info("disAppearFlag start to emit action state")
events_emitter.emit(backEvent, backData) events_emitter.emit(backEvent, backData)
}catch{ } catch {
console.info("disAppearFlag emit action state err: " + JSON.stringify(err.message)) console.info("disAppearFlag emit action state err: " + JSON.stringify(err.message))
} }
}) })
......
// @ts-nocheck
/**
* Copyright (c) 2021 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 events_emitter from '@ohos.emitter';
@Entry
@Component
struct ColumnExample {
@State alignItems: HorizontalAlign = HorizontalAlign.Start;
onPageShow() {
console.info('[column] page show called');
var stateChangeEvent = {
eventId: 192,
priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("[column] page stateChangCallBack");
if (eventData != null) {
console.info("[column] page state change called:" + JSON.stringify(eventData));
if(eventData.data.alignItems != null) {
this.alignItems = eventData.data.alignItems;
}
}
}
build() {
Column() {
Text('alignItems').fontSize(9).fontColor(0xCCCCCC).width('90%')
Column() {
Column().width('50%').height(30).backgroundColor(0xAFEEEE)
Column().width('50%').height(30).backgroundColor(0x00FFFF)
}
.key("alignItemsColumn")
.width('90%')
.border({ width: 1 })
.alignItems(this.alignItems)
}.width('100%').padding({ top: 5 })
}
}
\ No newline at end of file
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter'; import events_emitter from '@ohos.emitter';
@Entry @Entry
@Component @Component
struct EllipseExample { struct EllipseExample {
@State width: string = "200px"; @State width: string = "200px";
@State height: string = "200px"; @State height: string = "200px";
onPageShow() { onPageShow() {
console.info('[ellipse] page show called'); console.info('[ellipse] page show called');
var stateChangeEvent = { var stateChangeEvent = {
eventId: 92, eventId: 92,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(stateChangeEvent, this.stateChangCallBack); events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
var stateChangeEventTwo = {
private stateChangCallBack = (eventData) => { eventId: 907,
console.info("[ellipse] page stateChangCallBack"); priority: events_emitter.EventPriority.LOW
if (eventData != null) { }
console.info("[ellipse] page state change called:" + JSON.stringify(eventData)); events_emitter.on(stateChangeEventTwo, this.stateChangCallBack);
if(eventData.data.width != null) {
this.width = eventData.data.width; var stateChangeEventThree = {
} eventId: 908,
if(eventData.data.height != null) { priority: events_emitter.EventPriority.LOW
this.height = eventData.data.height; }
} events_emitter.on(stateChangeEventThree, this.stateChangCallBack);
} }
}
private stateChangCallBack = (eventData) => {
build() { console.info("[ellipse] page stateChangCallBack");
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center,justifyContent: FlexAlign.Center}) { if (eventData != null) {
Ellipse().width(`${this.width}`).height(`${this.height}`).key('ellipse') console.info("[ellipse] page state change called:" + JSON.stringify(eventData));
}.width('100%').height('100%') if (eventData.data.width != null) {
} this.width = eventData.data.width;
}
if (eventData.data.height != null) {
this.height = eventData.data.height;
}
}
}
build() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Ellipse().width(`${this.width}`).height(`${this.height}`).key('ellipse')
}.width('100%').height('100%')
}
} }
\ No newline at end of file
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter'
@Entry import events_emitter from '@ohos.emitter'
@Component
struct EnabledExample { @Entry
@State enabled: boolean = true; @Component
@State text: string = "enable"; struct EnabledExample {
@State enabled: boolean = true;
onPageShow() { @State text: string = "enable";
console.info('[enabled] page show called ');
var stateChangeEvent = { onPageShow() {
eventId: 93, console.info('[enabled] page show called ');
priority: events_emitter.EventPriority.LOW var stateChangeEvent = {
} eventId: 93,
events_emitter.on(stateChangeEvent, this.stateChangCallBack); priority: events_emitter.EventPriority.LOW
}
} events_emitter.on(stateChangeEvent, this.stateChangCallBack);
private stateChangCallBack = (eventData) => { var stateChangeEvent2 = {
console.info("[stateChangCallBack] stateChangCallBack "); eventId: 1111,
if (eventData != null) { priority: events_emitter.EventPriority.LOW
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData)); }
if (eventData.data.enabled != null) { events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
this.enabled = eventData.data.enabled
} }
if (eventData.data.text != null) {
this.text = eventData.data.text private stateChangCallBack = (eventData) => {
} console.info("[stateChangCallBack] stateChangCallBack ");
} if (eventData != null) {
} console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.enabled != null) {
build() { this.enabled = eventData.data.enabled
Flex({ justifyContent: FlexAlign.SpaceAround }) { }
Button('disable') if (eventData.data.text != null) {
.enabled(false) this.text = eventData.data.text
.backgroundColor(0x317aff) }
.opacity(0.4) }
Button(this.text) }
.key('enabled')
.backgroundColor(0x317aff) build() {
.enabled(this.enabled) Flex({ justifyContent: FlexAlign.SpaceAround }) {
} Button('disable')
.width('100%') .enabled(false)
.padding({ top: 5 }) .backgroundColor(0x317aff)
} .opacity(0.4)
Button(this.text)
.key('enabled')
.backgroundColor(0x317aff)
.enabled(this.enabled)
}
.width('100%')
.padding({ top: 5 })
}
} }
\ No newline at end of file
...@@ -23,25 +23,24 @@ struct FlexExample { ...@@ -23,25 +23,24 @@ struct FlexExample {
private stateChangCallBack = (eventData) => { private stateChangCallBack = (eventData) => {
if (eventData != null) { if (eventData != null) {
console.info("Flex page state change called:" + JSON.stringify(eventData)); console.info("Flex page state change called:" + JSON.stringify(eventData));
if(eventData.data.flexBasis != null) { if (eventData.data.flexBasis != null) {
this.flexBasis = eventData.data.flexBasis; this.flexBasis = eventData.data.flexBasis;
} }
if(eventData.data.flexGrow != null) { if (eventData.data.flexGrow != null) {
this.flexGrow = eventData.data.flexGrow; this.flexGrow = eventData.data.flexGrow;
} }
if(eventData.data.flexShrink != null) { if (eventData.data.flexShrink != null) {
this.flexShrink = eventData.data.flexShrink; this.flexShrink = eventData.data.flexShrink;
} }
if(eventData.data.alignSelf != null) { if (eventData.data.alignSelf != null) {
this.alignSelf = eventData.data.alignSelf; this.alignSelf = eventData.data.alignSelf;
} }
} }
} }
private stateChangCallBack = (eventData) => { private stateChangCallBack = (eventData) => {
if (eventData != null) { if (eventData != null) {
console.info("Flex page state change called:" + JSON.stringify(eventData)); console.info("Flex page state change called:" + JSON.stringify(eventData));
switch(eventData.data.alignSelf) { switch (eventData.data.alignSelf) {
case 'Auto': case 'Auto':
this.alignSelf = ItemAlign.Auto; this.alignSelf = ItemAlign.Auto;
break; break;
...@@ -80,33 +79,60 @@ struct FlexExample { ...@@ -80,33 +79,60 @@ struct FlexExample {
Text('flexBasis').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('flexBasis').fontSize(9).fontColor(0xCCCCCC).width('90%')
Flex() { Flex() {
Text('flexBasis("auto")') Text('flexBasis("auto")')
.flexBasis('auto').key("flexBasis").width('60%').height(100).lineHeight(70) .flexBasis('auto')
.backgroundColor(0xD2B48C).textAlign(TextAlign.Center) .key("flexBasis")
.width('60%')
.height(100)
.lineHeight(70)
.backgroundColor(0xD2B48C)
.textAlign(TextAlign.Center)
Text('flexBasis(100)') Text('flexBasis(100)')
.flexBasis('100').height(100).lineHeight(70) .flexBasis('100')
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) .height(100)
.lineHeight(70)
.backgroundColor(0xF5DEB3)
.textAlign(TextAlign.Center)
}.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE)
Text('flexGrow').key("flexGrow").fontSize(9).fontColor(0xCCCCCC).width('90%') Text('flexGrow').key("flexGrow").fontSize(9).fontColor(0xCCCCCC).width('90%')
Flex() { Flex() {
Text('flexGrow(2)') Text('flexGrow(2)')
.flexGrow(2).height(100).lineHeight(70) .flexGrow(2)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) .height(100)
.lineHeight(70)
.backgroundColor(0xF5DEB3)
.textAlign(TextAlign.Center)
Text('flexGrow(1)') Text('flexGrow(1)')
.flexGrow(1).height(100).lineHeight(70) .flexGrow(1)
.backgroundColor(0xD2B48C).textAlign(TextAlign.Center) .height(100)
.lineHeight(70)
.backgroundColor(0xD2B48C)
.textAlign(TextAlign.Center)
}.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE)
Text('flexShrink').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('flexShrink').fontSize(9).fontColor(0xCCCCCC).width('90%')
Flex({ direction: FlexDirection.Row }) { Flex({ direction: FlexDirection.Row }) {
Text('flexShrink(0)') Text('flexShrink(0)')
.flexShrink(0).key("flexShrink").width('50%').height(100).lineHeight(70) .flexShrink(0)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) .key("flexShrink")
.width('50%')
.height(100)
.lineHeight(70)
.backgroundColor(0xF5DEB3)
.textAlign(TextAlign.Center)
Text('no flexShrink') Text('no flexShrink')
.width('40%').height(100).lineHeight(70).backgroundColor(0xD2B48C).textAlign(TextAlign.Center) .width('40%')
.height(100)
.lineHeight(70)
.backgroundColor(0xD2B48C)
.textAlign(TextAlign.Center)
Text('flexShrink(2)') Text('flexShrink(2)')
.flexShrink(2).width('40%').height(100) .lineHeight(70) .flexShrink(2)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) .width('40%')
.height(100)
.lineHeight(70)
.backgroundColor(0xF5DEB3)
.textAlign(TextAlign.Center)
}.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) }.width('90%').height(120).padding(10).backgroundColor(0xAFEEEE)
Text('alignSelf').key("alignSelf").fontSize(9).fontColor(0xCCCCCC).width('90%') Text('alignSelf').key("alignSelf").fontSize(9).fontColor(0xCCCCCC).width('90%')
...@@ -114,11 +140,20 @@ struct FlexExample { ...@@ -114,11 +140,20 @@ struct FlexExample {
Text('no alignSelf,height:80').width('33%').height(80) Text('no alignSelf,height:80').width('33%').height(80)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
Text('alignSelf stretch') Text('alignSelf stretch')
.alignSelf(ItemAlign.Stretch).width('33%').height(80).lineHeight(70) .alignSelf(ItemAlign.Stretch)
.backgroundColor(0xD2B48C).textAlign(TextAlign.Center) .width('33%')
.height(80)
.lineHeight(70)
.backgroundColor(0xD2B48C)
.textAlign(TextAlign.Center)
Text('no alignSelf,height:100').width('34%').height(100) Text('no alignSelf,height:100').width('34%').height(100)
.backgroundColor(0xF5DEB3).textAlign(TextAlign.Center) .backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
}.key('flex').width('90%').height(120).padding(10).backgroundColor(0xAFEEEE) }
.key('flex')
.width('90%')
.height(120)
.padding(10)
.backgroundColor(0xAFEEEE)
}.width('100%').margin({ top: 5 }) }.width('100%').margin({ top: 5 })
} }
} }
\ No newline at end of file
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter'; import events_emitter from '@ohos.emitter';
@Entry @Entry
@Component @Component
struct GaugeExample { struct GaugeExample {
@State gaugeValue: string = 50; @State gaugeValue: string = 50;
@State strokeWidthValue: string = 20; @State strokeWidthValue: string = 20;
@State startAngleValue: string = 210; @State startAngleValue: string = 210;
@State endAngleValue: string = 150; @State endAngleValue: string = 150;
@State colorValues: Array = [[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]]; @State colorValues: Array = [[0x317AF7, 1], [0x5BA854, 1], [0xE08C3A, 1], [0x9C554B, 1], [0xD94838, 1]];
private stateChangCallBack = (eventData) => {
private stateChangCallBack = (eventData) => { if (eventData != null) {
if (eventData != null) { console.info("gauge page state change called:" + JSON.stringify(eventData));
console.info("gauge page state change called:" + JSON.stringify(eventData)); if (eventData.data.gaugeValue != null) {
if(eventData.data.gaugeValue != null) { this.gaugeValue = eventData.data.gaugeValue;
this.gaugeValue = eventData.data.gaugeValue; }
} if (eventData.data.strokeWidthValue != null) {
if(eventData.data.strokeWidthValue != null) { this.strokeWidthValue = eventData.data.strokeWidthValue;
this.strokeWidthValue = eventData.data.strokeWidthValue; }
} if (eventData.data.startAngleValue != null) {
if(eventData.data.startAngleValue != null) { this.startAngleValue = eventData.data.startAngleValue;
this.startAngleValue = eventData.data.startAngleValue; }
} if (eventData.data.endAngleValue != null) {
if(eventData.data.endAngleValue != null) { this.endAngleValue = eventData.data.endAngleValue;
this.endAngleValue = eventData.data.endAngleValue; }
} if (eventData.data.colorValues != null) {
if(eventData.data.colorValues != null) { this.colorValues = JSON.parse(eventData.data.colorValues);
this.colorValues = JSON.parse(eventData.data.colorValues); }
} }
} }
}
onPageShow() {
onPageShow() { console.info('gauge page show called');
console.info('gauge page show called'); var stateChangeEvent = {
var stateChangeEvent = { eventId: 102,
eventId: 102, priority: events_emitter.EventPriority.LOW
priority: events_emitter.EventPriority.LOW }
} events_emitter.on(stateChangeEvent, this.stateChangCallBack);
events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEventTwo = {
var stateChangeEventTwo = { eventId: 103,
eventId: 103, priority: events_emitter.EventPriority.LOW
priority: events_emitter.EventPriority.LOW }
} events_emitter.on(stateChangeEventTwo, this.stateChangCallBack);
events_emitter.on(stateChangeEventTwo, this.stateChangCallBack);
} var stateChangeEvent3 = {
eventId: 904,
build() { priority: events_emitter.EventPriority.LOW
Column() { }
Gauge({ value: 0, min: 0, max: 100 }) events_emitter.on(stateChangeEvent3, this.stateChangCallBack);
.key("gauge")
.value(`${this.gaugeValue}`) var stateChangeEvent4 = {
.startAngle(`${this.startAngleValue}`) eventId: 905,
.endAngle(`${this.endAngleValue}`) priority: events_emitter.EventPriority.LOW
.colors(this.colorValues) }
.strokeWidth(`${this.strokeWidthValue}`) events_emitter.on(stateChangeEvent4, this.stateChangCallBack);
.width(200).height(200)
}.width('100%').margin({ top: 300 }) var stateChangeEvent5 = {
} eventId: 906,
} priority: events_emitter.EventPriority.LOW
}
events_emitter.on(stateChangeEvent5, this.stateChangCallBack);
}
build() {
Column() {
Gauge({ value: 0, min: 0, max: 100 })
.key("gauge")
.value(`${this.gaugeValue}`)
.startAngle(`${this.startAngleValue}`)
.endAngle(`${this.endAngleValue}`)
.strokeWidth(`${this.strokeWidthValue}`)
.width(200)
.height(200)
}.width('100%').margin({ top: 300 })
}
}
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
@Entry @Entry
@Component @Component
struct GlobalExample { struct GlobalExample {
onPageShow() { onPageShow() {
} }
...@@ -44,9 +43,9 @@ struct GlobalExample { ...@@ -44,9 +43,9 @@ struct GlobalExample {
let width = img.width; let width = img.width;
let height = img.height; let height = img.height;
this.context.imageSmoothingEnabled = false; this.context.imageSmoothingEnabled = false;
this.context.drawImage( img, 30, 950, 160, 100); this.context.drawImage(img, 30, 950, 160, 100);
console.log("imagebitmap_width="+width); console.log("imagebitmap_width=" + width);
console.log("imagebitmap_height="+height); console.log("imagebitmap_height=" + height);
} }
testOffscreenCanvas() { testOffscreenCanvas() {
...@@ -63,17 +62,19 @@ struct GlobalExample { ...@@ -63,17 +62,19 @@ struct GlobalExample {
testImageData() { testImageData() {
var offscreen = new OffscreenCanvas(300, 300); var offscreen = new OffscreenCanvas(300, 300);
var offCanvas2 = offscreen.getContext("2d"); var offCanvas2 = offscreen.getContext("2d");
var imageData = offCanvas2.createImageData(100,100); var imageData = offCanvas2.createImageData(100, 100);
var imgData = imageData.data; var imgData = imageData.data;
console.log("imageData_width="+imageData.width); console.log("imageData_width=" + imageData.width);
console.log("imageData_height="+imageData.height); console.log("imageData_height=" + imageData.height);
} }
testImage(){ testImage() {
var img = new Image("/images/bg.jpg",100,100) var img = new Image("/images/bg.jpg", 100, 100)
.onload(()=>{}) .onload(() => {
.onerror(()=>{}); })
console.log("img_width="+img.width); .onerror(() => {
console.log("img_height="+img.height); });
console.log("img_width=" + img.width);
console.log("img_height=" + img.height);
} }
} }
\ No newline at end of file
...@@ -24,8 +24,8 @@ struct GridSetting { ...@@ -24,8 +24,8 @@ struct GridSetting {
@State gridSpan: number = 1; @State gridSpan: number = 1;
@State gridOffset: number = 0; @State gridOffset: number = 0;
build(){ build() {
GridContainer({sizeType: SizeType.SM}) { GridContainer({ sizeType: SizeType.SM }) {
Row({}) { Row({}) {
Row() { Row() {
Text('Left').fontSize(25) Text('Left').fontSize(25)
...@@ -34,6 +34,7 @@ struct GridSetting { ...@@ -34,6 +34,7 @@ struct GridSetting {
.height("100%") .height("100%")
.backgroundColor(0x66bbb2cb) .backgroundColor(0x66bbb2cb)
.key('gridOffset') .key('gridOffset')
Row() { Row() {
Text('Center').fontSize(25) Text('Center').fontSize(25)
} }
...@@ -44,6 +45,7 @@ struct GridSetting { ...@@ -44,6 +45,7 @@ struct GridSetting {
.height("100%") .height("100%")
.backgroundColor(0x66b6c5d1) .backgroundColor(0x66b6c5d1)
.key('gridRow') .key('gridRow')
Row() { Row() {
Text('Right').fontSize(25) Text('Right').fontSize(25)
} }
...@@ -58,6 +60,7 @@ struct GridSetting { ...@@ -58,6 +60,7 @@ struct GridSetting {
.margin({ top: 10 }) .margin({ top: 10 })
.key('gridContainer') .key('gridContainer')
} }
onPageShow() { onPageShow() {
let smChangeEvent = { let smChangeEvent = {
eventId: 9, eventId: 9,
...@@ -75,6 +78,7 @@ struct GridSetting { ...@@ -75,6 +78,7 @@ struct GridSetting {
} }
events_emitter.on(spanChangeEvent, this.stateChangCallBack); events_emitter.on(spanChangeEvent, this.stateChangCallBack);
} }
stateChangCallBack = (eventData) => { stateChangCallBack = (eventData) => {
console.info("GridSetting page stateChangCallBack" + JSON.stringify(eventData)); console.info("GridSetting page stateChangCallBack" + JSON.stringify(eventData));
if (eventData && eventData.data) { if (eventData && eventData.data) {
......
...@@ -28,7 +28,6 @@ struct ImageEffectsExample { ...@@ -28,7 +28,6 @@ struct ImageEffectsExample {
@State contrastValue: string= 20; @State contrastValue: string= 20;
@State invertValue: string= 10; @State invertValue: string= 10;
@State hueRotateValue: string= 10 @State hueRotateValue: string= 10
private stateChangCallBack = (eventData) => { private stateChangCallBack = (eventData) => {
if (eventData != null) { if (eventData != null) {
console.info("imageEffects page state change called:" + JSON.stringify(eventData)); console.info("imageEffects page state change called:" + JSON.stringify(eventData));
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
import file from '@system.file'; import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets"; import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets";
import testsuite from "../test/List.test.ets"; import testsuite from "../test/List.test.ets";
import featureAbility from "@ohos.ability.featureAbility"; import featureAbility from "@ohos.ability.featureAbility";
......
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter'; import events_emitter from '@ohos.emitter';
class ContainerInfo { class ContainerInfo {
label : string = '' label: string = ''
size : string = '' size: string = ''
}; };
class ChildInfo { class ChildInfo {
text : string = '' text: string = ''
priority : number = 0 priority: number = 0
}; };
@Entry @Entry
@Component @Component
struct LayoutConstraints { struct LayoutConstraints {
private children : string[] = ['1', '2', '3', '4', '5', '6']; private children: string[] = ['1', '2', '3', '4', '5', '6'];
@State aspectRatio: number = 1.5; @State aspectRatio: number = 1.5;
private container: ContainerInfo[] = [ private container: ContainerInfo[] = [
{label: 'Big container', size: '97%'}, { label: 'Big container', size: '97%' },
{label: 'Small container', size: '30%'}]; { label: 'Small container', size: '30%' }];
@State priorityChildren: any[] = [ @State priorityChildren: any[] = [
{text: '1\n(priority:1)', priority: 1}, { text: '1\n(priority:1)', priority: 1 },
{text: '2\n(priority:2)', priority: 2}, { text: '2\n(priority:2)', priority: 2 },
{text: '3\n(priority:3)', priority: 3}, { text: '3\n(priority:3)', priority: 3 },
{text: '4\n(priority:4)', priority: 4}]; { text: '4\n(priority:4)', priority: 4 }];
@State currentIndex : number = 0; @State currentIndex: number = 0;
build() { build() {
Column({ space: 20 }) { Column({ space: 20 }) {
Text('using container: row').fontSize(20).fontColor(Color.Black).width('100%') Text('using container: row').fontSize(20).fontColor(Color.Black).width('100%')
Row({space: 10}) { Row({ space: 10 }) {
ForEach(this.children, (item) => { ForEach(this.children, (item) => {
Text(item) Text(item)
.backgroundColor(0xbbb2cb) .backgroundColor(0xbbb2cb)
.fontSize(20) .fontSize(20)
.aspectRatio(this.aspectRatio) .aspectRatio(this.aspectRatio)
.height(60) .height(60)
Text(item) Text(item)
.backgroundColor(0xbbb2cb) .backgroundColor(0xbbb2cb)
.fontSize(20) .fontSize(20)
.aspectRatio(this.aspectRatio) .aspectRatio(this.aspectRatio)
.width(60) .width(60)
.key('aspectRatio') .key('aspectRatio')
}, item=>item) }, item => item)
} }
.size({width: "100%", height: 100}) .size({ width: "100%", height: 100 })
.backgroundColor(0xd2cab3) .backgroundColor(0xd2cab3)
.clip(true) .clip(true)
Text('using container: grid').fontSize(20).fontColor(Color.Black).width('100%') Text('using container: grid').fontSize(20).fontColor(Color.Black).width('100%')
Grid() { Grid() {
ForEach(this.children, (item) => { ForEach(this.children, (item) => {
GridItem() { GridItem() {
Text(item) Text(item)
.backgroundColor(0xbbb2cb) .backgroundColor(0xbbb2cb)
.fontSize(40) .fontSize(40)
.aspectRatio(this.aspectRatio) .aspectRatio(this.aspectRatio)
} }
}, item=>item) }, item => item)
} }
.columnsTemplate('1fr 1fr 1fr') .columnsTemplate('1fr 1fr 1fr')
.columnsGap(10) .columnsGap(10)
.rowsGap(10) .rowsGap(10)
.size({width: "100%", height: 165}) .size({ width: "100%", height: 165 })
.backgroundColor(0xd2cab3) .backgroundColor(0xd2cab3)
Text('displayPriority 4').fontSize(20).fontColor(Color.Black).width('100%') Text('displayPriority 4').fontSize(20).fontColor(Color.Black).width('100%')
Flex({justifyContent: FlexAlign.SpaceBetween}) { Flex({ justifyContent: FlexAlign.SpaceBetween }) {
ForEach(this.priorityChildren, (item)=>{ ForEach(this.priorityChildren, (item) => {
if (item.priority === 1 || item.priority === 5) { if (item.priority === 1 || item.priority === 5) {
Text(`1\n(priority:${item.priority})`) Text(`1\n(priority:${item.priority})`)
.width(135) .width(135)
.height(60) .height(60)
.fontSize(18) .fontSize(18)
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
.backgroundColor(0xbbb2cb) .backgroundColor(0xbbb2cb)
.displayPriority(item.priority) .displayPriority(item.priority)
.key('displayPriority') .key('displayPriority')
} else { } else {
Text(item.text) Text(item.text)
.width(135) .width(135)
.height(60) .height(60)
.fontSize(18) .fontSize(18)
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
.backgroundColor(0xbbb2cb) .backgroundColor(0xbbb2cb)
.displayPriority(item.priority) .displayPriority(item.priority)
} }
}, item=>item.text) }, item => item.text)
} }
.width(this.container[this.currentIndex].size) .width(this.container[this.currentIndex].size)
.backgroundColor(0xd2cab3) .backgroundColor(0xd2cab3)
}.padding(10) }.padding(10)
} }
onPageShow() {
let aspectRatioChangeEvent = { onPageShow() {
eventId: 20, let aspectRatioChangeEvent = {
priority: events_emitter.EventPriority.LOW eventId: 20,
} priority: events_emitter.EventPriority.LOW
events_emitter.on(aspectRatioChangeEvent, this.stateChangCallBack); }
events_emitter.on(aspectRatioChangeEvent, this.stateChangCallBack);
let priorityChangeEvent = {
eventId: 21, let priorityChangeEvent = {
priority: events_emitter.EventPriority.LOW eventId: 21,
} priority: events_emitter.EventPriority.LOW
events_emitter.on(priorityChangeEvent, this.stateChangCallBack); }
} events_emitter.on(priorityChangeEvent, this.stateChangCallBack);
stateChangCallBack = (eventData) => {
console.info("LayoutConstraints page stateChangCallBack" + JSON.stringify(eventData)); let priorityChangeEvent2 = {
if (eventData) { eventId: 1112,
if (eventData.data.aspectRatio) { priority: events_emitter.EventPriority.LOW
this.aspectRatio = eventData.data.aspectRatio; }
} else if (eventData.data.displayPriority) { events_emitter.on(priorityChangeEvent2, this.stateChangCallBack);
let priority = JSON.parse(JSON.stringify(this.priorityChildren)); }
priority[0].priority = eventData.data.displayPriority;
this.priorityChildren = []; stateChangCallBack = (eventData) => {
this.priorityChildren = priority; console.info("LayoutConstraints page stateChangCallBack" + JSON.stringify(eventData));
} if (eventData) {
} if (eventData.data.aspectRatio) {
} this.aspectRatio = eventData.data.aspectRatio;
} else if (eventData.data.displayPriority) {
let priority = JSON.parse(JSON.stringify(this.priorityChildren));
priority[0].priority = eventData.data.displayPriority;
this.priorityChildren = [];
this.priorityChildren = priority;
}
}
}
} }
\ No newline at end of file
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter'; import events_emitter from '@ohos.emitter';
@Entry @Entry
@Component @Component
struct ListExample { struct ListExample {
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
@State listDirection: Axis = Axis.Vertical; @State listDirection: Axis = Axis.Vertical;
@State editMode: boolean = false; @State editMode: boolean = false;
@State edgeEffect: EdgeEffect = EdgeEffect.None; @State edgeEffect: EdgeEffect = EdgeEffect.None;
@State chainAnimation: boolean = false; @State chainAnimation: boolean = false;
@State strokeWidth: number = 2.000000; @State strokeWidth: number = 2.000000;
@State color: string = 0xFFFFFF; @State color: string = 0xFFFFFF;
@State startMargin: number = 20.000000; @State startMargin: number = 20.000000;
@State endMargin: number = 20.000000; @State endMargin: number = 20.000000;
onPageShow() { onPageShow() {
console.info('[list] page show called'); console.info('[list] page show called');
var stateChangeEvent = { var stateChangeEvent = {
eventId: 124, eventId: 124,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(stateChangeEvent, this.stateChangCallBack); events_emitter.on(stateChangeEvent, this.stateChangCallBack);
var stateChangeEventTwo = { var stateChangeEventTwo = {
eventId: 125, eventId: 125,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(stateChangeEventTwo, this.stateChangCallBackTwo); events_emitter.on(stateChangeEventTwo, this.stateChangCallBackTwo);
}
var stateChangeEvent3 = {
private stateChangCallBack = (eventData) => { eventId: 901,
console.info("[stateChangCallBack] stateChangCallBack"); priority: events_emitter.EventPriority.LOW
if (eventData != null) { }
console.info("[stateChangCallBack] state change called:" + JSON.stringify(eventData)); events_emitter.on(stateChangeEvent3, this.stateChangCallBackTwo);
if(eventData.data.listDirection != null) {
this.listDirection = eventData.data.listDirection; var stateChangeEvent4 = {
} eventId: 902,
if(eventData.data.editMode != null) { priority: events_emitter.EventPriority.LOW
this.editMode = eventData.data.editMode; }
} events_emitter.on(stateChangeEvent4, this.stateChangCallBackTwo);
if(eventData.data.edgeEffect != null) {
this.edgeEffect = eventData.data.edgeEffect; var stateChangeEvent5 = {
} eventId: 903,
if(eventData.data.chainAnimation != null) { priority: events_emitter.EventPriority.LOW
this.chainAnimation = eventData.data.chainAnimation; }
} events_emitter.on(stateChangeEvent5, this.stateChangCallBackTwo);
} }
}
private stateChangCallBack = (eventData) => {
private stateChangCallBackTwo = (eventData) => { console.info("[stateChangCallBack] stateChangCallBack");
console.info("[stateChangCallBackTwo] stateChangCallBack"); if (eventData != null) {
if (eventData != null) { console.info("[stateChangCallBack] state change called:" + JSON.stringify(eventData));
console.info("[stateChangCallBackTwo] state change called:" + JSON.stringify(eventData)); if (eventData.data.listDirection != null) {
if(eventData.data.strokeWidth != null) { this.listDirection = eventData.data.listDirection;
this.strokeWidth = eventData.data.strokeWidth; }
} if (eventData.data.editMode != null) {
if(eventData.data.color != null) { this.editMode = eventData.data.editMode;
this.color = eventData.data.color; }
} if (eventData.data.edgeEffect != null) {
if(eventData.data.startMargin != null) { this.edgeEffect = eventData.data.edgeEffect;
this.startMargin = eventData.data.startMargin; }
} if (eventData.data.chainAnimation != null) {
if(eventData.data.endMargin != null) { this.chainAnimation = eventData.data.chainAnimation;
this.endMargin = eventData.data.endMargin; }
} }
} }
} private stateChangCallBackTwo = (eventData) => {
console.info("[stateChangCallBackTwo] stateChangCallBack");
build() { if (eventData != null) {
Stack({ alignContent: Alignment.TopStart }) { console.info("[stateChangCallBackTwo] state change called:" + JSON.stringify(eventData));
Column() { if (eventData.data.strokeWidth != null) {
List({ space: 20, initialIndex: 0 }) { this.strokeWidth = eventData.data.strokeWidth;
ForEach(this.arr, (item) => { }
ListItem() { if (eventData.data.color != null) {
Text('' + item) this.color = eventData.data.color;
.width('100%').height(100).fontSize(16) }
.textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF) if (eventData.data.startMargin != null) {
}.editable(true) this.startMargin = eventData.data.startMargin;
}, item => item) }
} if (eventData.data.endMargin != null) {
.key('list') this.endMargin = eventData.data.endMargin;
.listDirection(this.listDirection) }
.divider({ strokeWidth: this.strokeWidth, color: this.color, startMargin: this.startMargin, endMargin: this.endMargin }) }
.edgeEffect(this.edgeEffect) }
.chainAnimation(this.chainAnimation)
.multiSelectable(true) build() {
.onScrollIndex((firstIndex: number, lastIndex: number) => { Stack({ alignContent: Alignment.TopStart }) {
console.info('first' + firstIndex) Column() {
console.info('last' + lastIndex) List({ space: 20, initialIndex: 0 }) {
}) ForEach(this.arr, (item) => {
.onScroll((scrollOffset: number, scrollState: ScrollState) => { ListItem() {
console.info('scrollOffset:' + scrollOffset) Text('' + item)
console.info('scrollState:' + scrollState) .width('100%')
}) .height(100)
.editMode(this.editMode) .fontSize(16)
.onItemDelete((index: number) => { .textAlign(TextAlign.Center)
console.info(this.arr[index] + 'Delete') .borderRadius(10)
this.arr.splice(index, 1) .backgroundColor(0xFFFFFF)
console.info(JSON.stringify(this.arr)) }.editable(true)
this.editFlag = false }, item => item)
return true }
}).width('90%') .key('list')
}.width('100%') .listDirection(this.listDirection)
Button('edit list') .divider({
.onClick(() => { strokeWidth: this.strokeWidth,
this.editMode = !this.editMode color: this.color,
}).margin({ top: 5, left: 20 }) startMargin: this.startMargin,
}.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 }) endMargin: this.endMargin
} })
.edgeEffect(this.edgeEffect)
.chainAnimation(this.chainAnimation)
.multiSelectable(true)
.onScrollIndex((firstIndex: number, lastIndex: number) => {
console.info('first' + firstIndex)
console.info('last' + lastIndex)
})
.onScroll((scrollOffset: number, scrollState: ScrollState) => {
console.info('scrollOffset:' + scrollOffset)
console.info('scrollState:' + scrollState)
})
.editMode(this.editMode)
.onItemDelete((index: number) => {
console.info(this.arr[index] + 'Delete')
this.arr.splice(index, 1)
console.info(JSON.stringify(this.arr))
this.editFlag = false
return true
})
.width('90%')
}.width('100%')
Button('edit list')
.onClick(() => {
this.editMode = !this.editMode
}).margin({ top: 5, left: 20 })
}.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
}
} }
\ No newline at end of file
...@@ -44,7 +44,7 @@ struct MarqueeExample { ...@@ -44,7 +44,7 @@ struct MarqueeExample {
.allowScale(false) .allowScale(false)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
.backgroundColor(Color.Black) .backgroundColor(Color.Black)
.margin({bottom:40}) .margin({ bottom: 40 })
.onStart(() => { .onStart(() => {
console.log('Marquee animation complete onStart') console.log('Marquee animation complete onStart')
console.info('Onstart current action state is: ' + this.fontColor); console.info('Onstart current action state is: ' + this.fontColor);
...@@ -125,7 +125,7 @@ struct MarqueeExample { ...@@ -125,7 +125,7 @@ struct MarqueeExample {
}) })
.width(200) .width(200)
.height(60) .height(60)
.margin({bottom:20}) .margin({ bottom: 20 })
} }
.width('100%') .width('100%')
.height('100%') .height('100%')
......
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter' import events_emitter from '@ohos.emitter'
@Entry @Entry
@Component @Component
struct OverlayExample { struct OverlayExample {
@State title: string = 'old title' @State title: string = 'old title'
@State x: number = 0 @State x: number = 0
@State y: number = -15 @State y: number = -15
@State alignment: Alignment = Alignment.Bottom @State alignment: Alignment = Alignment.Bottom
onPageShow() { onPageShow() {
console.info('[overlay] page show called '); console.info('[overlay] page show called ');
var stateChangeEvent = { var stateChangeEvent = {
eventId: 143, eventId: 143,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(stateChangeEvent, this.stateChangCallBack); events_emitter.on(stateChangeEvent, this.stateChangCallBack);
}
var stateChangeEvent2 = {
private stateChangCallBack = (eventData) => { eventId: 1110,
console.info("[stateChangCallBack] stateChangCallBack "); priority: events_emitter.EventPriority.LOW
if (eventData != null) { }
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData)); events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
if (eventData.data.align != null) { }
this.alignment = eventData.data.align
} private stateChangCallBack = (eventData) => {
if (eventData.data.title != null) { console.info("[stateChangCallBack] stateChangCallBack ");
this.title = eventData.data.title if (eventData != null) {
} console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.x != null) { if (eventData.data.align != null) {
this.x = eventData.data.x this.alignment = eventData.data.align
} }
if (eventData.data.y != null) { if (eventData.data.title != null) {
this.y = eventData.data.y this.title = eventData.data.title
} }
if (eventData.data.x != null) {
} this.x = eventData.data.x
} }
if (eventData.data.y != null) {
build() { this.y = eventData.data.y
Column() { }
Column() {
Text('floating layer') }
.fontSize(12).fontColor(0xCCCCCC).maxLines(1) }
Column() {
Image('/images/img.jpeg') build() {
.width(340).height(240) Column() {
.key('overlay') Column() {
.overlay(this.title, Text('floating layer')
{ align: this.alignment, offset: { x: this.x, y: this.y } }) .fontSize(12).fontColor(0xCCCCCC).maxLines(1)
}.border({ color: Color.Black, width: 2 }) Column() {
}.width('100%') Image('/images/img.jpeg')
}.padding({ top: 20 }) .width(340).height(240)
} .key('overlay')
.overlay(this.title,
{ align: this.alignment, offset: { x: this.x, y: this.y } })
}.border({ color: Color.Black, width: 2 })
}.width('100%')
}.padding({ top: 20 })
}
} }
\ No newline at end of file
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter' import events_emitter from '@ohos.emitter'
@Entry @Entry
@Component @Component
struct StepperExample { struct StepperExample {
@State currentIndex: number = 0 @State currentIndex: number = 0
@State firstState: ItemState = ItemState.Normal @State firstState: ItemState = ItemState.Normal
@State secondState: ItemState = ItemState.Normal @State secondState: ItemState = ItemState.Normal
@State disabled: ItemState = ItemState.Normal @State disabled: ItemState = ItemState.Normal
build() { build() {
Stepper({ Stepper({
index: this.currentIndex index: this.currentIndex
}) { }) {
StepperItem() { StepperItem() {
Text('Page One') Text('Page One')
.fontSize(35) .fontSize(35)
.fontColor(Color.Blue) .fontColor(Color.Blue)
.width(200) .width(200)
.lineHeight(50) .lineHeight(50)
.margin({top:250}) .margin({ top: 250 })
} }
.nextLabel('') .nextLabel('')
.position({x: '35%', y: 0}) .position({ x: '35%', y: 0 })
.key('stepperItem1') .key('stepperItem1')
StepperItem() {
Text('Page Two') StepperItem() {
.fontSize(35) Text('Page Two')
.fontColor(Color.Blue) .fontSize(35)
.width(200) .fontColor(Color.Blue)
.lineHeight(50) .width(200)
.margin({top:250}) .lineHeight(50)
.key('text1') .margin({ top: 250 })
.onClick(()=>{ .key('text1')
this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip .onClick(() => {
}) this.firstState = this.firstState === ItemState.Skip ? ItemState.Normal : ItemState.Skip
} })
.nextLabel('Next') }
.prevLabel('Previous') .nextLabel('Next')
.status(this.firstState) .prevLabel('Previous')
.position({x: '35%', y: 0}) .status(this.firstState)
.key('stepperItem2') .position({ x: '35%', y: 0 })
StepperItem() { .key('stepperItem2')
Text('Page Three')
.fontSize(35) StepperItem() {
.fontColor(Color.Blue) Text('Page Three')
.width(200) .fontSize(35)
.lineHeight(50) .fontColor(Color.Blue)
.margin({top:250}) .width(200)
.key('text2') .lineHeight(50)
.onClick(()=>{ .margin({ top: 250 })
this.secondState = this.secondState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting .key('text2')
}) .onClick(() => {
} this.secondState = this.secondState === ItemState.Waiting ? ItemState.Normal : ItemState.Waiting
.position({x: '35%', y: 0}) })
.status(this.secondState) }
.key('stepperItem3') .position({ x: '35%', y: 0 })
StepperItem() { .status(this.secondState)
Text('Page four') .key('stepperItem3')
.fontSize(35)
.fontColor(Color.Blue) StepperItem() {
.width(200) Text('Page four')
.lineHeight(50) .fontSize(35)
.margin({top:250}) .fontColor(Color.Blue)
} .width(200)
.position({x: '35%', y: 0}) .lineHeight(50)
.nextLabel('Finish') .margin({ top: 250 })
.key('stepperItem4') }
} .position({ x: '35%', y: 0 })
.onFinish(() => { .nextLabel('Finish')
console.log('onFinish') .key('stepperItem4')
}) }
.onSkip(() => { .onFinish(() => {
console.log('onSkip') console.log('onFinish')
}) })
.onChange((prevIndex: number, index: number) => { .onSkip(() => {
this.currentIndex = index console.log('onSkip')
}) })
.align(Alignment.Center) .onChange((prevIndex: number, index: number) => {
.key('stepper') this.currentIndex = index
} })
.align(Alignment.Center)
onPageShow() { .key('stepper')
console.info('stepper page show called'); }
var stateChangeEvent = {
eventId: 202, onPageShow() {
priority: events_emitter.EventPriority.LOW console.info('stepper page show called');
} var stateChangeEvent = {
events_emitter.on(stateChangeEvent, this.stateChangCallBack) eventId: 202,
} priority: events_emitter.EventPriority.LOW
}
private stateChangCallBack = (eventData) => { events_emitter.on(stateChangeEvent, this.stateChangCallBack)
console.info("stepper page stateChangCallBack" + JSON.stringify(eventData));
if (eventData != null) { var stateChangeEventTwo = {
console.info("stepper page state change called:" + JSON.stringify(eventData)); eventId: 909,
if(eventData.data.currentIndex != null) { priority: events_emitter.EventPriority.LOW
this.currentIndex = parseInt(eventData.data.currentIndex); }
} events_emitter.on(stateChangeEventTwo, this.stateChangCallBack);
if(eventData.data.disabled != null) {
this.disabled = eventData.data.disabled; var stateChangeEventThree = {
} eventId: 910,
} priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(stateChangeEventThree, this.stateChangCallBack);
}
private stateChangCallBack = (eventData) => {
console.info("stepper page stateChangCallBack" + JSON.stringify(eventData));
if (eventData != null) {
console.info("stepper page state change called:" + JSON.stringify(eventData));
if (eventData.data.currentIndex != null) {
this.currentIndex = parseInt(eventData.data.currentIndex);
}
if (eventData.data.disabled != null) {
this.disabled = eventData.data.disabled;
}
}
}
} }
\ No newline at end of file
...@@ -92,7 +92,7 @@ struct SwiperExample { ...@@ -92,7 +92,7 @@ struct SwiperExample {
.displayMode(this.displayMode) .displayMode(this.displayMode)
.displayCount(this.displayCount) .displayCount(this.displayCount)
.effectMode(this.edgeEffect) .effectMode(this.edgeEffect)
.indicatorStyle({ top: 20, right: 20,size:2,color: Color.Blue}) .indicatorStyle({ top: 20, right: 20, size: 2, color: Color.Blue })
.key('swiper') .key('swiper')
.onChange((index: number) => { .onChange((index: number) => {
console.info(index.toString()) console.info(index.toString())
......
...@@ -68,8 +68,9 @@ struct TextStyle { ...@@ -68,8 +68,9 @@ struct TextStyle {
.fontStyle(FontStyle.Normal) .fontStyle(FontStyle.Normal)
.fontWeight(400) .fontWeight(400)
.fontFamily('source-sans-pro,cursive,sans-serif') .fontFamily('source-sans-pro,cursive,sans-serif')
}.width('100%').margin({top: 20}) }.width('100%').margin({ top: 20 })
} }
onPageShow() { onPageShow() {
let fontColorChangeEvent = { let fontColorChangeEvent = {
eventId: 37, eventId: 37,
...@@ -97,6 +98,7 @@ struct TextStyle { ...@@ -97,6 +98,7 @@ struct TextStyle {
} }
events_emitter.on(fontFamilyChangeEvent, this.textStyleChangCallBack); events_emitter.on(fontFamilyChangeEvent, this.textStyleChangCallBack);
} }
textStyleChangCallBack = (eventData) => { textStyleChangCallBack = (eventData) => {
console.info("textStyle page stateChangCallBack" + JSON.stringify(eventData)); console.info("textStyle page stateChangCallBack" + JSON.stringify(eventData));
if (eventData && eventData.data) { if (eventData && eventData.data) {
......
...@@ -19,7 +19,7 @@ import events_emitter from '@ohos.emitter' ...@@ -19,7 +19,7 @@ import events_emitter from '@ohos.emitter'
@Entry @Entry
@Preview @Preview
@Component @Component
struct TouchExample { struct TouchExample {
@State text: string = '' @State text: string = ''
@State eventType: string = '' @State eventType: string = ''
@State touchFlag: boolean = false @State touchFlag: boolean = false
...@@ -37,13 +37,13 @@ struct TouchExample { ...@@ -37,13 +37,13 @@ struct TouchExample {
console.info("[touch] page stateChangCallBack"); console.info("[touch] page stateChangCallBack");
if (eventData != null) { if (eventData != null) {
console.info("[touch] page state change called:" + JSON.stringify(eventData)); console.info("[touch] page state change called:" + JSON.stringify(eventData));
if(eventData.data.text != null) { if (eventData.data.text != null) {
this.text = eventData.data.text; this.text = eventData.data.text;
} }
if(eventData.data.eventType != null) { if (eventData.data.eventType != null) {
this.eventType = eventData.data.eventType; this.eventType = eventData.data.eventType;
} }
if(eventData.data.touchFlag != null) { if (eventData.data.touchFlag != null) {
this.touchFlag = eventData.data.touchFlag this.touchFlag = eventData.data.touchFlag
} }
} }
...@@ -51,7 +51,10 @@ struct TouchExample { ...@@ -51,7 +51,10 @@ struct TouchExample {
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.SpaceBetween }) {
Button('Touch').backgroundColor(0x2788D9).height(40).width(80) Button('Touch')
.backgroundColor(0x2788D9)
.height(40)
.width(80)
.key('touch') .key('touch')
.onTouch((event: Touch) => { .onTouch((event: Touch) => {
if (event.type === TouchType.Down) { if (event.type === TouchType.Down) {
...@@ -72,7 +75,7 @@ struct TouchExample { ...@@ -72,7 +75,7 @@ struct TouchExample {
stopPropagation: () => { stopPropagation: () => {
console.info('stopPropagation') console.info('stopPropagation')
} }
console.info('onTouch successful, touchFlag is : ' + this.eventType + ', ' +this.touchFlag) console.info('onTouch successful, touchFlag is : ' + this.eventType + ', ' + this.touchFlag)
console.info(this.text = 'TouchType:' + this.eventType console.info(this.text = 'TouchType:' + this.eventType
+ '\nDistance between touch point and touch element:\nx: ' + '\nDistance between touch point and touch element:\nx: '
+ event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\ncomponent globalPos:(' + event.touches[0].x + '\n' + 'y: ' + event.touches[0].y + '\ncomponent globalPos:('
...@@ -84,7 +87,7 @@ struct TouchExample { ...@@ -84,7 +87,7 @@ struct TouchExample {
+ event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\nwidth:' + event.target.area.globalPos.x + ',' + event.target.area.globalPos.y + ')\nwidth:'
+ event.target.area.width + '\nheight:' + event.target.area.height) + event.target.area.width + '\nheight:' + event.target.area.height)
console.log('fang--->A') console.log('fang--->A')
try{ try {
console.log('fang--->B') console.log('fang--->B')
var backData = { var backData = {
data: { data: {
...@@ -99,7 +102,7 @@ struct TouchExample { ...@@ -99,7 +102,7 @@ struct TouchExample {
console.log('fang--->D') console.log('fang--->D')
console.info("touchFlag start to emit action state") console.info("touchFlag start to emit action state")
events_emitter.emit(backEvent, backData) events_emitter.emit(backEvent, backData)
}catch{ } catch {
console.info("touchFlag emit action state err: " + JSON.stringify(err.message)) console.info("touchFlag emit action state err: " + JSON.stringify(err.message))
} }
}) })
......
...@@ -23,7 +23,6 @@ struct TouchAbleExample { ...@@ -23,7 +23,6 @@ struct TouchAbleExample {
@State text1: string = ''; @State text1: string = '';
@State text2: string = ''; @State text2: string = '';
@State touchableValue: boolean = false; @State touchableValue: boolean = false;
private stateChangCallBack = (eventData) => { private stateChangCallBack = (eventData) => {
console.info("[TouchAble] page stateChangCallBack"); console.info("[TouchAble] page stateChangCallBack");
if (eventData != null) { if (eventData != null) {
...@@ -46,13 +45,17 @@ struct TouchAbleExample { ...@@ -46,13 +45,17 @@ struct TouchAbleExample {
build() { build() {
Stack() { Stack() {
Rect() Rect()
.fill(Color.Gray).width(150).height(150) .fill(Color.Gray)
.width(150)
.height(150)
.onClick(() => { .onClick(() => {
console.info(this.text1 = 'Rect Clicked') console.info(this.text1 = 'Rect Clicked')
}) })
.overlay(this.text1, { align: Alignment.Bottom, offset: { x: 0, y: 20 } }) .overlay(this.text1, { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
Ellipse() Ellipse()
.fill(Color.Pink).width(150).height(80) .fill(Color.Pink)
.width(150)
.height(80)
.key('ellipse') .key('ellipse')
.touchable(this.touchableValue) .touchable(this.touchableValue)
.onClick(() => { .onClick(() => {
......
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter'; import events_emitter from '@ohos.emitter';
@Entry @Entry
@Component @Component
struct VisibilityExample { struct VisibilityExample {
@State visibility: Visibility = Visibility.Visible; @State visibility: Visibility = Visibility.Visible;
onPageShow() { onPageShow() {
let hiddenChangeEvent = { let hiddenChangeEvent = {
eventId: 47, eventId: 47,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(hiddenChangeEvent, this.hiddenChangCallBack) events_emitter.on(hiddenChangeEvent, this.hiddenChangCallBack)
let noneChangeEvent = { let noneChangeEvent = {
eventId: 48, eventId: 48,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(noneChangeEvent, this.noneChangCallBack) events_emitter.on(noneChangeEvent, this.noneChangCallBack)
}
var stateChangeEvent2 = {
private hiddenChangCallBack = (eventData) => { eventId: 1116,
console.info("[hiddenChangCallBack] stateChangCallBack"); priority: events_emitter.EventPriority.LOW
if (eventData != null) { }
console.info("[hiddenChangCallBack] state change called:" + JSON.stringify(eventData)); events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
if(eventData.data.visibility != null) { }
this.visibility = eventData.data.visibility;
} private hiddenChangCallBack = (eventData) => {
} console.info("[hiddenChangCallBack] stateChangCallBack");
} if (eventData != null) {
console.info("[hiddenChangCallBack] state change called:" + JSON.stringify(eventData));
private noneChangCallBack = (eventData) => { if (eventData.data.visibility != null) {
console.info("[noneChangCallBack] stateChangCallBack"); this.visibility = eventData.data.visibility;
if (eventData != null) { }
console.info("[noneChangCallBack] state change called:" + JSON.stringify(eventData)); }
if(eventData.data.visibility != null) { }
this.visibility = eventData.data.visibility; private noneChangCallBack = (eventData) => {
} console.info("[noneChangCallBack] stateChangCallBack");
} if (eventData != null) {
} console.info("[noneChangCallBack] state change called:" + JSON.stringify(eventData));
if (eventData.data.visibility != null) {
build() { this.visibility = eventData.data.visibility;
Column() { }
Column() { }
Text('BoxOne').fontSize(9).width('90%').fontColor(0xCCCCCC) }
Row().visibility(this.visibility).width('90%').height(80).backgroundColor(0xAFEEEE).padding(20).key('box')
build() {
Text('BoxTwo').fontSize(9).width('90%').fontColor(0xCCCCCC) Column() {
Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE).padding(20) Column() {
}.width('90%').border({ width: 1 }) Text('BoxOne').fontSize(9).width('90%').fontColor(0xCCCCCC)
}.width('100%').margin({ top: 5 }) Row()
} .visibility(this.visibility)
} .width('90%')
.height(80)
.backgroundColor(0xAFEEEE)
.padding(20)
.key('box')
Text('BoxTwo').fontSize(9).width('90%').fontColor(0xCCCCCC)
Row()
.visibility(Visibility.Visible)
.width('90%')
.height(80)
.backgroundColor(0xAFEEEE)
.padding(20)
}.width('90%').border({ width: 1 })
}.width('100%').margin({ top: 5 })
}
}
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import events_emitter from '@ohos.emitter' import events_emitter from '@ohos.emitter'
@Entry @Entry
@Component @Component
struct zIndexExample { struct zIndexExample {
@State zIndex: number = 1; @State zIndex: number = 1;
onPageShow() { onPageShow() {
console.info('[zIndex] page show called '); console.info('[zIndex] page show called ');
var stateChangeEvent = { var stateChangeEvent = {
eventId: 236, eventId: 236,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
events_emitter.on(stateChangeEvent, this.stateChangCallBack); events_emitter.on(stateChangeEvent, this.stateChangCallBack);
} var stateChangeEvent2 = {
eventId: 1113,
private stateChangCallBack = (eventData) => { priority: events_emitter.EventPriority.LOW
console.info("[stateChangCallBack] stateChangCallBack "); }
if (eventData != null) { events_emitter.on(stateChangeEvent2, this.stateChangCallBack);
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
if (eventData.data.zIndex != null) { }
this.zIndex = eventData.data.zIndex
} private stateChangCallBack = (eventData) => {
} console.info("[stateChangCallBack] stateChangCallBack ");
} if (eventData != null) {
console.info("[stateChangCallBack] state change called: " + JSON.stringify(eventData));
build() { if (eventData.data.zIndex != null) {
Column() { this.zIndex = eventData.data.zIndex
Stack() { }
Text('first child, zIndex(2)') }
.size({ width: '40%', height: '60%' }).backgroundColor(0xbbb2cb) }
.zIndex(2)
Text('second child, default zIndex(0)') build() {
.size({ width: '90%', height: '80%' }).backgroundColor(0xd2cab3).align(Alignment.TopStart) Column() {
Text('third child, zIndex(1)') Stack() {
.size({ width: '70%', height: '50%' }) Text('first child, zIndex(2)')
.backgroundColor(0xc1cbac) .size({ width: '40%', height: '60%' }).backgroundColor(0xbbb2cb)
.align(Alignment.TopStart) .zIndex(2)
.zIndex(this.zIndex) Text('second child, default zIndex(0)')
.key('zIndex') .size({ width: '90%', height: '80%' }).backgroundColor(0xd2cab3).align(Alignment.TopStart)
} Text('third child, zIndex(1)')
}.width('100%').height(200) .size({ width: '70%', height: '50%' })
} .backgroundColor(0xc1cbac)
.align(Alignment.TopStart)
.zIndex(this.zIndex)
.key('zIndex')
}
}.width('100%').height(200)
}
} }
\ No newline at end of file
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets" import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router'; import router from '@system.router';
import events_emitter from '@ohos.events.emitter' import events_emitter from '@ohos.events.emitter'
import Utils from './Utils'; import Utils from './Utils.ets';
export default function appearJsunit() {
describe('appInfoTest', function () { export default function appearJsunit() {
beforeEach(async function (done) { describe('appearTest', function () {
console.info("appear beforeEach start"); beforeEach(async function (done) {
let options = { console.info("appear beforeEach start");
uri: 'pages/appear', let options = {
} uri: 'pages/appear',
let result; }
try { let result;
router.clear(); try {
let pages = router.getState(); router.clear();
console.info("get appear state pages: " + JSON.stringify(pages)); let pages = router.getState();
if (!("appear" == pages.name)) { console.info("get appear state pages: " + JSON.stringify(pages));
console.info("get appear state pages.name: " + JSON.stringify(pages.name)); if (!("appear" == pages.name)) {
result = await router.push(options); console.info("get appear state pages.name: " + JSON.stringify(pages.name));
await Utils.sleep(2000); result = await router.push(options);
console.info("push appear page result: " + JSON.stringify(result)); await Utils.sleep(2000);
} console.info("push appear page result: " + JSON.stringify(result));
} catch (err) { }
console.error("push appear page error: " + err); } catch (err) {
} console.error("push appear page error: " + err);
done() }
}); done()
});
afterEach(async function () {
await Utils.sleep(1000); afterEach(async function () {
console.info("appear after each called"); await Utils.sleep(1000);
}) console.info("appear after each called");
})
it('testAppear01', 0, async function (done) {
console.info('[testAppear01] START'); it('testAppear01', 0, async function (done) {
await Utils.sleep(1000); console.info('[testAppear01] START');
try { await Utils.sleep(1000);
let callBackAppear = (backData) => { try {
console.info("testAppear01 get appearEvent result is: " + JSON.stringify(appearEvent)); let callBackAppear = (backData) => {
expect(backData.data.ACTION).assertEqual(true); console.info("testAppear01 get appearEvent result is: " + JSON.stringify(appearEvent));
} expect(backData.data.ACTION).assertEqual(true);
var appearEvent = { }
eventId: 58, var appearEvent = {
priority: events_emitter.EventPriority.LOW eventId: 58,
} priority: events_emitter.EventPriority.LOW
events_emitter.on(appearEvent, callBackAppear); }
} catch (err) { events_emitter.on(appearEvent, callBackAppear);
console.info("testAppear01 on appearEvent err : " + JSON.stringify(err)); } catch (err) {
} console.info("testAppear01 on appearEvent err : " + JSON.stringify(err));
console.info("testAppear01 click result is: " + JSON.stringify(sendEventByKey('appear', 10, ""))); }
console.info('[testAppear01] END'); console.info("testAppear01 click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
done(); console.info('[testAppear01] END');
}); done();
});
it('testAppear02', 0, async function (done) {
console.info('[testAppear02] START'); it('testAppear02', 0, async function (done) {
await Utils.sleep(1000); console.info('[testAppear02] START');
try { await Utils.sleep(1000);
let callBackAppear = (backData) => { try {
console.info("testAppear02 get appearEvent result is: " + JSON.stringify(appearEvent)); let callBackAppear = (backData) => {
expect(backData.data.ACTION).assertEqual(true); console.info("testAppear02 get appearEvent result is: " + JSON.stringify(appearEvent));
} expect(backData.data.ACTION).assertEqual(true);
var appearEvent = { }
eventId: 59, var appearEvent = {
priority: events_emitter.EventPriority.LOW eventId: 59,
} priority: events_emitter.EventPriority.LOW
events_emitter.on(appearEvent, callBackAppear); }
} catch (err) { events_emitter.on(appearEvent, callBackAppear);
console.info("testAppear02 on appearEvent err : " + JSON.stringify(err)); } catch (err) {
} console.info("testAppear02 on appearEvent err : " + JSON.stringify(err));
console.info("testAppear02 appearEvent click result is: " + JSON.stringify(sendEventByKey('appear', 10, ""))); }
console.info("testAppear02 appearEvent click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
try {
let callBackDisAppear = (backData) => { try {
console.info("testAppear02 get disAppearEvent result is: " + JSON.stringify(disAppearEvent)); let callBackDisAppear = (backData) => {
expect(backData.data.ACTION).assertEqual(true); console.info("testAppear02 get disAppearEvent result is: " + JSON.stringify(disAppearEvent));
} expect(backData.data.ACTION).assertEqual(true);
var disAppearEvent = { }
eventId: 60, var disAppearEvent = {
priority: events_emitter.EventPriority.LOW eventId: 60,
} priority: events_emitter.EventPriority.LOW
events_emitter.on(disAppearEvent, callBackDisAppear); }
} catch (err) { events_emitter.on(disAppearEvent, callBackDisAppear);
console.info("testAppear02 on disAppearEvent err : " + JSON.stringify(err)); } catch (err) {
} console.info("testAppear02 on disAppearEvent err : " + JSON.stringify(err));
console.info("testAppear02 disAppearEvent click result is: " + JSON.stringify(sendEventByKey('appear', 10, ""))); }
console.info('[testAppear02] END'); console.info("testAppear02 disAppearEvent click result is: " + JSON.stringify(sendEventByKey('appear', 10, "")));
done(); console.info('[testAppear02] END');
}); done();
});
})
} })
}
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets" import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router'; import router from '@system.router';
import events_emitter from '@ohos.events.emitter' import events_emitter from '@ohos.events.emitter'
import Utils from './Utils'; import Utils from './Utils.ets';
export default function areaChangeJsunit() {
describe('areaChange', function () { export default function areaChangeJsunit() {
beforeEach(async function (done) { describe('areaChangeTest', function () {
let options = { beforeEach(async function (done) {
uri: 'pages/areaChange', let options = {
} uri: 'pages/areaChange',
try { }
router.clear(); try {
let pages = router.getState(); router.clear();
console.info("get areaChange state success " + JSON.stringify(pages)); let pages = router.getState();
if (!("areaChange" == pages.name)) { console.info("get areaChange state success " + JSON.stringify(pages));
console.info("get areaChange state success " + JSON.stringify(pages.name)); if (!("areaChange" == pages.name)) {
let result = await router.push(options); console.info("get areaChange state success " + JSON.stringify(pages.name));
await Utils.sleep(1000); let result = await router.push(options);
console.info("push areaChange page success " + JSON.stringify(result)); await Utils.sleep(1000);
} console.info("push areaChange page success " + JSON.stringify(result));
} catch (err) { }
console.error("push areaChange page error: " + err); } catch (err) {
} console.error("push areaChange page error: " + err);
done() }
}); done()
});
afterEach(async function () {
await Utils.sleep(1000); afterEach(async function () {
console.info("areaChange after each called"); await Utils.sleep(1000);
}); console.info("areaChange after each called");
});
it('areaChangeTest_0100', 0, async function (done) {
console.info('areaChangeTest_0100 START'); it('areaChangeTest_0100', 0, async function (done) {
let strJson = getInspectorByKey('text1'); console.info('areaChangeTest_0100 START');
console.info("areaChangeTest_0100 component strJson:" + strJson); let strJson = getInspectorByKey('text1');
let obj = JSON.parse(strJson); console.info("areaChangeTest_0100 component strJson:" + strJson);
console.info("areaChangeTest_0100 component obj is: " + JSON.stringify(obj)); let obj = JSON.parse(strJson);
expect(obj.$type).assertEqual('Text'); console.info("areaChangeTest_0100 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('42.000000'); expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.height).assertEqual('23.000000'); expect(obj.$attrs.width).assertEqual('42.000000');
console.info('areaChangeTest_0100 END'); expect(obj.$attrs.height).assertEqual('23.000000');
done(); console.info('areaChangeTest_0100 END');
}); done();
});
it('areaChangeTest_0200', 0, async function (done) {
console.info('areaChangeTest_0200 START'); it('areaChangeTest_0200', 0, async function (done) {
let strJson = getInspectorByKey('text2'); console.info('areaChangeTest_0200 START');
console.info("areaChangeTest_0200 component strJson:" + strJson); let strJson = getInspectorByKey('text2');
let obj = JSON.parse(strJson); console.info("areaChangeTest_0200 component strJson:" + strJson);
console.info("areaChangeTest_0200 component obj is: " + JSON.stringify(obj)); let obj = JSON.parse(strJson);
expect(obj.$type).assertEqual('Text'); console.info("areaChangeTest_0200 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('519.000000'); expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.height).assertEqual('140.000000'); expect(obj.$attrs.width).assertEqual('519.000000');
console.info('areaChangeTest_0200 END'); expect(obj.$attrs.height).assertEqual('210.000000');
done(); console.info('areaChangeTest_0200 END');
}); done();
});
it('areaChangeTest_0300', 0, async function (done) {
console.info('areaChangeTest_0300 START'); it('areaChangeTest_0300', 0, async function (done) {
await Utils.sleep(1000); console.info('areaChangeTest_0300 START');
let callback = (indexEvent) => { await Utils.sleep(1000);
console.info("areaChangeTest_0300 get state result is: " + JSON.stringify(indexEvent)); let callback = (indexEvent) => {
expect(indexEvent.data.value).assertEqual('TextText'); console.info("areaChangeTest_0300 get state result is: " + JSON.stringify(indexEvent));
} expect(indexEvent.data.value).assertEqual('TextText');
let indexEvent = { }
eventId: 61, let indexEvent = {
priority: events_emitter.EventPriority.LOW eventId: 61,
} priority: events_emitter.EventPriority.LOW
try { }
events_emitter.on(indexEvent, callback); try {
} catch (err) { events_emitter.on(indexEvent, callback);
console.info("areaChangeTest_0300 on events_emitter err : " + JSON.stringify(err)); } catch (err) {
} console.info("areaChangeTest_0300 on events_emitter err : " + JSON.stringify(err));
console.info("areaChangeTest_0300 click result is: " + JSON.stringify(sendEventByKey('text1', 10, ""))); }
var innerEventOne = { console.info("areaChangeTest_0300 click result is: " + JSON.stringify(sendEventByKey('text1', 10, "")));
eventId: 62, var innerEventOne = {
priority: events_emitter.EventPriority.LOW eventId: 62,
} priority: events_emitter.EventPriority.LOW
await Utils.sleep(1500); }
var callback1 = (eventData) => { await Utils.sleep(1500);
console.info("areaChangeTest_0300 get event state result is: " + JSON.stringify(eventData)); var callback1 = (eventData) => {
expect(eventData.data.ACTION).assertEqual(true); console.info("areaChangeTest_0300 get event state result is: " + JSON.stringify(eventData));
} expect(eventData.data.ACTION).assertEqual(true);
try { }
events_emitter.on(innerEventOne, callback1); try {
} catch (err) { events_emitter.on(innerEventOne, callback1);
console.info("areaChangeTest_0300 on events_emitter err : " + JSON.stringify(err)); } catch (err) {
} console.info("areaChangeTest_0300 on events_emitter err : " + JSON.stringify(err));
console.info('areaChangeTest_0300 END'); }
done(); console.info('areaChangeTest_0300 END');
}); done();
});
it('areaChangeTest_0400', 0, async function (done) {
console.info('areaChangeTest_0400 START'); it('areaChangeTest_0400', 0, async function (done) {
await Utils.sleep(1000); console.info('areaChangeTest_0400 START');
let callback = (indexEvent) => { await Utils.sleep(1000);
console.info("areaChangeTest_0400 get state result is: " + JSON.stringify(indexEvent)); let callback = (indexEvent) => {
expect(indexEvent.data.value).assertEqual('TextTextText'); console.info("areaChangeTest_0400 get state result is: " + JSON.stringify(indexEvent));
} expect(indexEvent.data.value).assertEqual('TextTextText');
let indexEvent = { }
eventId: 62, let indexEvent = {
priority: events_emitter.EventPriority.LOW eventId: 62,
} priority: events_emitter.EventPriority.LOW
try { }
events_emitter.on(indexEvent, callback); try {
} catch (err) { events_emitter.on(indexEvent, callback);
console.info("areaChangeTest_0400 on events_emitter err : " + JSON.stringify(err)); } catch (err) {
} console.info("areaChangeTest_0400 on events_emitter err : " + JSON.stringify(err));
console.info("areaChangeTest_0400 click result is: " + JSON.stringify(sendEventByKey('text1',10,""))); }
console.info('areaChangeTest_0400 END'); console.info("areaChangeTest_0400 click result is: " + JSON.stringify(sendEventByKey('text1', 10, "")));
done(); console.info('areaChangeTest_0400 END');
}); done();
}) });
} })
}
// @ts-nocheck
/**
* Copyright (c) 2021 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 {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets";
import router from '@system.router';
import events_emitter from '@ohos.events.emitter';
import Utils from './Utils.ets';
export default function columnJsunit() {
describe('columnTest', function () {
beforeEach(async function (done) {
console.info("column beforeEach start");
let options = {
uri: 'pages/column',
}
try {
router.clear();
let pages = router.getState();
console.info("get column state pages:" + JSON.stringify(pages));
if (!("column" == pages.name)) {
console.info("get column state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push column page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push column page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("column after each called");
});
it('testColumn01', 0, async function (done) {
console.info('[testColumn01] START');
await Utils.sleep(1000);
let strJson = getInspectorByKey('alignItemsColumn');
let obj = JSON.parse(strJson);
console.info("[testColumn01] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.alignItems).assertEqual('HorizontalAlign.Start');
console.info('[testColumn01] END');
done();
});
it('testColumn02', 0, async function (done) {
console.info('[testColumn02] START');
try {
var eventData = {
data: {
"alignItems":HorizontalAlign.Center
}
}
var innerEvent = {
eventId: 192,
priority: events_emitter.EventPriority.LOW
}
console.info("[testColumn02] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testColumn02] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('alignItemsColumn');
let obj = JSON.parse(strJson);
console.info("[testColumn02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.alignItems).assertEqual('HorizontalAlign.Center');
console.info('[testColumn02] END');
done();
});
})
}
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"; import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets";
import router from '@system.router'; import router from '@system.router';
import events_emitter from '@ohos.events.emitter'; import events_emitter from '@ohos.events.emitter';
import Utils from './Utils'; import Utils from './Utils.ets';
export default function ellipseJsunit() { export default function ellipseJsunit() {
describe('appInfoTest', function () { describe('ellipseTest', function () {
beforeEach(async function (done) { beforeEach(async function (done) {
console.info("ellipse beforeEach start"); console.info("ellipse beforeEach start");
let options = { let options = {
uri: 'pages/ellipse', uri: 'pages/ellipse',
} }
try { try {
router.clear(); router.clear();
let pages = router.getState(); let pages = router.getState();
console.info("get ellipse state pages:" + JSON.stringify(pages)); console.info("get ellipse state pages:" + JSON.stringify(pages));
if (!("ellipse" == pages.name)) { if (!("ellipse" == pages.name)) {
console.info("get ellipse state pages.name:" + JSON.stringify(pages.name)); console.info("get ellipse state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options); let result = await router.push(options);
await Utils.sleep(2000); await Utils.sleep(2000);
console.info("push ellipse page result:" + JSON.stringify(result)); console.info("push ellipse page result:" + JSON.stringify(result));
} }
} catch (err) { } catch (err) {
console.error("push ellipse page error:" + err); console.error("push ellipse page error:" + err);
} }
done() done()
}); });
afterEach(async function () { afterEach(async function () {
await Utils.sleep(1000); await Utils.sleep(1000);
console.info("ellipse after each called"); console.info("ellipse after each called");
}); });
it('testEllipse01', 0, async function (done) { it('testEllipse01', 0, async function (done) {
console.info('[testEllipse01] START'); console.info('[testEllipse01] START');
await Utils.sleep(1000); await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse'); let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testEllipse02] obj is: " + JSON.stringify(obj)); console.info("[testEllipse02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('200.00px'); expect(obj.$attrs.height).assertEqual('200.00px');
expect(obj.$attrs.width).assertEqual('200.00px'); expect(obj.$attrs.width).assertEqual('200.00px');
console.info('testEllipse02 END'); console.info('testEllipse02 END');
done(); done();
}); });
it('testEllipse02', 0, async function (done) { it('testEllipse02', 0, async function (done) {
console.info('[testEllipse02] START'); console.info('[testEllipse02] START');
try { try {
var eventData = { var eventData = {
data: { data: {
"width": '100px' "width": '100px'
} }
} }
var innerEvent = { var innerEvent = {
eventId: 92, eventId: 92,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
console.info("[testEllipse02] start to publish emit"); console.info("[testEllipse02] start to publish emit");
events_emitter.emit(innerEvent, eventData); events_emitter.emit(innerEvent, eventData);
} catch (err) { } catch (err) {
console.log("[testEllipse02] change component data error: " + err.message); console.log("[testEllipse02] change component data error: " + err.message);
} }
await Utils.sleep(1000); await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse'); let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testEllipse02] obj is: " + JSON.stringify(obj)); console.info("[testEllipse02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('100.00px'); expect(obj.$attrs.width).assertEqual('100.00px');
console.info('testEllipse02 END'); console.info('testEllipse02 END');
done(); done();
}); });
it('testEllipse03', 0, async function (done) { it('testEllipse03', 0, async function (done) {
console.info('[testEllipse03] START'); console.info('[testEllipse03] START');
try { try {
var eventData = { var eventData = {
data: { data: {
"height": '500px' "height": '500px'
} }
} }
var innerEvent = { var innerEvent = {
eventId: 92, eventId: 92,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
console.info("[testEllipse03] start to publish emit"); console.info("[testEllipse03] start to publish emit");
events_emitter.emit(innerEvent, eventData); events_emitter.emit(innerEvent, eventData);
} catch (err) { } catch (err) {
console.log("[testEllipse03] change component data error: " + err.message); console.log("[testEllipse03] change component data error: " + err.message);
} }
await Utils.sleep(1000); await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse'); let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testEllipse03] obj is: " + JSON.stringify(obj)); console.info("[testEllipse03] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('500.00px'); expect(obj.$attrs.height).assertEqual('500.00px');
console.info('testEllipse03 END'); console.info('testEllipse03 END');
done(); done();
}); });
})
} it('testEllipse04', 0, async function (done) {
console.info('[testEllipse04] START');
try {
var eventData = {
data: {
"width": '1111111111111'
}
}
var innerEvent = {
eventId: 907,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse04] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse04] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse04] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('1111111111111.00px');
console.info('testEllipse04 END');
done();
});
it('testEllipse05', 0, async function (done) {
console.info('[testEllipse05] START');
try {
var eventData = {
data: {
"height": '12111111111111'
}
}
var innerEvent = {
eventId: 907,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse05] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse05] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse05] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('12111111111111.00px');
console.info('testEllipse05 END');
done();
});
it('testEllipse06', 0, async function (done) {
console.info('[testEllipse06] START');
try {
var eventData = {
data: {
"height": '-40'
}
}
var innerEvent = {
eventId: 908,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse06] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse06] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse06] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.height).assertEqual('-40.00px');
console.info('testEllipse06 END');
done();
});
it('testEllipse07', 0, async function (done) {
console.info('[testEllipse07] START');
try {
var eventData = {
data: {
"width": '-10'
}
}
var innerEvent = {
eventId: 908,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEllipse07] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEllipse07] change component data error: " + err.message);
}
await Utils.sleep(1000);
let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson);
console.info("[testEllipse07] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.width).assertEqual('-10.00px');
console.info('testEllipse07 END');
done();
});
})
}
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets" import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router'; import router from '@system.router';
import events_emitter from '@ohos.events.emitter' import events_emitter from '@ohos.events.emitter'
import Utils from './Utils'; import Utils from './Utils.ets';
export default function enableJsunit() {
export default function enableJsunit() { describe('enableTest', function () {
describe('appInfoTest', function () { beforeEach(async function (done) {
beforeEach(async function (done) { console.info("enable beforeEach start");
console.info("enable beforeEach start"); let options = {
let options = { uri: 'pages/enable',
uri: 'pages/enable', }
} try {
try { router.clear();
router.clear(); let pages = router.getState();
let pages = router.getState(); console.info("get enable state pages: " + JSON.stringify(pages));
console.info("get enable state pages: " + JSON.stringify(pages)); if (!("enable" == pages.name)) {
if (!("enable" == pages.name)) { console.info("get enable state pages.name:" + JSON.stringify(pages.name));
console.info("get enable state pages.name:" + JSON.stringify(pages.name)); let result = await router.push(options);
let result = await router.push(options); await Utils.sleep(2000);
await Utils.sleep(2000); console.info("push enable page result:" + JSON.stringify(result));
console.info("push enable page result:" + JSON.stringify(result)); }
} } catch (err) {
} catch (err) { console.error("push enable page error:" + err);
console.error("push enable page error:" + err); }
} done()
done() });
});
afterEach(async function () {
afterEach(async function () { await Utils.sleep(1000);
await Utils.sleep(1000); console.info("enable after each called");
console.info("enable after each called"); });
});
it('testEnable01', 0, async function (done) {
it('testEnable01', 0, async function (done) { console.info('[testEnable01] START');
console.info('[testEnable01] START'); await Utils.sleep(1000);
await Utils.sleep(1000); let strJson = getInspectorByKey('enabled');
let strJson = getInspectorByKey('enabled'); let obj = JSON.parse(strJson);
let obj = JSON.parse(strJson); console.info("[testEnable01] obj is: " + JSON.stringify(obj));
console.info("[testEnable01] obj is: " + JSON.stringify(obj)); expect(obj.$attrs.enabled).assertEqual(true);
expect(obj.$attrs.enabled).assertEqual(true); console.info('[testEnable01] END');
console.info('[testEnable01] END'); done();
done(); });
});
it('testEnable02', 0, async function (done) {
it('testEnable02', 0, async function (done) { console.info('[testEnable02] START');
console.info('[testEnable02] START'); try {
try { var eventData = {
var eventData = { data: {
data: { "enabled": false,
"enabled": false, "text": "disable"
"text": "disable" }
} }
} var innerEvent = {
var innerEvent = { eventId: 93,
eventId: 93, priority: events_emitter.EventPriority.LOW
priority: events_emitter.EventPriority.LOW }
} console.info("[testEnable02] start to publish emit");
console.info("[testEnable02] start to publish emit"); events_emitter.emit(innerEvent, eventData);
events_emitter.emit(innerEvent, eventData); } catch (err) {
} catch (err) { console.log("[testEnable02] change component data error: " + err.message);
console.log("[testEnable02] change component data error: " + err.message); }
} await Utils.sleep(2000);
await Utils.sleep(2000); let strJson = getInspectorByKey('enabled');
let strJson = getInspectorByKey('enabled'); let obj = JSON.parse(strJson);
let obj = JSON.parse(strJson); console.info("[testEnable02] obj is: " + JSON.stringify(obj.$attrs.enabled));
console.info("[testEnable02] obj is: " + JSON.stringify(obj.$attrs.enabled)); expect(obj.$attrs.enabled).assertEqual(false);
expect(obj.$attrs.enabled).assertEqual(false); console.info('testEnable02 END');
console.info('testEnable02 END'); done();
done(); });
});
}) it('testEnable03', 0, async function (done) {
} console.info('[testEnable03] START');
try {
var eventData = {
data: {
"enabled": -3
}
}
var innerEvent = {
eventId: 1111,
priority: events_emitter.EventPriority.LOW
}
console.info("[testEnable03] start to publish emit");
events_emitter.emit(innerEvent, eventData);
} catch (err) {
console.log("[testEnable03] change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJson = getInspectorByKey('enabled');
let obj = JSON.parse(strJson);
console.info("[testEnable03] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.enabled).assertEqual(true);
console.info('testEnable03 END');
done();
});
it('testEnable04', 0, async function (done) {
console.info('testEnable04 START');
try {
let eventData = {
data: {
"enabled": 33567444
}
}
let indexEvent = {
eventId: 1111,
priority: events_emitter.EventPriority.LOW
}
console.info("testEnable04 start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("testEnable04 change component data error: " + err.message);
}
await Utils.sleep(2000);
let strJsonNew = getInspectorByKey('enabled');
let objNew = JSON.parse(strJsonNew);
console.info("testEnable04 component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.enabled).assertEqual(true);
done();
});
})
}
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets" import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router'; import router from '@system.router';
import Utils from './Utils'; import Utils from './Utils.ets';
export default function globalJsunit() { export default function globalJsunit() {
describe('globalJsunit', function () { describe('globalJsunit', function () {
...@@ -50,7 +50,7 @@ export default function globalJsunit() { ...@@ -50,7 +50,7 @@ export default function globalJsunit() {
* @tc.desc Test setTimeout * @tc.desc Test setTimeout
*/ */
it('ACE_global_setTimeout', 0, function (done) { it('ACE_global_setTimeout', 0, function (done) {
let caseName:string = "ACE_global_setTimeout" let caseName: string = "ACE_global_setTimeout"
console.info(`${caseName} START`); console.info(`${caseName} START`);
setTimeout(() => { setTimeout(() => {
expect(true).assertTrue(); expect(true).assertTrue();
...@@ -65,9 +65,9 @@ export default function globalJsunit() { ...@@ -65,9 +65,9 @@ export default function globalJsunit() {
* @tc.desc Test canIUse * @tc.desc Test canIUse
*/ */
it('ACE_global_canIUse', 0, function (done) { it('ACE_global_canIUse', 0, function (done) {
let caseName:string = "ACE_global_canIUse" let caseName: string = "ACE_global_canIUse"
console.info(`${caseName} START`); console.info(`${caseName} START`);
let syscapName:string = ""; let syscapName: string = "";
var result = canIUse(syscapName); var result = canIUse(syscapName);
expect(result === false).assertTrue(); expect(result === false).assertTrue();
console.info(`${caseName} END`); console.info(`${caseName} END`);
...@@ -80,11 +80,12 @@ export default function globalJsunit() { ...@@ -80,11 +80,12 @@ export default function globalJsunit() {
* @tc.desc Test getApp * @tc.desc Test getApp
*/ */
it('ACE_global_getApp', 0, function (done) { it('ACE_global_getApp', 0, function (done) {
let caseName:string = "ACE_global_getApp" let caseName: string = "ACE_global_getApp"
console.info(`${caseName} START`); console.info(`${caseName} START`);
try{ try {
var info = getApp(); var info = getApp();
}catch(err){} } catch (err) {
}
console.info(`${caseName} END`); console.info(`${caseName} END`);
done(); done();
}); });
...@@ -95,11 +96,12 @@ export default function globalJsunit() { ...@@ -95,11 +96,12 @@ export default function globalJsunit() {
* @tc.desc Test createLocalParticleAbility * @tc.desc Test createLocalParticleAbility
*/ */
it('ACE_global_createLocalParticleAbility', 0, function (done) { it('ACE_global_createLocalParticleAbility', 0, function (done) {
let caseName:string = "ACE_global_createLocalParticleAbility" let caseName: string = "ACE_global_createLocalParticleAbility"
console.info(`${caseName} START`); console.info(`${caseName} START`);
try{ try {
var info = createLocalParticleAbility(100); var info = createLocalParticleAbility(100);
}catch(err){} } catch (err) {
}
console.info(`${caseName} END`); console.info(`${caseName} END`);
done(); done();
}); });
...@@ -166,6 +168,5 @@ export default function globalJsunit() { ...@@ -166,6 +168,5 @@ export default function globalJsunit() {
}); });
}) })
} }
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets" import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router'; import router from '@system.router';
import events_emitter from '@ohos.events.emitter'; import events_emitter from '@ohos.events.emitter';
import Utils from './Utils'; import Utils from './Utils.ets';
export default function girdContainerJsunit() { export default function girdContainerJsunit() {
describe('appInfoTest', function () { describe('girdContainerTest', function () {
beforeEach(async function (done) { beforeEach(async function (done) {
console.info("girdContainer beforeEach start"); console.info("girdContainer beforeEach start");
let options = { let options = {
uri: 'pages/gridContainer', uri: 'pages/gridContainer',
} }
try { try {
router.clear(); router.clear();
let pages = router.getState(); let pages = router.getState();
console.info("get girdContainer state pages:" + JSON.stringify(pages)); console.info("get girdContainer state pages:" + JSON.stringify(pages));
if (!("gridContainer" == pages.name)) { if (!("gridContainer" == pages.name)) {
console.info("get girdContainer state pages.name:" + JSON.stringify(pages.name)); console.info("get girdContainer state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options); let result = await router.push(options);
await Utils.sleep(2000); await Utils.sleep(2000);
console.info("push girdContainer page result:" + JSON.stringify(result)); console.info("push girdContainer page result:" + JSON.stringify(result));
} }
} catch (err) { } catch (err) {
console.error("push girdContainer page error:" + err); console.error("push girdContainer page error:" + err);
} }
done() done()
}); });
afterEach(async function () { afterEach(async function () {
await Utils.sleep(1000); await Utils.sleep(1000);
console.info("girdContainer after each called"); console.info("girdContainer after each called");
}); });
it('testGirdContainer01', 0, async function (done) { it('testGirdContainer01', 0, async function (done) {
console.info('[testGirdContainer01] START'); console.info('[testGirdContainer01] START');
await Utils.sleep(1000); await Utils.sleep(1000);
let strJson = getInspectorByKey('gridContainer'); let strJson = getInspectorByKey('gridContainer');
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testGirdContainer01] obj is: " + JSON.stringify(obj)); console.info("[testGirdContainer01] obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('GridContainer'); expect(obj.$type).assertEqual('GridContainer');
expect(obj.$attrs.constructor.columns).assertEqual('12'); expect(obj.$attrs.constructor.columns).assertEqual('12');
expect(obj.$attrs.constructor.sizeType).assertEqual('SizeType.XS'); expect(obj.$attrs.constructor.sizeType).assertEqual('SizeType.XS');
expect(obj.$attrs.constructor.gutter).assertEqual('10.00vp'); expect(obj.$attrs.constructor.gutter).assertEqual('10.00vp');
expect(obj.$attrs.constructor.margin).assertEqual('20.00vp'); expect(obj.$attrs.constructor.margin).assertEqual('20.00vp');
console.info('testGirdContainer01 END'); console.info('testGirdContainer01 END');
done(); done();
}); });
it('testGirdContainer02', 0, async function (done) { it('testGirdContainer02', 0, async function (done) {
console.info('[testEllipse02] START'); console.info('[testEllipse02] START');
try { try {
var eventData = { var eventData = {
data: { data: {
"sizeType": 'SM' "sizeType": 'SM'
} }
} }
var innerEvent = { var innerEvent = {
eventId: 109, eventId: 109,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
console.info("[testGirdContainer02] start to publish emit"); console.info("[testGirdContainer02] start to publish emit");
events_emitter.emit(innerEvent, eventData); events_emitter.emit(innerEvent, eventData);
} catch (err) { } catch (err) {
console.log("[testGirdContainer02] change component data error: " + err.message); console.log("[testGirdContainer02] change component data error: " + err.message);
} }
await Utils.sleep(1000); await Utils.sleep(1000);
let strJson = getInspectorByKey('gridContainer'); let strJson = getInspectorByKey('gridContainer');
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testGirdContainer02] obj is: " + JSON.stringify(obj)); console.info("[testGirdContainer02] obj is: " + JSON.stringify(obj));
expect(obj.$attrs.constructor.sizeType).assertEqual('SizeType.SM'); expect(obj.$attrs.constructor.sizeType).assertEqual('SizeType.SM');
console.info('testGirdContainer02 END'); console.info('testGirdContainer02 END');
done(); done();
}); });
}) })
} }
// @ts-nocheck // @ts-nocheck
/** /**
* Copyright (c) 2021 Huawei Device Co., Ltd. * Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets" import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from "deccjsunit/index.ets"
import router from '@system.router'; import router from '@system.router';
import events_emitter from '@ohos.events.emitter'; import events_emitter from '@ohos.events.emitter';
import Utils from './Utils.ets'; import Utils from './Utils.ets';
export default function layoutConstraintsJsunit() { export default function layoutConstraintsJsunit() {
describe('layoutConstraintsTest', function () { describe('layoutConstraintsTest', function () {
beforeEach(async function (done) { beforeEach(async function (done) {
console.info("layoutConstraints beforeEach start"); console.info("layoutConstraints beforeEach start");
let options = { let options = {
uri: 'pages/layoutConstraints', uri: 'pages/layoutConstraints',
} }
try { try {
router.clear(); router.clear();
let pages = router.getState(); let pages = router.getState();
console.info("get layoutConstraints state pages:" + JSON.stringify(pages)); console.info("get layoutConstraints state pages:" + JSON.stringify(pages));
if (!("layoutConstraints" == pages.name)) { if (!("layoutConstraints" == pages.name)) {
console.info("get layoutConstraints state pages.name:" + JSON.stringify(pages.name)); console.info("get layoutConstraints state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options); let result = await router.push(options);
await Utils.sleep(2000); await Utils.sleep(2000);
console.info("push layoutConstraints page result:" + JSON.stringify(result)); console.info("push layoutConstraints page result:" + JSON.stringify(result));
} }
} catch (err) { } catch (err) {
console.error("push layoutConstraints page error:" + err); console.error("push layoutConstraints page error:" + err);
} }
done() done()
}); });
afterEach(async function () { afterEach(async function () {
await Utils.sleep(1000); await Utils.sleep(1000);
console.info("layoutConstraints after each called"); console.info("layoutConstraints after each called");
}); });
it('testLayoutConstraints001', 0, async function (done) { it('testLayoutConstraints001', 0, async function (done) {
console.info('[testLayoutConstraints001] START'); console.info('[testLayoutConstraints001] START');
await Utils.sleep(1000); await Utils.sleep(1000);
let strJson = getInspectorByKey('aspectRatio'); let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints001] component strJson:" + strJson); console.info("[testLayoutConstraints001] component strJson:" + strJson);
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints001] aspectRatio: " + obj.$attrs.aspectRatio); console.info("[testLayoutConstraints001] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(1.5); expect(obj.$attrs.aspectRatio).assertEqual(1.5);
done(); done();
}); });
it('testLayoutConstraints002', 0, async function (done) { it('testLayoutConstraints002', 0, async function (done) {
console.info('[testLayoutConstraints002] START'); console.info('[testLayoutConstraints002] START');
try { try {
let eventData = { let eventData = {
data: { data: {
"aspectRatio": 2 "aspectRatio": 2
} }
} }
let indexEvent = { let indexEvent = {
eventId: 20, eventId: 20,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
console.info("[testLayoutConstraints002] start to publish emit"); console.info("[testLayoutConstraints002] start to publish emit");
events_emitter.emit(indexEvent, eventData); events_emitter.emit(indexEvent, eventData);
} catch (err) { } catch (err) {
console.log("[testLayoutConstraints002] change component data error: " + err.message); console.log("[testLayoutConstraints002] change component data error: " + err.message);
} }
await Utils.sleep(4000); await Utils.sleep(4000);
let strJson = getInspectorByKey('aspectRatio'); let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints002] component strJson:" + strJson); console.info("[testLayoutConstraints002] component strJson:" + strJson);
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints002] aspectRatio: " + obj.$attrs.aspectRatio); console.info("[testLayoutConstraints002] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(2); expect(obj.$attrs.aspectRatio).assertEqual(2);
done(); done();
}); });
it('testLayoutConstraints003', 0, async function (done) { it('testLayoutConstraints003', 0, async function (done) {
console.info('[testLayoutConstraints003] START'); console.info('[testLayoutConstraints003] START');
await Utils.sleep(1000); await Utils.sleep(1000);
let strJson = getInspectorByKey('displayPriority'); let strJson = getInspectorByKey('displayPriority');
console.info("[testLayoutConstraints003] component strJson:" + strJson); console.info("[testLayoutConstraints003] component strJson:" + strJson);
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints003] displayPriority: " + obj.$attrs.displayPriority); console.info("[testLayoutConstraints003] displayPriority: " + obj.$attrs.displayPriority);
expect(obj.$attrs.displayPriority).assertEqual(1); expect(obj.$attrs.displayPriority).assertEqual(1);
done(); done();
}); });
it('testLayoutConstraints004', 0, async function (done) { it('testLayoutConstraints004', 0, async function (done) {
console.info('[testLayoutConstraints004] START'); console.info('[testLayoutConstraints004] START');
try { try {
let eventData = { let eventData = {
data: { data: {
"displayPriority": 5 "displayPriority": 5
} }
} }
let indexEvent = { let indexEvent = {
eventId: 21, eventId: 21,
priority: events_emitter.EventPriority.LOW priority: events_emitter.EventPriority.LOW
} }
console.info("[testLayoutConstraints004] start to publish emit"); console.info("[testLayoutConstraints004] start to publish emit");
events_emitter.emit(indexEvent, eventData); events_emitter.emit(indexEvent, eventData);
} catch (err) { } catch (err) {
console.log("[testLayoutConstraints004] change component data error: " + err.message); console.log("[testLayoutConstraints004] change component data error: " + err.message);
} }
await Utils.sleep(4000); await Utils.sleep(4000);
let strJson = getInspectorByKey('displayPriority'); let strJson = getInspectorByKey('displayPriority');
console.info("[testLayoutConstraints004] component strJson:" + strJson); console.info("[testLayoutConstraints004] component strJson:" + strJson);
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints004] displayPriority: " + obj.$attrs.displayPriority); console.info("[testLayoutConstraints004] displayPriority: " + obj.$attrs.displayPriority);
expect(obj.$attrs.displayPriority).assertEqual(5); expect(obj.$attrs.displayPriority).assertEqual(5);
done(); done();
}); });
});
it('testLayoutConstraints005', 0, async function (done) {
console.info('[testLayoutConstraints005] START');
try {
let eventData = {
data: {
"aspectRatio": -4
}
}
let indexEvent = {
eventId: 1112,
priority: events_emitter.EventPriority.LOW
}
console.info("[testLayoutConstraints005] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testLayoutConstraints005] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints005] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints005] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(-4);
done();
});
it('testLayoutConstraints006', 0, async function (done) {
console.info('[testLayoutConstraints006] START');
try {
let eventData = {
data: {
"aspectRatio": 9997077
}
}
let indexEvent = {
eventId: 1112,
priority: events_emitter.EventPriority.LOW
}
console.info("[testLayoutConstraints006] start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("[testLayoutConstraints006] change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJson = getInspectorByKey('aspectRatio');
console.info("[testLayoutConstraints006] component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("[testLayoutConstraints006] aspectRatio: " + obj.$attrs.aspectRatio);
expect(obj.$attrs.aspectRatio).assertEqual(9997077);
done();
});
});
} }
\ No newline at end of file
...@@ -51,7 +51,7 @@ export default function touchAbleJsunit() { ...@@ -51,7 +51,7 @@ export default function touchAbleJsunit() {
let strJson = getInspectorByKey('ellipse'); let strJson = getInspectorByKey('ellipse');
let obj = JSON.parse(strJson); let obj = JSON.parse(strJson);
console.info("[testTouchAble001] component obj is: " + JSON.stringify(obj)); console.info("[testTouchAble001] component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.focusable).assertEqual(false); expect(obj.$attrs.focusable).assertEqual(true);
done(); done();
}); });
......
...@@ -19,21 +19,22 @@ import events_emitter from '@ohos.emitter' ...@@ -19,21 +19,22 @@ import events_emitter from '@ohos.emitter'
@Component @Component
struct ParentComp { struct ParentComp {
@State isCountDown: boolean = true @State isCountDown: boolean = true
build() { build() {
Column() { Column() {
Text(this.isCountDown ? 'Count Down' : 'Stopwatch') Text(this.isCountDown ? 'Count Down' : 'Stopwatch')
if (this.isCountDown) { if (this.isCountDown) {
Image($rawfile('ic_health_heart.png')).width(50).height(50) Image($rawfile('ic_health_heart.png')).width(50).height(50)
TimerComponent({counter: 10, changePerSec: -1, showInColor: Color.Red}) TimerComponent({ counter: 10, changePerSec: -1, showInColor: Color.Red })
} else { } else {
Image($rawfile('ic_health_heart.png')).width(150).height(150) Image($rawfile('ic_health_heart.png')).width(150).height(150)
TimerComponent({counter: 0, changePerSec: +1, showInColor: Color.Black }) TimerComponent({ counter: 0, changePerSec: +1, showInColor: Color.Black })
} }
Button(this.isCountDown ? 'Swtich to Stopwatch' : 'Switch to Count Down') Button(this.isCountDown ? 'Swtich to Stopwatch' : 'Switch to Count Down')
.onClick(() => { .onClick(() => {
this.isCountDown = !this.isCountDown this.isCountDown = !this.isCountDown
}) })
.key('button1') .key('button1')
} }
} }
} }
...@@ -43,8 +44,8 @@ struct TimerComponent { ...@@ -43,8 +44,8 @@ struct TimerComponent {
@State counter: number = 0 @State counter: number = 0
private changePerSec: number = -1 private changePerSec: number = -1
private showInColor: Color = Color.Black private showInColor: Color = Color.Black
private timerId : number = -1 private timerId: number = -1
@State onActionCalled :boolean = false @State onActionCalled: boolean = false
build() { build() {
Text(`${this.counter}sec`) Text(`${this.counter}sec`)
...@@ -52,7 +53,9 @@ struct TimerComponent { ...@@ -52,7 +53,9 @@ struct TimerComponent {
} }
aboutToAppear() { aboutToAppear() {
this.timerId = setInterval(() => {this.counter += this.changePerSec}, 1000) this.timerId = setInterval(() => {
this.counter += this.changePerSec
}, 1000)
} }
aboutToDisappear() { aboutToDisappear() {
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
import file from '@system.file'; import file from '@system.file';
import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets"; import {Core, ExpectExtend, InstrumentLog, ReportExtend} from "deccjsunit/index.ets";
import testsuite from "../test/List.test.ets"; import testsuite from "../test/List.test.ets";
import featureAbility from "@ohos.ability.featureAbility"; import featureAbility from "@ohos.ability.featureAbility";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册