Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: leftButton not always responding to click #577

Open
m1ga opened this issue Aug 9, 2022 · 16 comments
Open

iOS: leftButton not always responding to click #577

m1ga opened this issue Aug 9, 2022 · 16 comments
Assignees

Comments

@m1ga
Copy link
Contributor

m1ga commented Aug 9, 2022

The leftButton is not always responding to a click. It sometimes stays in the "clicked" position too.

Steps to reproduce:

  • run the example below
  • click on the pin
  • click on the leftButton icon
  • watch the log output
  • clicking the infobox works everytime
var Map = require('ti.map');
var win = Titanium.UI.createWindow();

var mountainView = Map.createAnnotation({
	latitude: 37.390749,
	longitude: -122.081651,
	title: 'Appcelerator Headquarters',
	subtitle: 'Mountain View, CA',
	leftButton: Ti.UI.iOS.SystemButton.INFO_LIGHT,
});

var mapview = Map.createView({
	mapType: Map.NORMAL_TYPE,
	region: {
		latitude: 37.390749,
		longitude: -122.081651,
		latitudeDelta: 0.01,
		longitudeDelta: 0.01
	},
	animate: true,
	regionFit: true,
	userLocation: true,
	annotations: [mountainView]
});

win.add(mapview);

var clickCounter = 0;
mapview.addEventListener('click', function(event) {
	Ti.API.info(clickCounter + ': clicked ' + event.clicksource);
	clickCounter++;
});
win.open();
@zenjoe
Copy link

zenjoe commented Dec 10, 2022

It affects leftButton, rightButton, leftView and rightView (testet on 11.1.1 GA)
Screenshot 2022-12-10 at 17 15 42
Screenshot 2022-12-10 at 17 15 45

@m1ga
Copy link
Contributor Author

m1ga commented Dec 15, 2022

@hansemannn did you have time to look at this issue?

@hansemannn
Copy link
Contributor

I oversaw it, sorry! Will schedule to complete this month

@hansemannn
Copy link
Contributor

To understand this correctly: The accessories leftView/rightView & leftButton/rightButton were also in the "click" event of the map view? How were they distinguished from the normal click events?

@m1ga
Copy link
Contributor Author

m1ga commented Dec 16, 2022

I think they'll returned e.g. rightButton or leftView as clicksource. There was an older ticket #104 (point 3) where the same issue was in 2015.

I've only created the ticket for a Slack user (can't find it because it's too old) but we have another thread about it too

@ferdi2005
Copy link

That slack user is me! @m1ga

@hansemannn
Copy link
Contributor

Okay, so I've spent some time on this, but couldn't find any issue with the code, yet. Though I am sure to know what could cause it: The click listener is currently handled via the "global" map click event of the map, which may not always respond to child views of the annotations. When looking into other native implementations, they use a tap gesture recognizer for the button / view itself, which is much more flexible, also in terms of advanced tap gestures like "longpress" and "singletap".

I will try to refactor the code to use these gesture recognizers instead and start clean. The ti.map module has a LOT of legacy code that should be cleaned up.

@LynMajor
Copy link

LynMajor commented Mar 3, 2023

I'm having this issue also, on iOS 16.3.1 and Ti.Map v7.0.0 click source never returns 'leftButton' or 'rightButton' but is working for 'infoWindow'

Is this likely to be fixed?

Many thanks Lyn

@hansemannn
Copy link
Contributor

I am seriously considering to rewrite ti.map completely in Swift to start fresh for things like this. Any thoughts if it's worth it?

@LynMajor
Copy link

LynMajor commented Mar 3, 2023

I am seriously considering to rewrite ti.map completely in Swift to start fresh for things like this. Any thoughts if it's worth it?

Hi Hans, We use the map module in two apps both iOS and Droid and apart from this issue it seems to work to an acceptable level. I would assume that its a popular module but guess you would need to ask the community.

@zenjoe
Copy link

zenjoe commented Mar 8, 2023

Same problem - but solved it by sliding in options into the view I usually would attach to left/right button. (Like - calculate route, more info and stuff. But yeah - would be great with an update to the module :)

@adamtarmstrong
Copy link

adamtarmstrong commented Jun 7, 2023

fwiw...I see the title says the left/right button is "not always" responding.....however for me it fails 100% of the time.

on 12.1.2.GA - for click event, when checking clicksource I only get map or pin.

@designbymind
Copy link
Contributor

Hey Hey. I will help sponsor a portion the Ti.Map rewrite and contribute what I can . Mapping should be considered first-class as it’s such an important part of our day-to-day lives. I’d love to see this module get updated and even some modern MapKit features added 🙂

@m1ga
Copy link
Contributor Author

m1ga commented Oct 21, 2023

So I finally was able to build ti.map on iOS and added some logs.

build the module

I had to remove the last else #error unsupported Swift architecture (line 306/307) in TitaniumKit-Swift so I can build it on my Intel Mac again.

Click event

At first I added a log in:
https://github.com/tidev/ti.map/blob/master/ios/Classes/TiMapMarkerAnnotationView.m#L37
and it is called when you click the leftButton but I'm not sure how it will trigger the click event.

Then I tried this:
Adding this code in https://github.com/tidev/ti.map/blob/master/ios/Classes/TiMapView.m#L1281-L1283

  if (left != nil) {
    annView.leftCalloutAccessoryView = left;

    UITapGestureRecognizer *singleFingerTap =  [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    [left addGestureRecognizer:singleFingerTap];
  }

plus

-(void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
    NSLog(@"[ERROR] click click");
    [self fireClickEvent:selectedAnnotation source:@"leftButton" deselected:NO];
}

will show the log everytime and trigger the click event when you click on the leftButton. I'm not sure if that is the correct way (or a good way) to do it but it works and maybe something to fix the issue. @hansemannn would this be a way to fix it?

@hansemannn
Copy link
Contributor

In general, yes. The possible problem is that it could cause lags in the map view when having many annotations (maybe 500+), because every instance will have an own native click listener. If this does not cause issues, it's a good solution.

@m1ga
Copy link
Contributor Author

m1ga commented Oct 21, 2023

test PR #655 for people to test. There is a ZIP and demo code.

500 annotations is ok too 😄

Simulator Screenshot - iPhone 15 Pro Max - 2023-10-21 at 13 13 55

Simulator Screenshot - iPad Air (5th generation) - 2023-10-21 at 13 21 25

sometime it takes a bit to run the "open annotation" animation (same as in the current live module) but the click event is instant.

edit:
another solution would still be fixing the part in https://github.com/tidev/ti.map/blob/master/ios/Classes/TiMapMarkerAnnotationView.m#L37 as it seems to go into that function when you click but then not to the fireevent part (only the first time it works). Then we don't need new touch events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants