• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The famous iOS Nuke native image caching library for Xamarin.Forms

Xamarin.Forms.Nuke

Nuke image caching library for Xamarin.Forms.

Get it from NuGet:

Nuget

This repository was inspired by Jonathan Peppers GlideX implementation of the new IImageViewHandler interface for Xamarin.Forms (https://github.com/jonathanpeppers/glidex).

Its goal is to provide the same kind of implementation for iOS, achieving a complete image caching solution for Xamarin.Forms: you don't have to change any line of your existing project, the Xamarin.Forms image source handlers will just be overridden with cache-enabled ones.

Installation

Xamarin.Forms.Nuke

  1. Install https://www.nuget.org/packages/xamarin.forms.nuke/ in your xamarin forms iOS project
  2. Add this Init method after Forms.Init call:
Xamarin.Forms.Forms.Init();
Xamarin.Forms.Nuke.FormsHandler.Init(debug: false);
LoadApplication(new App());

GlideX.Forms

  1. Install https://www.nuget.org/packages/glidex.forms/ in your xamarin forms Android project
  2. Add this one liner after your app's Forms.Init call:
Xamarin.Forms.Forms.Init (this, bundle);
//This forces the custom renderers to be used
Android.Glide.Forms.Init (this);
LoadApplication (new App ());

BOOM

You just achieved 90%+ memory reduction when manipulating Image views on both platforms.

Support for iOS < 12.2

As specified here: https://docs.microsoft.com/en-us/xamarin/ios/platform/binding-swift/walkthrough#consume-the-binding-library

You need to add the Xamarin.iOS.SwiftRuntimeSupport NuGet package to your target project if you want to support iOS 12.1 and earlier. Please read the above doc to submit an app with such support.

Known Issues

Xamarin.Forms.Nuke cannot cache images coming from the Asset Catalog:

https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/images-icons/displaying-an-image

This is due to the fact that the Asset Catalogue is packed in the ipa, and you cannot get an image URI from it. Since version 8.4.1, it will however cache correctly images respecting the density convention (@2x, @3x) locating in your Resources folder (see Issue #13).

However, if you still have some issues with your local images, you can disable Xamarin.Forms.Nuke for all FileImageSource by setting the disableFileImageSourceHandling parameter of the FormsHandler.Init to true:

Xamarin.Forms.Forms.Init();
Xamarin.Forms.Nuke.FormsHandler.Init(debug: false, disableFileImageSourceHandling: true);
LoadApplication(new App());

Benchmark

I changed a bit the glidex benchmark samples to have a more fair comparison. I switched from a random distribution of the images to a deterministic one to be sure we are comparing the same data set.

I used System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 to have the memory workload of the process. The value given in the results are the consumed bytes between the MainPage and the complete loading of the target page.

The tests have been made on an iPhone 7 (real device, not a simulator).

For each test:

  1. Launch iPhone 7
  2. Wait 4-5 seconds on MainPage
  3. Launch a Page
  4. Scroll till the end of page
  5. Get consumed bytes in the output window
  6. Empty caches
  7. Kill app
Page Data Type Xamarin.Forms 4.5.0.356 Xamarin.Forms.Nuke 8.4.0
GridOnlyRemotePage Remote only 248 905 728 15 073 280 (-94%)
GridPage Remote and local mix 195 035 136 15 040 512 (-92%)
ViewCellPage Remote and local mix 41 418 752 20 758 528 (-50%)
ImageCellPage Remote and local mix 27 000 832 20 611 072 (-24%)
HugeImagePage Local only 128 516 096 8 634 368 (-93%)

Comparison with FFImageLoading

Before I could successfully bind the Nuke swift library, I tried to use FFImageLoading as image source handler. You can find the older repository here:

https://github.com/roubachof/Xamarin.Forms.ImageSourceHandlers

As expected the native Nuke library outperforms FFImageLoading on every test.

Page Data Type FFImageLoading 2.4.11.982 Xamarin.Forms.Nuke 8.4.0
GridOnlyRemotePage Remote only 25 722 880 15 073 280 (-41%)
GridPage Remote and local mix 24 674 304 15 040 512 (-39%)
ViewCellPage Remote and local mix 28 852 224 (1) 20 758 528 (-28%)
ImageCellPage Remote and local mix 28 868 608 (2) 20 611 072 (-28%)
HugeImagePage Local only 10 059 776 8 634 368 (-14%)
  • (1) often fails to load first images (failed 7 times on 10)
  • (2) often fails to load some images (failed 6 times on 10)

And more importantly, it loads way faster the cells images:

View Cells test

FFImageLoading Nuke

Image Cells test

FFImageLoading Nuke

More Repositories

1

Sharpnado.Presentation.Forms

Presentation layer: Xamarin Forms custom components and renderers
596
star
2

Sharpnado.MaterialFrame

A modern MAUI (and XF) Frame component supporting blur, acrylic, dark mode. Implemented with RealtimeBlurView on Android (custom blurview) and UIVisualEffectView on iOS.
C#
463
star
3

Sharpnado.Tabs

Pure MAUI and Xamarin.Forms Tabs, including fixed tabs, scrollable tabs, bottom tabs, badge, segmented control, custom tabs, button tabs, bendable tabs...
C#
416
star
4

Sharpnado.Shadows

Add as many custom shadows (Color, Offset, Blur, Neumorphism) as you like to any Xamarin.Forms view (Android, iOS, UWP).
C#
329
star
5

Xamarin-Forms-Practices

Collection of good practices for Xamarin forms developement
C#
289
star
6

Sharpnado.TaskLoaderView

Free yourself from IsBusy=true! The `TaskLoaderView` is a UI component that handles all your UI loading state (Loading, Error, Result, Notification), and removes all the pain of async loading from your view models (try catch / async void / IsBusy / HasErrors / base view models / ...) thanks to its brother the `TaskLoaderNotifier`.
C#
222
star
7

Sharpnado.CollectionView

A performant list view supporting: grid, horizontal and vertical layout, drag and drop, and reveal animations.
C#
217
star
8

Sharpnado.TaskMonitor

Free yourself from async void! TaskMonitor is a component (a task wrapper) helping you to deal with "fire and forget" Task (non awaited Task) by implementing async/await best practices.
C#
95
star
9

SkiaSharpnado

SkiaSharp components and case studies for Xamarin.Forms
C#
79
star
10

Maui.Nuke

Maui version of the Nuke iOS image caching native library
C#
38
star
11

falotier_riverpod

The purpose of this PoC is to implement main real life app use cases and see if Riverpod elegantly supports all the needed mutations.
Dart
36
star
12

Xamarin.Forms.ImageSourceHandlers

GlideX.Forms + FFImageLoading.ImageSourceHandler = complete image caching solution for Xamarin.Forms without changing any line of your current project.
C#
28
star
13

Sharpnado.Acrylic

Where Sharpnado is experimenting Acrylic effects.
C#
26
star
14

NukeProxy

C#
17
star
15

Mobile.Practices.Frameworkless

Best practices for Xamarin developpement post MVVM (without binding) (Xamarin.Android and iOS)
C#
8
star
16

Sharpnado.Infrastructure

C#
5
star
17

falotier_design

Dart
5
star
18

Sharpnado.HorizontalListView

Obsolete repository, the project has been renamed to Sharpnado.CollectionView
1
star
19

SLIDES_FreeYourselfFromIsBusy

JavaScript
1
star
20

Mvvm.Flux.Maui

Showcase the mvvm flux architecture (one-way update)
C#
1
star