PeterStaev / NativeScript-Drop-Down

A NativeScript DropDown widget.
Apache License 2.0
105 stars 65 forks source link

Conflict when observing page tap #84

Closed ickata closed 7 years ago

ickata commented 7 years ago

Hi,

I have an issue on iOS only – dropdown does not show on tap if I observe page tap in my business logic:

      page.observe( gestures.GestureTypes.tap, function ( args ) {
         // ... my stuff ...
      });

It looks like this plugin also observes page tap, and it appears that my observer overwrites plugin's.

{N} version is 2.5.3, plugin version 1.5.1 .

Please advise.

Thanks!

PeterStaev commented 7 years ago

Hey @ickata , Yes, I'm subscribing to the touch event for the iOS here. I will have to research and see how to overcome this. Looking at the implementation of the Button widget for {N} they are using addTargetActionForControlEvents so may be this fires even when there is an outside touch observer.

ickata commented 7 years ago

Hi @PeterStaev ,

Thanks for the quick response! Until you fix the problem, is there any workaround I can go with? Perhaps accessing your tap handler (if public) and invoke it in my business logic? I saw that the DD instance provides open method, so I'll try to go with it and will let you know the result.

PeterStaev commented 7 years ago

Yes, you could detect when the user taps on the drop down in your observer and manually call the dropdown's open() method. This should work.

ickata commented 7 years ago

@PeterStaev ,

I added a workaround like this:

         page.observe( gestures.GestureTypes.tap, function ( args ) {
            // ... my stuff ...
         });
         page.getViewById( 'dd-instance-id' ).observe( gestures.GestureTypes.tap, function ( args ) {
            if ( application.ios ) {
               // DropDown component also observes tap gesture
               // of the Page object and the above observer overwrites it.
               // Therefore, DropDown options are never displayed.
               // Thankfully DD instance provides `open` method...
               typeof args.object.open == 'function' && args.object.open();
            }
         });

I'll leave the issue in "open" state if you decide to fix this problem in the plugin. Otherwise, you can close it.