1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16exports.source = ` 17import router from '@system.router' 18import app from '@system.app' 19 20@Entry 21@Component 22struct MyComponent { 23 @State text_num: float = 0.0 24 25 build() { 26 Column() { 27 Text('fingers:2,scale: ' + this.text_num) 28 .fontSize(25) 29 .width(400) 30 .height(400) 31 .backgroundColor('red') 32 .gesture( 33 PinchGesture({fingers: 2, distance: 18}) 34 .onActionStart((event: GestureEvent) => { 35 this.text_num = event.scale 36 console.error('pinch gesture on clicked') 37 }) 38 .onActionUpdate((event: GestureEvent) => { 39 this.text_num = event.scale 40 console.error('pinch gesture on clicked') 41 }) 42 .onActionEnd((event: GestureEvent) => { 43 this.text_num = event.scale 44 console.error('pinch gesture on clicked') 45 }) 46 .onActionCancel(() => { 47 }) 48 ) 49 } 50 } 51}` 52 53exports.expectResult = 54`"use strict"; 55var router = globalThis.requireNativeModule('system.router'); 56var app = globalThis.requireNativeModule('system.app'); 57class MyComponent extends View { 58 constructor(compilerAssignedUniqueChildId, parent, params) { 59 super(compilerAssignedUniqueChildId, parent); 60 this.__text_num = new ObservedPropertyObject(0.0, this, "text_num"); 61 this.updateWithValueParams(params); 62 } 63 updateWithValueParams(params) { 64 if (params.text_num !== undefined) { 65 this.text_num = params.text_num; 66 } 67 } 68 aboutToBeDeleted() { 69 this.__text_num.aboutToBeDeleted(); 70 SubscriberManager.Get().delete(this.id()); 71 } 72 get text_num() { 73 return this.__text_num.get(); 74 } 75 set text_num(newValue) { 76 this.__text_num.set(newValue); 77 } 78 render() { 79 Column.create(); 80 Text.create('fingers:2,scale: ' + this.text_num); 81 Text.fontSize(25); 82 Text.width(400); 83 Text.height(400); 84 Text.backgroundColor('red'); 85 Gesture.create(GesturePriority.Low); 86 PinchGesture.create({ fingers: 2, distance: 18 }); 87 PinchGesture.onActionStart((event) => { 88 this.text_num = event.scale; 89 console.error('pinch gesture on clicked'); 90 }); 91 PinchGesture.onActionUpdate((event) => { 92 this.text_num = event.scale; 93 console.error('pinch gesture on clicked'); 94 }); 95 PinchGesture.onActionEnd((event) => { 96 this.text_num = event.scale; 97 console.error('pinch gesture on clicked'); 98 }); 99 PinchGesture.onActionCancel(() => { 100 }); 101 PinchGesture.pop(); 102 Gesture.pop(); 103 Text.pop(); 104 Column.pop(); 105 } 106} 107loadDocument(new MyComponent("1", undefined, {})); 108` 109