简体   繁体   English

如果弹出框处于活动状态,则不会显示Ionic2警报

[英]Ionic2 Alert does not show if a popover is active

I have a list where the user can call a popover from an list item. 我有一个列表,用户可以在其中从列表项调用弹出窗口。 Inside the popover, when a option is selected, a confirmation alert should be created. 在弹出框内,选择一个选项后,应创建一个确认警报。

The problem is when I try to call the alert when the popover is open, it does not show correctly. 问题是当我尝试在弹出窗口打开时调用警报时,它无法正确显示。 It appears to be behind the list and the list becomes unresponsive (can´t accept clicks anymore)... 它似乎在列表的后面,并且列表变得没有响应(不再接受点击)...

For testing proposes if I add the alert directly from a click on the item, instead of the option selected from the popover, the alert appears correctly. 为了进行测试,建议如果我直接通过单击项目添加警报,而不是从弹出菜单中选择的选项,警报将正确显示。

On the page where the list and the popover are created: 在创建列表和弹出窗口的页面上:

public OnItemOptionsPress(event, item)
  {
        event.stopPropagation();

        let popoverOptions =
        [
              { 
                    Resource: "Remove",  
                    Icon: "icon-trash",               
                    Callback: (event, item) => 
                    { 
                          this.confirmRemoveItem(event, item) 
                    },
              }
        ];

        let popover = this.PopoverController.create
        (
              PopoverOptions, 
              { 
                    Owner: item, 
                    Items: this.popoverOptions 
              }
        );

        popover.present({ ev:event });
  }

  public confirmRemoveItem(event, item)
  {
        let alert = this.AlertController.create
        (
              {
                    title: 'Remove Item',
                    message: 'Do you want to remove?',
                    buttons: 
                    [
                          {
                                text: 'No',
                                role: 'cancel',
                                handler: () => 
                                {
                                      console.log('No has been clicked');
                                }
                          },
                          {
                                text: 'Yes',
                                handler: () => 
                                {
                                      console.log('yes has been clicked');

                                      this.removeItem(item);
                                }
                          }
                    ]
              }
        );

        alert.present();
  }

  public removeItem(item)
  {
        this.items.splice(item.Index, 1);
  }

Inside the popover when an option is selected and the close function is called: 在弹出框内,选择一个选项并调用close函数时:

  public close(event, item) 
  {
        if (item.Callback) item.Callback(event, this.Owner);

        this.ViewController.dismiss();
  }

I noticed the dismiss() method is returning a promise. 我注意到dismiss()方法正在返回诺言。 I had to add a delay when dismissing the popover and calling the callback async. 在关闭弹出窗口并调用回调异步时,我不得不添加一个延迟。

  public close(event, item:PopoverItemModel) 
  {    
        let animation = this.ViewController.dismiss();

        animation.then(()=>
        {
               if (item.Callback) item.Callback(this.Owner);
        });

        //if (item.Callback) item.Callback(this.Owner);
  }

Now it works... but there's a strange delay (the time the popover takes to complete his animation and be dismissed). 现在可以了...但是有一个奇怪的延迟(弹出窗口完成其动画并被关闭的时间)。 Probably the viewcontroller can't handle multiple animations/component transitions at the same time... 可能是viewcontroller无法同时处理多个动画/组件过渡...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM