未验证 提交 0db11e41 编写于 作者: O openharmony_ci 提交者: Gitee

!9650 提供获取组件绘制区域坐标和大小的能力xts回退后修改与提交

Merge pull request !9650 from huangdong/getcomponentfix
......@@ -13,7 +13,7 @@
* limitations under the License.
*/
import componentUtils from '@ohos.componentUtils';
import componentUtils from '@ohos.arkui.componentUtils';
@Entry
@Component
......
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Entry
@Component
struct getcomponentadd {
private scroller: Scroller = new Scroller()
private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
@State Number: String[] = ['0', '1', '2', '3', '4']
@State message: string = 'Hello World'
build() {
Row() {
Column() {
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.key('ArkUX_Get_component_add_0010')
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.width('35%')
.height('5%')
Checkbox({name: 'checkbox1', group: 'checkboxGroup'})
.select(true)
.selectedColor(0xed6f21)
.position({x:100,y:100})
.key('ArkUX_Get_component_add_0020')
Image($r('app.media.icon'))
.width(110).height(110).border({ width: 1 }).borderStyle(BorderStyle.Dashed)
.overlay('png', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
.position({x:200,y:200})
.key('ArkUX_Get_component_add_0030')
Text('Radio1')
Radio({ value: 'Radio1', group: 'radioGroup' }).checked(true)
.height(50)
.width(50)
.position({x:300,y:300})
.key('ArkUX_Get_component_add_0040')
Scroll(this.scroller) {
Flex({ direction: FlexDirection.Column }) {
ForEach(this.arr, (item) => {
Row() {
Text(item.toString())
.width('80%')
.height(60)
.backgroundColor('#3366CC')
.borderRadius(15)
.fontSize(16)
.textAlign(TextAlign.Center)
.margin({ top: 5 })
}
}, item => item)
}.margin({ right: 15 })
}
.width('90%')
.scrollBar(BarState.Off)
.scrollable(ScrollDirection.Vertical)
ScrollBar({ scroller: this.scroller, direction: ScrollBarDirection.Vertical,state: BarState.Auto }) {
Text()
.width(20)
.height(100)
.borderRadius(10)
.backgroundColor('#C0C0C0')
}.width(20).backgroundColor('#ededed')
.position({x:400,y:400})
.key('ArkUX_Get_component_add_0050')
Select([{value:'aaa'},{value:'bbb'},{value:'ccc'}])
.selected(2)
.value('TTTTT')
.font({ size: 16, weight: 500 })
.fontColor('#182431')
.selectedOptionFont({ size: 16, weight: 400 })
.optionFont({ size: 16, weight: 400 })
.position({x:500,y:500})
.key('ArkUX_Get_component_add_0060')
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.position({x:600,y:600})
.key('ArkUX_Get_component_add_0070')
Grid() {
ForEach(this.Number, (day: string) => {
ForEach(this.Number, (day: string) => {
GridItem() {
Text(day)
.fontSize(16)
.backgroundColor(0xF9CF93)
.width('100%')
.height('100%')
.textAlign(TextAlign.Center)
}
}, day => day)
}, day => day)
}
.columnsTemplate('1fr 1fr 1fr 1fr 1fr')
.rowsTemplate('1fr 1fr 1fr 1fr 1fr')
.columnsGap(10)
.rowsGap(10)
.width('90%')
.backgroundColor(0xFAEEE0)
.height(300)
.position({x:700,y:700})
.key('ArkUX_Get_component_add_0080')
List({ space: 20, initialIndex: 0 }) {
ForEach(this.arr, (item) => {
ListItem() {
Text('' + item)
.width('100%').height(100).fontSize(16)
.textAlign(TextAlign.Center).borderRadius(10).backgroundColor(0xFFFFFF)
}
}, item => item)
}
.position({x:800,y:800})
.key('ArkUX_Get_component_add_0090')
.listDirection(Axis.Vertical)
.divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 })
.edgeEffect(EdgeEffect.Spring)
.onScrollIndex((firstIndex: number, lastIndex: number) => {
console.info('first' + firstIndex)
console.info('last' + lastIndex)
})
.width('90%')
TextInput({ placeholder: 'input your password...' })
.width(400)
.height(40)
.margin(20)
.type(InputType.Password)
.maxLength(9)
.showPasswordIcon(true)
.position({x:900,y:900})
.key('ArkUX_Get_component_add_0100')
Button() {
Text('next page')
.fontSize(20)
.fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule)
.key('ArkUX_Get_component_add_0110')
}.width('100%')
}.height('100%')
}
}
\ No newline at end of file
......@@ -38,7 +38,9 @@ import assemblyCallbackTest from './assemblyCallback.test';
import ActsGridTest from './Grid.test';
import ActsListTest from './Listitem.test';
import ActsSwiperTest from './Swiper.test';
import ActsRichEditorTest from './richeditor.test'
import ActsRichEditorTest from './richeditor.test';
import ActsgetcomponentTest from './getcomponent.test';
import ActsgetcomponentaddTest from './getcomponentadd.test';
export default function testsuite() {
......@@ -68,4 +70,6 @@ export default function testsuite() {
ActsListTest()
ActsSwiperTest()
ActsRichEditorTest()
ActsgetcomponentTest()
ActsgetcomponentaddTest()
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import componentRect from '@ohos.componentUtils'
import componentRect from '@ohos.arkui.componentUtils'
export default class Utils {
......
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import hilog from '@ohos.hilog';
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
import Utils from './common/Utils'
import router from '@system.router';
import componentUtils from '@ohos.arkui.componentUtils';
export default function ActsgetcomponentaddTest() {
describe('ActsgetcomponentaddTest', function () {
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
beforeAll(function () {
// Presets an action, which is performed only once before all test cases of the test suite start.
// This API supports only one parameter: preset action function.
})
beforeEach(async function (done) {
console.info("flex beforeEach start");
let options = {
uri: 'TestAbility/pages/getcomponentadd',
}
try {
router.clear();
let pages = router.getState();
console.info("get getcomponentadd state success " + JSON.stringify(pages));
if (!("getcomponentadd" == pages.name)) {
console.info("get getcomponentadd state success " + JSON.stringify(pages.name));
let result = await router.push(options);
console.info("push getcomponentadd page success " + JSON.stringify(result));
}
} catch (err) {
console.error("push getcomponentadd page error: " + err);
}
done()
});
afterEach(function () {
// Presets a clear action, which is performed after each unit test case ends.
// The number of execution times is the same as the number of test cases defined by **it**.
// This API supports only one parameter: clear action function.
})
afterAll(function () {
// Presets a clear action, which is performed after all test cases of the test suite end.
// This API supports only one parameter: clear action function.
})
it('ArkUX_Get_component_add_0010', 0, async function (done) {
console.info('ArkUX_Get_component_add_0010 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0010');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0010 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0010 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0020', 0, async function (done) {
console.info('ArkUX_Get_component_add_0020 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0020');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0020 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0020 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0030', 0, async function (done) {
console.info('ArkUX_Get_component_add_0030 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0030');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0030 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0030 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0040', 0, async function (done) {
console.info('ArkUX_Get_component_add_0040 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0040');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0040 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0040 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0050', 0, async function (done) {
console.info('ArkUX_Get_component_add_0050 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0050');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0050 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0050 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0060', 0, async function (done) {
console.info('ArkUX_Get_component_add_0060 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0060');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0060 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0060 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0070', 0, async function (done) {
console.info('ArkUX_Get_component_add_0070 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0070');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0070 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0070 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0080', 0, async function (done) {
console.info('ArkUX_Get_component_add_0080 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0080');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0080 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0080 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0090', 0, async function (done) {
console.info('ArkUX_Get_component_add_0090 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0090');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0090 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0090 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0100', 0, async function (done) {
console.info('ArkUX_Get_component_add_0100 START');
setTimeout(()=>{
try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_add_0100');
expect(typeof(strJson.width)).assertEqual("number");
expect(typeof(strJson.height)).assertEqual("number");
expect(typeof(strJson.localOffsetX)).assertEqual("number");
expect(typeof(strJson.localOffsetY)).assertEqual("number");
expect(typeof(strJson.windowOffsetX)).assertEqual("number");
expect(typeof(strJson.windowOffsetY)).assertEqual("number");
expect(typeof(strJson.screenOffsetX)).assertEqual("number");
expect(typeof(strJson.screenOffsetY)).assertEqual("number");
console.info('ArkUX_Get_component_add_0100 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0100 ERR '+ JSON.stringify(err));
}
done();
},500)
});
it('ArkUX_Get_component_add_0110', 0, async function (done) {
console.info('ArkUX_Get_component_add_0110 START');
setTimeout(()=>{
try{
let strJson = getInspectorByKey('ArkUX_Get_component_add_0110');
console.info('ArkUX_Get_component_add_0110 START :'+ JSON.stringify(strJson));
let obj = JSON.parse(strJson);
console.info("ArkUX_Get_component_add_0110 obj is: " + JSON.stringify(obj));
let getRectangleById = componentUtils.getRectangleById('');
let Matrix4_1 = getRectangleById.transform[0];
let Matrix4_2 = getRectangleById.transform[1];
let Matrix4_3 = getRectangleById.transform[2];
let Matrix4_4 = getRectangleById.transform[3];
let Matrix4_5 = getRectangleById.transform[4];
let Matrix4_6 = getRectangleById.transform[5];
let Matrix4_7 = getRectangleById.transform[6];
let Matrix4_8 = getRectangleById.transform[7];
let Matrix4_9 = getRectangleById.transform[8];
let Matrix4_10 = getRectangleById.transform[9];
let Matrix4_11 = getRectangleById.transform[10];
let Matrix4_12 = getRectangleById.transform[11];
let Matrix4_13 = getRectangleById.transform[12];
let Matrix4_14 = getRectangleById.transform[13];
let Matrix4_15 = getRectangleById.transform[14];
let Matrix4_16 = getRectangleById.transform[15];
let localOffsetX = getRectangleById.localOffset.x;
let localOffsetY = getRectangleById.localOffset.y;
let windowOffsetX = getRectangleById.windowOffset.x;
let windowOffsetY = getRectangleById.windowOffset.y;
let screenOffsetX = getRectangleById.screenOffset.x;
let screenOffsetY = getRectangleById.screenOffset.y;
console.info('ArkUX_Get_component_add_0110 START :'+ getRectangleById);
console.info('ArkUX_Get_component_add_0110 START :'+ typeof getRectangleById);
expect(typeof getRectangleById).assertEqual("object")
expect(Matrix4_1).assertEqual(1)
expect(Matrix4_2).assertEqual(0)
expect(Matrix4_3).assertEqual(0)
expect(Matrix4_4).assertEqual(0)
expect(Matrix4_5).assertEqual(0)
expect(Matrix4_6).assertEqual(1)
expect(Matrix4_7).assertEqual(0)
expect(Matrix4_8).assertEqual(0)
expect(Matrix4_9).assertEqual(0)
expect(Matrix4_10).assertEqual(0)
expect(Matrix4_11).assertEqual(1)
expect(Matrix4_12).assertEqual(0)
expect(Matrix4_13).assertEqual(0)
expect(Matrix4_14).assertEqual(0)
expect(Matrix4_15).assertEqual(0)
expect(Matrix4_16).assertEqual(1)
expect(localOffsetX).assertEqual(0)
expect(localOffsetY).assertEqual(0)
expect(windowOffsetX).assertEqual(0)
expect(windowOffsetY).assertEqual(0)
expect(screenOffsetX).assertEqual(0)
expect(screenOffsetY).assertEqual(0)
console.info('ArkUX_Get_component_add_0110 END ');
} catch(err) {
expect().assertFail()
console.info('ArkUX_Get_component_add_0110 ERR '+ JSON.stringify(err));
}
done();
},500)
});
})
}
\ No newline at end of file
......@@ -27,6 +27,8 @@
"TestAbility/pages/list",
"TestAbility/pages/grid",
"TestAbility/pages/swiper",
"TestAbility/pages/richeditor"
"TestAbility/pages/richeditor",
"TestAbility/pages/getcomponent",
"TestAbility/pages/getcomponentadd"
]
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册