智能客服
你问我答,随时在线为你解决问题
Text组件绑定了bindPopup和bindMenu,想要长按显示bindMenu,点击显示bindPopup,该如何实现?
使用组合手势中的互斥手势GestureMode.Exclusive来实现长按手势LongPressGesture触发弹出bindMenu,点击手势TapGesture触发弹出bindPopup。
- @Entry
- @Component
- struct GestureGroupDemo {
- @State isMenu: boolean = false;
- @State isPopup: boolean = false;
-
- @Builder
- bindMenuBuilder() {
- Row() {
- Text('MenuContent');
- }.backgroundColor(Color.Pink);
- }
-
- @Builder
- bindPopupBuilder() {
- Row() {
- Text('PopupContent');
- }.backgroundColor(Color.Orange);
- }
-
- build() {
- RelativeContainer() {
- Button('长按或者点击')
- .alignRules({
- center: { anchor: '__container__', align: VerticalAlign.Center },
- middle: { anchor: '__container__', align: HorizontalAlign.Center }
- })
- .fontSize(28)
- .gesture(
- GestureGroup(GestureMode.Exclusive,
- LongPressGesture({ repeat: true })
- .onAction(() => {
- this.isPopup = false;
- this.isMenu = true;
- }),
- TapGesture({ count: 1, fingers: 1 })
- .onAction(() => {
- this.isMenu = false;
- this.isPopup = !this.isPopup;
- }))
- )
- .bindContextMenu(this.isMenu, this.bindMenuBuilder())
- .bindPopup(this.isPopup, {
- builder: this.bindPopupBuilder(), onStateChange: (e) => {
- if (!e.isVisible) {
- this.isPopup = false;
- }
- },
- });
- }
- .width('100%')
- .height('100%');
- }
- }
智能客服
你问我答,随时在线为你解决问题
合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
解决方案
精准高效的一站式服务支持,助力开发者商业成功