diff --git a/ArkUI/entry/src/main/ets/entryability/EntryAbilityMonitorTheFrontAndBack.ets b/ArkUI/entry/src/main/ets/entryability/EntryAbilityMonitorTheFrontAndBack.ets index 97ba92d254d392ef4d523cf938bc74c1c35986ff..9ed5d5d0c92ef155022ca31476ba4a69d6dd0c98 100644 --- a/ArkUI/entry/src/main/ets/entryability/EntryAbilityMonitorTheFrontAndBack.ets +++ b/ArkUI/entry/src/main/ets/entryability/EntryAbilityMonitorTheFrontAndBack.ets @@ -27,7 +27,7 @@ const DOMAIN = 0x0000; // EntryAbility中 export default class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { - AppStorage.setOrCreate('isOnForeground', true); + AppStorage.setOrCreate('isOnForeground', undefined); } onForeground(): void { diff --git a/ArkUI/entry/src/main/ets/pages/ListSideRebound.ets b/ArkUI/entry/src/main/ets/pages/ListSideRebound.ets new file mode 100644 index 0000000000000000000000000000000000000000..eda4fc7860767482e2cb1fcdeb9e49166c7c8fa1 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/ListSideRebound.ets @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2024 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. +*/ + +/* +* FAQ:如何实现Scroll、List单边回弹效果 +*/ + +// [Start list_side_rebound] +// Single side rebound effect of List component +@Entry +@Component +struct ListSideRebound { + @State isTop: boolean = true; + private arr: number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + + build() { + Column() { + List({ space: 20, initialIndex: 0 }) { + ForEach(this.arr, (item: number) => { + ListItem() { + Text('' + item) + .width('100%') + .height(100) + .fontSize(16) + .textAlign(TextAlign.Center) + .borderRadius(10) + .backgroundColor(0xFFFFFF) + } + }, (item: string) => item) + } + .listDirection(Axis.Vertical) // Arrangement direction + .scrollBar(BarState.Off) + .friction(0.6) + .edgeEffect(this.isTop ? EdgeEffect.Spring : EdgeEffect.None) + .onScrollIndex((firstIndex: number) => { + if (firstIndex === 0) { + this.isTop = true; + } else { + this.isTop = false; + } + }) + .width('90%') + } + .width('100%') + .height('100%') + .backgroundColor(0xDCDCDC) + .padding({ top: 5 }) + } +} +// [End list_side_rebound] \ No newline at end of file diff --git a/ArkUI/entry/src/main/ets/pages/MockOnclick.ets b/ArkUI/entry/src/main/ets/pages/MockOnclick.ets new file mode 100644 index 0000000000000000000000000000000000000000..bebb319e5068690b9b53aaffb85cce529dfd6898 --- /dev/null +++ b/ArkUI/entry/src/main/ets/pages/MockOnclick.ets @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2024 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. +*/ + +/* +* FAQ:如何模拟点击事件? +*/ + +// [Start mock_onclick] +import { NodeController, BuilderNode, FrameNode, UIContext } from '@kit.ArkUI'; + +class Params { + text: string = 'this is a text'; +} + +@Builder +function ButtonBuilder(params: Params) { + Column() { + Button(`button ` + params.text) + .backgroundColor(Color.Orange) + .width('100%') + .gesture( + TapGesture() + .onAction((event: GestureEvent) => { + console.info('TapGesture'); + }) + ) + } + .width('100%') + .height(300) + .padding({ + left: 16, + right: 16 + }) + .justifyContent(FlexAlign.Center) + .backgroundColor(Color.Gray) +} + +class MyNodeController extends NodeController { + private rootNode: BuilderNode<[Params]> | null = null; + private wrapBuilder: WrappedBuilder<[Params]> = wrapBuilder(ButtonBuilder); + + makeNode(uiContext: UIContext): FrameNode | null { + this.rootNode = new BuilderNode(uiContext); + this.rootNode.build(this.wrapBuilder, { text: 'this is a string' }); + return this.rootNode.getFrameNode(); + } + + // Coordinate Conversion Example + postTouchEvent(event: TouchEvent, uiContext: UIContext): boolean { + if (this.rootNode == null) { + return false; + } + let node: FrameNode | null = this.rootNode.getFrameNode(); + let offsetX: number | null | undefined = node?.getPositionToParent().x; + let offsetY: number | null | undefined = node?.getPositionToParent().y; + + let changedTouchLen = event.changedTouches.length; + for (let i = 0; i < changedTouchLen; i++) { + if (offsetX != null && offsetY != null && offsetX != undefined && offsetY != undefined) { + event.changedTouches[i].x = uiContext.vp2px(offsetX + event.changedTouches[i].x); + event.changedTouches[i].y = uiContext.vp2px(offsetY + event.changedTouches[i].y); + } + } + let result = this.rootNode.postTouchEvent(event); + console.info('result:' + result); + return result; + } +} + +@Entry +@Component +struct MyComponent { + private nodeController: MyNodeController = new MyNodeController(); + + build() { + Column() { + NodeContainer(this.nodeController) + .height(300) + .width('100%') + + Column() + .width(500) + .height(300) + .backgroundColor('#0A59F7') + .onTouch((event) => { + if (event != undefined) { + let uiContext = this.getUIContext(); + // Dispatch event events to the FrameNode created by the nodeController by touching them with fingers + this.nodeController.postTouchEvent(event, uiContext); + } + }) + } + } +} +// [End mock_onclick] \ No newline at end of file