提交 89d49bcb 编写于 作者: Z zhangrao

add compnent

Signed-off-by: Nzhangrao <zhangrao@huawei.com>
上级 0d90f453
......@@ -83,7 +83,7 @@ struct CanvasExample {
this.getBitImageSize();
})
.key('canvas1')
}.width('100%').height('400%')
}.width('100%').height('350%')
}.scrollable(ScrollDirection.Vertical).scrollBar(BarState.On)
.scrollBarColor(Color.Gray).scrollBarWidth(10)
}
......
......@@ -35,8 +35,8 @@ struct Canvas2Example {
this.transferFromImageBitmap();
this.offScreenToDataURL();
})
.key('canvas1')
}.width('100%').height('400%')
.key('canvas2')
}.width('100%').height('100%')
}.scrollable(ScrollDirection.Vertical).scrollBar(BarState.On)
.scrollBarColor(Color.Gray).scrollBarWidth(10)
}
......
/**
* 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 Canvas3Example {
private settings: RenderingContextSettings = new RenderingContextSettings(true);
private context: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
build() {
Flex({ direction: FlexDirection.Row, alignItems: ItemAlign.Start, justifyContent: FlexAlign.Start }) {
Column() {
Canvas(this.context)
.width('100%')
.height('100%')
.backgroundColor('#ffff00')
.onReady(() => {
this.rotate();
})
.key('canvas3')
}.width('100%').height('100%')
}
.width('100%')
.height('100%')
}
onPageShow() {
}
rotate() {
this.context.rotate(45 * Math.PI / 180);
this.context.fillRect(200, 20, 100, 100);
}
}
\ No newline at end of file
// @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 GestureSettingsExample {
@State value: string = ''
build() {
Column() {
Text('Click\n' + this.value).gesture(TapGesture()
.onAction(() => {
this.value = 'gesture onAction'
try {
var backData = {
data: {
"value": this.value
}
}
var backEvent = {
eventId: 199,
priority: events_emitter.EventPriority.LOW
}
console.info("click to emit action state")
events_emitter.emit(backEvent, backData)
} catch (err) {
console.info("click action state err: " + JSON.stringify(err.message))
}
})
)
.key('tapGesture')
}
.key('parallelGesture')
.height(200).width(300).padding(60).border({ width: 1 }).margin(30)
.priorityGesture(
TapGesture()
.onAction(() => {
this.value = 'parallelGesture onAction'
}), GestureMask.IgnoreInternal
)
}
}
\ No newline at end of file
// @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 GestureSettingsExample {
@State value: string = ''
build() {
Column() {
Text('Click\n' + this.value).gesture(TapGesture()
.onAction(() => {
this.value = 'gesture onAction'
try {
var backData = {
data: {
"value": this.value
}
}
var backEvent = {
eventId: 111,
priority: events_emitter.EventPriority.LOW
}
console.info("click to emit action state")
events_emitter.emit(backEvent, backData)
} catch (err) {
console.info("click action state err: " + JSON.stringify(err.message))
}
})
)
.key('tapGesture')
}
.height(200).width(300).padding(60).border({ width: 1 }).margin(30)
.priorityGesture(
TapGesture()
.onAction(() => {
this.value = 'priorityGesture onAction'
}), GestureMask.IgnoreInternal
)
}
}
\ No newline at end of file
......@@ -24,10 +24,6 @@ struct TextExample {
.fontSize(this.fontSize)
.fontColor(0xCCCCCC)
.key('text')
Text($r('app.string.string_hello'))
.fontColor($r('app.color.color_hello'))
.fontSize($r('app.float.font_hello'))
.key('text1')
Image($rawfile('test.png'))
.key('image')
}
......
/**
* 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 TransitionExample {
@State btn1: boolean = false
@State show: string = "show"
@State onActionCalled: boolean = false
@State transitionTypeOne: TransitionType = TransitionType.Insert
@State transitionTypeTwo: TransitionType = TransitionType.Delete
build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center,}) {
Button(this.show).width(80).height(30).backgroundColor(0x317aff).margin({bottom:50}).key('button')
.onClick(() => {
this.onActionCalled = true;
try {
var backData = {
data: {
"btn1": this.btn1,
}
}
var backEvent = {
eventId: 333,
priority: events_emitter.EventPriority.LOW
}
console.info("transitionTest_0200 start to emit action state")
events_emitter.emit(backEvent, backData)
} catch (err) {
console.info("transitionTest_0200 emit action state err: " + JSON.stringify(err.message))
}
animateTo({ duration: 3000 }, () => {
this.btn1 = !this.btn1
if(this.btn1){
this.show = "hide"
}else{
this.show = "show"
}
})
})
if (this.btn1) {
Button() {
Image($r('app.media.bg')).width("80%").height(300).key('image')
}.transition({ type: this.transitionTypeOne, scale: {x:0,y:1.0} }).key('button1')
.transition({ type: this.transitionTypeTwo, scale: { x: 1.0, y: 0.0 } })
}
}.height(400).width("100%").padding({top:100})
}
}
\ No newline at end of file
// @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 Utils from './Utils';
export default function canvasJsunit() {
describe('canvas3Test', function () {
beforeEach(async function (done) {
console.info("canvas3 beforeEach start");
let options = {
uri: 'pages/canvas3',
}
try {
router.clear();
let pages = router.getState();
console.info("get canvas3 state pages:" + JSON.stringify(pages));
if (!("canvas3" == pages.name)) {
console.info("get canvas3 state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push canvas3 page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push canvas3 page error:" + err);
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("canvas3 after each called");
});
it('testCanvas01', 0, async function (done) {
console.info('[testCanvas01] START');
await Utils.sleep(1000);
console.info('[testCanvas01]----------- START');
console.info('testCanvas01 END');
done();
});
});
}
......@@ -64,7 +64,10 @@ import toggleJsunit from './ToggleJsunit.test.ets';
import shapeJsunit from './ShapeJsunit.test.ets'
import motionPathJsunit from './MotionPathJsunit.test.ets';
import scrollCodeJsunit from './ScrollCodeJsunit.test.ets';
import canvas3Jsunit from './Canvas3Jsunit.test.ets';
import transitionJsunit from './TransitionJsunit.test.ets';
import priorityGestureJsunit from './PriorityGestureJsunit.test.ets';
import parallelGestureJsunit from './ParallelGestureJsunit.test.ets';
export default function testsuite() {
gaugeJsunit();
......@@ -102,6 +105,7 @@ export default function testsuite() {
badgeJsunit();
canvasJsunit();
canvas2Jsunit();
canvas3Jsunit();
longPressGestureJsUnit();
buttonJsunit();
responseRegionJsunit();
......@@ -119,4 +123,7 @@ export default function testsuite() {
motionPathJsunit();
columnJsunit();
scrollCodeJsunit();
transitionJsunit();
priorityGestureJsunit();
parallelGestureJsunit();
}
\ No newline at end of file
// @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 Utils from './Utils';
import events_emitter from '@ohos.events.emitter';
export default function parallelGestureJsunit() {
describe('parallelGestureTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/parallelGesture',
}
try {
router.clear();
let pages = router.getState();
console.info("get parallelGesture state success " + JSON.stringify(pages));
if (!("parallelGesture" == pages.name)) {
console.info("get parallelGesture state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(1000);
console.info("push parallelGesture page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push parallelGesture page error " + JSON.stringify(result));
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("parallelGesture after each called");
});
it('parallelGestureTest_0100', 0, async function (done) {
await Utils.sleep(1000)
let rect = await Utils.getComponentRect('tapGesture')
console.info("parallelGestureTest_0100 rectInfo is " + JSON.stringify(rect));
let x_value = rect.left + (rect.right - rect.left) / 2;
let y_value = rect.top + (rect.bottom - rect.top) / 2;
console.info("parallelGestureTest_0100 onTouch location is: " + "[x]=== " + x_value + " [y]===" + y_value);
let point: TouchObject = { id: 11, x: x_value, y: y_value, type: TouchType.DOWN}
var callback = (eventData) => {
console.info("parallelGestureTest_0100 get event state result is: " + JSON.stringify(eventData));
expect(eventData.data.value).assertEqual('gesture onAction')
}
var innerEvent = {
eventId: 199,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(innerEvent, callback)
} catch (err) {
console.info("parallelGestureTest_0100 on events_emitter err : " + JSON.stringify(err));
}
console.info('parallelGestureTest_0100 sendTouchEvent result:' + sendTouchEvent(point));
await Utils.sleep(1000)
console.info('parallelGestureTest_0100 testSendTouchEvent END');
done();
});
})
}
\ No newline at end of file
// @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 Utils from './Utils';
import events_emitter from '@ohos.events.emitter';
export default function priorityGestureJsunit() {
describe('PriorityGestureTest', function () {
beforeEach(async function (done) {
let options = {
uri: 'pages/priorityGesture',
}
try {
router.clear();
let pages = router.getState();
console.info("get priorityGesture state success " + JSON.stringify(pages));
if (!("priorityGesture" == pages.name)) {
console.info("get priorityGesture state success " + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(1000);
console.info("push priorityGesture page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push priorityGesture page error " + JSON.stringify(result));
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("priorityGesture after each called");
});
it('priorityGestureTest_0100', 0, async function (done) {
await Utils.sleep(1000)
let rect = await Utils.getComponentRect('tapGesture')
console.info("priorityGestureTest_0100 rectInfo is " + JSON.stringify(rect));
let x_value = rect.left + (rect.right - rect.left) / 2;
let y_value = rect.top + (rect.bottom - rect.top) / 2;
console.info("priorityGestureTest_0100 onTouch location is: " + "[x]=== " + x_value + " [y]===" + y_value);
let point: TouchObject = { id: 11, x: x_value, y: y_value, type: TouchType.Move}
var callback = (eventData) => {
console.info("priorityGestureTest_0100 get event state result is: " + JSON.stringify(eventData));
expect(eventData.data.value).assertEqual('gesture onAction')
}
var innerEvent = {
eventId: 111,
priority: events_emitter.EventPriority.LOW
}
try {
events_emitter.on(innerEvent, callback)
} catch (err) {
console.info("priorityGestureTest_0100 on events_emitter err : " + JSON.stringify(err));
}
console.info('priorityGestureTest_0100 sendTouchEvent one:' + sendTouchEvent(point));
await Utils.sleep(1000)
console.info('priorityGestureTest_0100 testSendTouchEvent END');
done();
});
})
}
\ No newline at end of file
......@@ -60,57 +60,22 @@ export default function textJsunit() {
it('testText_0200', 0, async function (done) {
console.info('testText_0200 START');
let strJson = getInspectorByKey('text1');
let strJson = getInspectorByKey('image');
console.info("testText_0200 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("testText_0200 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.fontSize).assertEqual('28.000000px');
console.info('testText_0200 END');
done();
});
it('testText_0300', 0, async function (done) {
console.info('testText_0300 START');
let strJson = getInspectorByKey('text1');
console.info("testText_0300 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("testText_0300 component obj is: " + JSON.stringify(obj));
expect(obj.$attrs.content).assertEqual('Hello');
console.info('testText_0300 END');
done();
});
it('testText_0400', 0, async function (done) {
console.info('testText_0400 START');
let strJson = getInspectorByKey('text1');
console.info("testText_0400 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("testText_0400 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Text');
expect(obj.$attrs.fontColor).assertEqual('#FFFF0000');
console.info('testText_0400 END');
done();
});
it('testText_0500', 0, async function (done) {
console.info('testText_0500 START');
let strJson = getInspectorByKey('image');
console.info("testText_0500 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("testText_0500 component obj is: " + JSON.stringify(obj));
var res = obj.$attrs.src.indexOf('rawfile/test.png');
console.info("testText_0500 result is: " + res);
console.info("testText_0200 result is: " + res);
var sres = obj.$attrs.src.slice(res,res + 16);
console.info("testText_0500 slice result is: " + sres);
console.info("testText_0200 slice result is: " + sres);
expect(obj.$type).assertEqual('Image');
expect(obj.$attrs.src.slice(res,res + 16)).assertEqual('rawfile/test.png');
console.info('testText_0500 END');
console.info('testText_0200 END');
done();
});
it('testText_0600', 0, async function (done) {
console.info('testText_0600 START');
it('testText_0300', 0, async function (done) {
console.info('testText_0300 START');
try {
let eventData = {
data: {
......@@ -121,17 +86,17 @@ export default function textJsunit() {
eventId: 60,
priority: events_emitter.EventPriority.LOW
}
console.info("testText_0600 start to publish emit");
console.info("testText_0300 start to publish emit");
events_emitter.emit(indexEvent, eventData);
} catch (err) {
console.log("testText_0600 change component data error: " + err.message);
console.log("testText_0300 change component data error: " + err.message);
}
await Utils.sleep(4000);
let strJsonNew = getInspectorByKey('text');
let objNew = JSON.parse(strJsonNew);
console.info("testText_0600 component objNew is: " + JSON.stringify(objNew));
console.info("testText_0300 component objNew is: " + JSON.stringify(objNew));
expect(objNew.$attrs.fontSize).assertEqual('10.000000fp');
console.info('testText_0600 END');
console.info('testText_0300 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';
export default function transitionJsunit() {
describe('appInfoTest', function () {
beforeEach(async function (done) {
console.info("text beforeEach start");
let options = {
uri: 'pages/transition',
}
try {
router.clear();
let pages = router.getState();
console.info("get transition state pages:" + JSON.stringify(pages));
if (!("transition" == pages.name)) {
console.info("get transition state pages.name:" + JSON.stringify(pages.name));
let result = await router.push(options);
await Utils.sleep(2000);
console.info("push transition page result:" + JSON.stringify(result));
}
} catch (err) {
console.error("push transition page error:" + JSON.stringify(result));
}
done()
});
afterEach(async function () {
await Utils.sleep(1000);
console.info("transition after each called");
});
it('transitionTest_0100', 0, async function (done) {
console.info('transitionTest_0100 START');
let strJson = getInspectorByKey('button');
console.info("transitionTest_0100 component strJson:" + strJson);
let obj = JSON.parse(strJson);
console.info("transitionTest_0100 component obj is: " + JSON.stringify(obj));
expect(obj.$type).assertEqual('Button');
expect(obj.$attrs.opacity).assertEqual(1);
console.info('transitionTest_0100 END');
done();
});
it('transitionTest_0200', 0, async function (done) {
console.info('transitionTest_0200 START');
let indexEvent = {
eventId: 333,
priority: events_emitter.EventPriority.LOW
}
await Utils.sleep(1000);
let callback = (indexEvent) => {
console.info("transitionTest_0200 get state result is: " + JSON.stringify(indexEvent));
expect(indexEvent.data.btn1).assertEqual(false);
}
try {
events_emitter.on(indexEvent, callback);
} catch (err) {
console.info("transitionTest_0200 on events_emitter err : " + JSON.stringify(err));
}
console.info("transitionTest_0200 click result is: " + JSON.stringify(sendEventByKey('button',10,"")));
await Utils.sleep(1000);
console.info('transitionTest_0200 END');
done();
});
})
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册