Tap gesture fired for multiple sub-views inside ListView











up vote
0
down vote

favorite












I have this ListView:



<ListView
CachingStrategy="RecycleElement"
x:Name="ItemList"
HasUnevenRows="True"
BackgroundColor="Transparent"
SeparatorColor="{x:Static local:LmcColor.defaultFg}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
IsVisible="False"
ItemSelected="ItemList_ItemSelected"/>


Its ItemTemplate is initialized as follows:



ItemList.ItemTemplate = new DataTemplate(() =>
new ViewCell() { View = new ItemReadView() });


And ItemReadView is a ContentView containing a StackView containing an Image called ItemImage. I define a gesture recognizer for this Image:



TapGestureRecognizer handler = new TapGestureRecognizer();
handler.Tapped += ((object sender, EventArgs e) =>
{
// Do stuff!
});
ItemImage.GestureRecognizers.Clear();
ItemImage.GestureRecognizers.Add(handler);


It worked fine in Xamarin Forms 2.5.1.444934. Now, in 3.3.0.967583, the "Do stuff" is being invoked for multiple image views after a single tap. I am not sure if the issue was present in Forms 3.1.0.637273. The bug only affects iOS.



As a workaround, I added a 200-msec delay before "doing stuff", and "stuff" is not "done" if a new event arrives in that interval. Luckily, the "real" event comes in last. Unluckily, the more I scroll the list view before tapping, the more events come in, and I'm afraid of some sort of resource overflow.



Has anyone noticed this? Are there any "proper" fixes? Is there anything I may be doing wrong? Should I replace TapGestureRecognizer with something else, and if so, with what?



Thanks!










share|improve this question






















  • Have you tried using Command and CommandParameter?
    – Tom
    Nov 12 at 10:06










  • Don't see how. Unlike, say, Button, the Image class doesn't have Command property.
    – user1334767
    Nov 12 at 12:20










  • No, it doesn't, but you can try the example in the docs.
    – Tom
    Nov 12 at 12:26










  • As this example still has TapGestureRecognizer underneath, I don't think it would make a difference. The gesture is incorrectly generated for multiple views. I don't see how this can be rectified by tying a Command to it.
    – user1334767
    Nov 12 at 12:36















up vote
0
down vote

favorite












I have this ListView:



<ListView
CachingStrategy="RecycleElement"
x:Name="ItemList"
HasUnevenRows="True"
BackgroundColor="Transparent"
SeparatorColor="{x:Static local:LmcColor.defaultFg}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
IsVisible="False"
ItemSelected="ItemList_ItemSelected"/>


Its ItemTemplate is initialized as follows:



ItemList.ItemTemplate = new DataTemplate(() =>
new ViewCell() { View = new ItemReadView() });


And ItemReadView is a ContentView containing a StackView containing an Image called ItemImage. I define a gesture recognizer for this Image:



TapGestureRecognizer handler = new TapGestureRecognizer();
handler.Tapped += ((object sender, EventArgs e) =>
{
// Do stuff!
});
ItemImage.GestureRecognizers.Clear();
ItemImage.GestureRecognizers.Add(handler);


It worked fine in Xamarin Forms 2.5.1.444934. Now, in 3.3.0.967583, the "Do stuff" is being invoked for multiple image views after a single tap. I am not sure if the issue was present in Forms 3.1.0.637273. The bug only affects iOS.



As a workaround, I added a 200-msec delay before "doing stuff", and "stuff" is not "done" if a new event arrives in that interval. Luckily, the "real" event comes in last. Unluckily, the more I scroll the list view before tapping, the more events come in, and I'm afraid of some sort of resource overflow.



Has anyone noticed this? Are there any "proper" fixes? Is there anything I may be doing wrong? Should I replace TapGestureRecognizer with something else, and if so, with what?



Thanks!










share|improve this question






















  • Have you tried using Command and CommandParameter?
    – Tom
    Nov 12 at 10:06










  • Don't see how. Unlike, say, Button, the Image class doesn't have Command property.
    – user1334767
    Nov 12 at 12:20










  • No, it doesn't, but you can try the example in the docs.
    – Tom
    Nov 12 at 12:26










  • As this example still has TapGestureRecognizer underneath, I don't think it would make a difference. The gesture is incorrectly generated for multiple views. I don't see how this can be rectified by tying a Command to it.
    – user1334767
    Nov 12 at 12:36













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have this ListView:



<ListView
CachingStrategy="RecycleElement"
x:Name="ItemList"
HasUnevenRows="True"
BackgroundColor="Transparent"
SeparatorColor="{x:Static local:LmcColor.defaultFg}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
IsVisible="False"
ItemSelected="ItemList_ItemSelected"/>


Its ItemTemplate is initialized as follows:



ItemList.ItemTemplate = new DataTemplate(() =>
new ViewCell() { View = new ItemReadView() });


And ItemReadView is a ContentView containing a StackView containing an Image called ItemImage. I define a gesture recognizer for this Image:



