Forum Xamarin Xamarin.Forms

FastCell on github - silky smooth scrolling in ListView while using XAML

2»

Posts

  • GeorgeCookGeorgeCook PEUniversity ✭✭✭

    @Info-FrameLtd you nasty person ;p! You had me worried!!

  • ElielDinaullyElielDinaully USMember

    Hi @GeorgeCook ,

    your fastcell project looks just awesome, as i've got problems on my Xamarin.Forms project while loading a listview with image (app crashed on Android: outofmemory error and is not that smooth when i scroll). And I bet that your solution could fix my problem.

    Is it possible to use your solution without any Xaml code?

  • ChaseFlorellChaseFlorell CAInsider, University mod

    Anything you do in xaml can be done in c# / code behind.

  • GeorgeCookGeorgeCook PEUniversity ✭✭✭

    As @chaseflorell said, absolutely. I have since made an open source project and blog series about it. You will certainly resolve your performance and memory issues with it. But you will need 1.4.3 to use it on android.

    https://github.com/twintechs/TwinTechsFormsLib

    The library has both xaml and c# samples gesture recognisers page in page embedding a superior android grid view and more.

    Blog post series is here.

    http://blog.twintechs.com/advanced-xamarin-forms-techniques-for-flexible-and-performant-cross-platform-apps-part-1

    Lists are in part 2 grids part 3 and gesture recognisers I'll push out later this week (second baby is due so I'm busy)

  • ElielDinaullyElielDinaully USMember

    Thanks, i'll give it a try!

  • MaartenvanAremMaartenvanArem NLMember
    edited July 2015

    @GeorgeCook I have currently implemented the fast cell in my project but I noticed that the fix to display the correct values in the cells (which you referenced in your post on May 29) partly solves the problem of the cells getting bound to incorrect objects.

    I've found out that when you listen for the item tapped event you have the possibility to get the incorrect item returned when scrolling some way down and back up. This is probably the incorrect value you would see when not applying the fix.

    I'm not sure where the problem lies, but I think its the fact that the initial cells that get created and cached have their binding context altered while the listview thinks these are the old objects.

    Edit: I think I found the solution to this problem, ive created a pull request on github for Android.

  • GeorgeCookGeorgeCook PEUniversity ✭✭✭

    Yes,

    Good man!!

    I tried your solution and it works. I'll merge it shortly. The only thing was that I thought it might get rid of the caching; but to my surprise it does not (it's early here, and I've got 2 kids, so I'm a bit blurry eyed).

    I also applied it to iOS. Thanks a bunch!

  • MaartenvanAremMaartenvanArem NLMember

    @GeorgeCook It gets rid of the OriginalBindingContexts caching part, the cells themselves still need to be cached.

    I've used your implementation (after much refactoring ;)) in a project of ours, works like a charm!

  • GeorgeCookGeorgeCook PEUniversity ✭✭✭
    edited July 2015

    Glad to hear it.

    however, does this now get us back to a 1-1 mapping of ViewCells to items in a list?

    if that was the case, I'd certainly want to work out a more permanent fix, as 1-1 viewcell item ratio is extremely bad (that would mean potentially 1,000's of imageviews in memory (and God forbid if one were to use video/charts/etc).

    [Edit: just tested it - and no it does not.]

    Cool, happy to leave it like this going forward then. It's still super-zippy and works much better. I'm glad it's working out on your project.

    Also take note, I provide a new GridView now, based on android's recycler view.

    I'm not an android guy, so it's still lackign a bit - especially the layout.. I need to write a custom one.. but it's still much more performant and more feature complete than the default xlabs grid view.

    Hoping you find a use for that too in your projects, so you can work your keen eye and smart fixing on it as well!

    thanks again!

  • AlanSpiresAlanSpires USBeta ✭✭

    Using your FastImage in my app, Thanks George!

  • ddjddj USMember

    Hi @GeorgeCook, when I'm scrolling touching only spaces between GridView items it's really smooth, however when I'm doing the same on my GridView items scrolling stops for a moment. I cannot reproduce it on your TwinTechsFormsExample. I'm keeping my GridView in a TabbedPage, could it be a reason?

    Please move my question to the separate thread if you think it's not strictly conntected with this conversation.

    Thanks in advance for your help.

  • GeorgeCookGeorgeCook PEUniversity ✭✭✭

    Please raise an issue with an example of your grid and details about wha platform you are running on on GitHub.

  • @GeorgeCook I have been at battle with listview performance for over two weeks now, and just stumbled upon this! Thank you so much for finding a solution, and then extending that out to the community. If you ever take a vacation in Florida, I will buy you as much alcohol as you can drink!

    Is there a nuget package you have available, or should we just copy your implementation into our project? I know you said you will be updating it later down the road, so ideally I would want a way to see that updates are in.

    Thanks again George!

  • arroyosarroyos MYMember

    Hi Guys,

    I am trying to use the Fast Cell thing in my sample app to serve as a picture gallery purpose. Currently i am displaying the fastimage in the cell on the listview however i found all my pictures are in blurry view. Currently my image is downloaded from url...Any idea?

  • SagarPanwalaSagarPanwala USMember ✭✭✭

    widthrequest and heightrequest not working on FastImage. How to set it fix 70 x 70

  • EmanueleSabettaEmanueleSabetta ITBeta ✭✭✭

    @SagarPanwala I solved changing the parameters of this class:

    https://github.com/twintechs/TwinTechsFormsLib/blob/master/TwinTechsForms/TwinTechsForms.Droid/TwinTechs/Droid/Controls/ImageLoaderCache.cs

    SPECIFICALLY you should increase the current value of "64" to the image resolution you need:

    c# public static ImageLoader GetImageLoader (FastImageRenderer imageRenderer) { //TODO if (_onlyLoader == null) { _onlyLoader = new ImageLoader (Android.App.Application.Context, 64, 40); } return _onlyLoader; }

    @GeorgeCook I've made a pull request to fix the image issues and add SVG: https://github.com/twintechs/TwinTechsFormsLib/pull/53 . But it is a while now. Can you pull it? Thanks!

  • SagarPanwalaSagarPanwala USMember ✭✭✭

    @EmanueleSabetta : How to do it in iOS? Is there any way to handle it from PCL project?

  • EmanueleSabettaEmanueleSabetta ITBeta ✭✭✭

    @SagarPanwala said:

    @EmanueleSabetta : How to do it in iOS?

    It uses two different native libraries to handle image loading on the two platforms.

    On Android it uses MonoDroidToolkit.ImageLoader by Jamesmontemagno:

    https://github.com/jamesmontemagno/MonoDroidToolkit

    On iOS it uses SDWebImage:

    https://github.com/rs/SDWebImage
    https://github.com/Viv-Rajkumar/SDWebImage-XamarinBinding

    It doesn't have a setting for image resolutions. It should load and display images as they are. But the images used as samples from the web are of low resolution, so you need another set of images to load, like those from http://lorempixel.com .

    @SagarPanwala said:

    Is there any way to handle it from PCL project?

    The only way is to replace the FastImageLoader with a different library that is cross platform and built for Xamarin.Forms, like FFImageLoading:

    https://github.com/luberda-molinet/FFImageLoading

    But you need to rewrite the fastimage cell caching mechanism to use that.

  • PhamThanhTongPhamThanhTong USMember ✭✭

    Hi everyone,
    I'm using FastCell with FFImageLoading in Xamarin Forms.

    I have a problem:
    Image was reused, while my listview scrolling to load more ViewCell, images (of viewcells before scrolling) was reused.
    ViewCells (display after scrolling) are taked some seconds to load themself 's image. It is not good.
    Because I would like to the images of ViewCells(display after scrolling) should be display blank while waiting load images.
    So, how to not reuse image in FastCell?
    Thanks in advanced.

  • SteeBonoSteeBono ITMember ✭✭
    edited May 2017

    Hi @GeorgeCook,

    I noticed that 'FastCellRenderer.cs' must implement 'INativeElementView' on NativeCell code, based on use that you do with cells.
    INativeElementView contains a read-only property that returns the platform-specific native view for an element.

    If I do not implement this interface, Xamarin throw an Exception when I try to scroll my ListView.
    This Exception occurs when you use a ListView with CachingStrategy = 'RecycleElement', the Exception is:
    View for cell must implement INativeElementView to enable recycling

    In conclusion I added this implementation to 'FastCellRenderer.cs':

    `

        internal class NativeCell : UITableViewCell, INativeElementView
    
        .....
    
        public Element Element => _fastCell;
    

    `

    Thanks for your code @GeorgeCook.
    I Hope that this help other people.
    Byee

  • ElPiponElPipon COMember ✭✭

    Hi @GeorgeCook, I cant implement you code.

    I am try use FastCell but i dont know that i am doing bad.

    Can help me?

  • ElPiponElPipon COMember ✭✭

    Thanks George, i already solved my problem. A example more specific here https://github.com/georgejecook/xamarinFastCell

    You are the best!.

    A lot of patience analizing this project.

  • SteveShaw.5557SteveShaw.5557 USMember ✭✭✭
    edited July 2018

    @SteeBono - if you are using CachingStrategy = 'RecycleElement', then do you gain anything by using FastCellRenderer?
    I thought that RecycleElement does what FastCellRenderer was written to accomplish?

    (Notice that TwinTechsForms/TwinTechsFormsExample/TwinTechs/Example/FastCells/...xaml files don't set CachingStrategy, which they certainly would if RecycleElement had been an option at the time those were written.)

    Anyway, setting CachingStrategy = 'RecycleElement' on long lists with XAML cells (not using FastCellRenderer - just using existing ViewCells) makes a huge performance improvement for me.
    So the FastCells library might no longer be needed.

Sign In or Register to comment.