luberda-molinet / FFImageLoading

Image loading, caching & transforming library for Xamarin and Windows
MIT License
1.41k stars 377 forks source link

Support XmlnsDefinitionAttribute with custom http://ffimageloading.com url #1204

Open dansiegel opened 5 years ago

dansiegel commented 5 years ago

Description

The version of Xamarin.Forms that this is built against should be bumped to 3.5 to allow support for the XmlnsDefinitionAttribute.

Current API

With the existing API a new fully qualified xmlns is required for each unique CLR Namespace / Assembly pair.

<ContentPage xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms" 
             xmlns:fftransformations="clr-namespace:FFImageLoading.Transformations;assembly=FFImageLoading.Transformations">
<ffimageloading:CachedImage HorizontalOptions="Center" 
                            VerticalOptions="Center"
                            LoadingPlaceholder="loading.png" 
                            ErrorPlaceholder="error.png" 
                            DownsampleToViewSize="true"
                            Aspect="AspectFill" 
                            HeightRequest="150"
                            WidthRequest="150">
            <ffimageloading:CachedImage.Transformations>
                <fftransformations:GrayscaleTransformation/>
                <fftransformations:RoundedTransformation Radius="60"/>
            </ffimageloading:CachedImage.Transformations>
        </ffimageloading:CachedImage>

Proposed API

Updating to Xamarin.Forms 3.5 definitions can be added to each project to expose the namespaces that are relevant to Forms Developers.

// In FFImageLoading.Forms
[assembly: XmlnsDefinition("http://ffimageloading.com", "FFImageLoading.Forms")]
[assembly: XmlnsDefinition("http://ffimageloading.com", "FFImageLoading.Transformations", AssemblyName = "FFImageLoading.Transformations")]
<ContentPage xmlns:ffimageloading="http://ffimageloading.com">
<ffimageloading:CachedImage HorizontalOptions="Center" 
                            VerticalOptions="Center"
                            LoadingPlaceholder="loading.png" 
                            ErrorPlaceholder="error.png" 
                            DownsampleToViewSize="true"
                            Aspect="AspectFill" 
                            HeightRequest="150"
                            WidthRequest="150">
            <ffimageloading:CachedImage.Transformations>
                <ffimageloading:GrayscaleTransformation/>
                <ffimageloading:RoundedTransformation Radius="60"/>
            </ffimageloading:CachedImage.Transformations>
        </ffimageloading:CachedImage>
daniel-luberda commented 5 years ago

Love it. Will definitely implement this soon.