Fabulous icon indicating copy to clipboard operation
Fabulous copied to clipboard

GeastureRecognizers are not updated via UpdateIncremental on iOS

Open Dolfik1 opened this issue 3 years ago • 4 comments

We have out implementation of CollectionView that frequently uses UpdateIncremental function. I find out that sometimes geastureRecognizers are not updated. There is examle:

let i = ref 0
let view ... =
  incr i
  let a = !i
  View.Label(
    text = string a,
    geastureRecognizers = [
      View.TapGestureRecognizer (fun _ -> printfn "%i" a)
    ]
  )

When I run this example I see different values in UI and stdout. This reproduced only on iOS.

Dolfik1 avatar Aug 10 '20 08:08 Dolfik1

@Dolfik1 Hmm strange. Fabulous use the exact same logic for all the platforms, so UpdateIncremental shouldn't behave differently between Android and iOS. Moreover the code that updates gesturesRecognizers is the exact same that updates pretty much everything else, so I don't see why it would behave incorrectly here when everything else works as expected...

It is more likely to be a bug in Xamarin.Forms (well, at least on the iOS implementation) which seems to be a common occurrence according to Google.

Or if you wrote your own CollectionView renderer, it could be an invalid use of UpdateIncremental.

Collections can be tricky to handle because of virtualization, the cells are reused and you need to make sure to keep the correct ViewElements that were used to generate those cells. Otherwise you can end up with mismatch.

Fabulous only compares "previous" and "new" ViewElements to decide what to update in the cell. If the "previous" ViewElement doesn't exactly match the cell, after calling UpdateIncremental you end up with old data that Fabulous didn't cleared/didn't add, such as GestureRecognizers.

TimLariviere avatar Aug 18 '20 17:08 TimLariviere

@TimLariviere I am also experiencing this issue. Taps defined in CollectionView cells fire multiple times after the cell has been recycled. It looks very much as if the event handler for the GestureRecognizer isn't being unhooked when the BindingContext of the cell changes. I seem to recall a fix for something like that in the latest XF 5.0 release. If that's a Xamarin Forms bug, would Fabulous 0.60 be able to work with Xamarin Forms 5.0?

programmation avatar Jan 13 '21 02:01 programmation

@programmation Thanks for your report. Would you happen to have a reproduction that you can share?

Regarding XF 5.0, it's not currently possible to use it as there are a bunch of breaking changes. #836 is aiming to support it.

TimLariviere avatar Jan 13 '21 05:01 TimLariviere

@TimLariviere Thanks for the information about XF 5.0. I'll hold off upgrading until it is supported. I'm also trying to put a sample project together to demonstrate the Taps problem in CollectionView cells.

programmation avatar Jan 13 '21 14:01 programmation