TapGestureRecognizer handler = new TapGestureRecognizer();
handler.Tapped += ((object sender, EventArgs e) =>
{
// Do stuff!
});
ItemImage.GestureRecognizers.Clear();
ItemImage.GestureRecognizers.Add(handler);


It worked fine in Xamarin Forms 2.5.1.444934. Now, in 3.3.0.967583, the "Do stuff" is being invoked for multiple image views after a single tap. I am not sure if the issue was present in Forms 3.1.0.637273. The bug only affects iOS.



As a workaround, I added a 200-msec delay before "doing stuff", and "stuff" is not "done" if a new event arrives in that interval. Luckily, the "real" event comes in last. Unluckily, the more I scroll the list view before tapping, the more events come in, and I'm afraid of some sort of resource overflow.



Has anyone noticed this? Are there any "proper" fixes? Is there anything I may be doing wrong? Should I replace TapGestureRecognizer with something else, and if so, with what?



Thanks!










share|improve this question













I have this ListView:



<ListView
CachingStrategy="RecycleElement"
x:Name="ItemList"
HasUnevenRows="True"
BackgroundColor="Transparent"
SeparatorColor="{x:Static local:LmcColor.defaultFg}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
IsVisible="False"
ItemSelected="ItemList_ItemSelected"/>


Its ItemTemplate is initialized as follows:



ItemList.ItemTemplate = new DataTemplate(() =>
new ViewCell() { View = new ItemReadView() });


And ItemReadView is a ContentView containing a StackView containing an Image called ItemImage. I define a gesture recognizer for this Image:



TapGestureRecognizer handler = new TapGestureRecognizer();
handler.Tapped += ((object sender, EventArgs e) =>
{
// Do stuff!
});
ItemImage.GestureRecognizers.Clear();
ItemImage.GestureRecognizers.Add(handler);


It worked fine in Xamarin Forms 2.5.1.444934. Now, in 3.3.0.967583, the "Do stuff" is being invoked for multiple image views after a single tap. I am not sure if the issue was present in Forms 3.1.0.637273. The bug only affects iOS.



As a workaround, I added a 200-msec delay before "doing stuff", and "stuff" is not "done" if a new event arrives in that interval. Luckily, the "real" event comes in last. Unluckily, the more I scroll the list view before tapping, the more events come in, and I'm afraid of some sort of resource overflow.



Has anyone noticed this? Are there any "proper" fixes? Is there anything I may be doing wrong? Should I replace TapGestureRecognizer with something else, and if so, with what?



Thanks!







ios listview xamarin xamarin.forms uitapgesturerecognizer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 0:12









user1334767

124112




124112












  • Have you tried using Command and CommandParameter?
    – Tom
    Nov 12 at 10:06










  • Don't see how. Unlike, say, Button, the Image class doesn't have Command property.
    – user1334767
    Nov 12 at 12:20










  • No, it doesn't, but you can try the example in the docs.
    – Tom
    Nov 12 at 12:26










  • As this example still has TapGestureRecognizer underneath, I don't think it would make a difference. The gesture is incorrectly generated for multiple views. I don't see how this can be rectified by tying a Command to it.
    – user1334767
    Nov 12 at 12:36


















  • Have you tried using Command and CommandParameter?
    – Tom
    Nov 12 at 10:06










  • Don't see how. Unlike, say, Button, the Image class doesn't have Command property.
    – user1334767
    Nov 12 at 12:20










  • No, it doesn't, but you can try the example in the docs.
    – Tom
    Nov 12 at 12:26










  • As this example still has TapGestureRecognizer underneath, I don't think it would make a difference. The gesture is incorrectly generated for multiple views. I don't see how this can be rectified by tying a Command to it.
    – user1334767
    Nov 12 at 12:36
















Have you tried using Command and CommandParameter?
– Tom
Nov 12 at 10:06




Have you tried using Command and CommandParameter?
– Tom
Nov 12 at 10:06












Don't see how. Unlike, say, Button, the Image class doesn't have Command property.
– user1334767
Nov 12 at 12:20




Don't see how. Unlike, say, Button, the Image class doesn't have Command property.
– user1334767
Nov 12 at 12:20












No, it doesn't, but you can try the example in the docs.
– Tom
Nov 12 at 12:26




No, it doesn't, but you can try the example in the docs.
– Tom
Nov 12 at 12:26












As this example still has TapGestureRecognizer underneath, I don't think it would make a difference. The gesture is incorrectly generated for multiple views. I don't see how this can be rectified by tying a Command to it.
– user1334767
Nov 12 at 12:36




As this example still has TapGestureRecognizer underneath, I don't think it would make a difference. The gesture is incorrectly generated for multiple views. I don't see how this can be rectified by tying a Command to it.
– user1334767
Nov 12 at 12:36

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244679%2ftap-gesture-fired-for-multiple-sub-views-inside-listview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244679%2ftap-gesture-fired-for-multiple-sub-views-inside-listview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues