|
| 1 | +# Copilot Instructions for FFImageLoading.Cross |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +FFImageLoading.Cross is a .NET image loading, caching, and transforming library for .NET Android, .NET iOS, and MvvmCross. It provides configurable disk/memory caching, deduplication of download requests, placeholder support, downsampling, SVG/WebP/GIF support, fade-in animations, and built-in image transformations. |
| 6 | + |
| 7 | +## Repository Structure |
| 8 | + |
| 9 | +- `source/FFImageLoading/` — Cross-platform core library (`Cross.FFImageLoading.Core` NuGet package), targeting `net9.0;net10.0` |
| 10 | +- `source/FFImageLoading.Droid/` — Android platform implementation (`Cross.FFImageLoading.Android` NuGet package), targeting `net9.0-android;net10.0-android` |
| 11 | +- `source/FFImageLoading.Ios/` — iOS platform implementation (`Cross.FFImageLoading.Ios` NuGet package), targeting `net9.0-ios;net10.0-ios` |
| 12 | +- `samples/SampleApp.Droid/` — Sample Android application demonstrating library usage |
| 13 | +- `Directory.Build.props` — Shared MSBuild properties, multi-target framework versions (`NetVersion`, `NetVersionAndroid`, `NetVersionIos`), and NuGet package metadata |
| 14 | + |
| 15 | +## Build & Development Setup |
| 16 | + |
| 17 | +### Prerequisites |
| 18 | + |
| 19 | +- .NET 9 and .NET 10 SDKs |
| 20 | +- Android and iOS workloads: `dotnet workload install android ios` |
| 21 | + |
| 22 | +### Build Commands |
| 23 | + |
| 24 | +```bash |
| 25 | +dotnet restore |
| 26 | +dotnet build -c Release |
| 27 | +``` |
| 28 | + |
| 29 | +### CI/CD |
| 30 | + |
| 31 | +- **CI** (`.github/workflows/ci.yml`): Runs on `macos-latest` on push/PR to `master`. Installs android + ios workloads, restores, and builds. |
| 32 | +- **Publish** (`.github/workflows/publish.yml`): Triggers on GitHub release. Uses NuGet Trusted Publishing via `nuget/login@v1` with OIDC to push packages. |
| 33 | + |
| 34 | +## Code Style & Conventions |
| 35 | + |
| 36 | +### General |
| 37 | + |
| 38 | +- Follow the `.editorconfig` at the repo root for all formatting rules. |
| 39 | +- C# files use **tabs** for indentation (size 4), with `utf-8-bom` encoding. |
| 40 | +- XML/JSON files use **spaces** (indent size 2). |
| 41 | +- Nullable reference types are enabled globally (`<Nullable>enable</Nullable>`). |
| 42 | +- Implicit usings are enabled globally (`<ImplicitUsings>enable</ImplicitUsings>`). |
| 43 | + |
| 44 | +### Naming Conventions |
| 45 | + |
| 46 | +- **PascalCase** for constants, methods, properties, classes, interfaces, enums, structs, delegates, and events. |
| 47 | +- **camelCase** for parameters and local variables. |
| 48 | +- **_camelCase** (underscore prefix) for private fields (e.g., `_initialized`, `_config`, `_disposed`). |
| 49 | +- Avoid `this.` qualification unless necessary. |
| 50 | +- Use language keywords over framework types (e.g., `string` not `String`). |
| 51 | + |
| 52 | +### Code Style Preferences |
| 53 | + |
| 54 | +- Methods, constructors, and operators: prefer **block bodies**. |
| 55 | +- Properties, indexers, and accessors: prefer **expression bodies**. |
| 56 | +- Use pattern matching over `is`/`as` with casts. |
| 57 | +- Use inline variable declarations. |
| 58 | +- Use null-coalescing (`??`) and null-propagation (`?.`) operators. |
| 59 | +- Allman brace style — opening braces on a new line. |
| 60 | + |
| 61 | +## Architecture & Key Patterns |
| 62 | + |
| 63 | +### Namespaces |
| 64 | + |
| 65 | +- Core types: `FFImageLoading`, `FFImageLoading.Work`, `FFImageLoading.Cache`, `FFImageLoading.Config`, `FFImageLoading.Helpers` |
| 66 | +- Android-specific: `FFImageLoading.Droid`, `FFImageLoading.Droid.*` |
| 67 | +- iOS-specific: `FFImageLoading.Ios`, `FFImageLoading.Ios.*` |
| 68 | +- Shared public view: `FFImageLoading.Cross` (contains `MvxCachedImageView` on both platforms) |
| 69 | + |
| 70 | +### Key Types |
| 71 | + |
| 72 | +- `ImageServiceBase<TImageContainer>` — Abstract base providing the core image service logic. Platform implementations override abstract methods for platform-specific behavior. |
| 73 | +- `ImageService` — Platform-specific singleton (in `FFImageLoading.Droid` / `FFImageLoading.Ios`). Access via `ImageService.Instance`. Call `Initialize()` before use. |
| 74 | +- `TaskParameter` — Fluent API for configuring image loading tasks (via `FromFile`, `FromUrl`, `FromEmbeddedResource`, etc.). |
| 75 | +- `MvxCachedImageView` — The primary image view for both Android (`Android.Widget.ImageView` subclass) and iOS (`UIImageView` subclass), registered as `ffimageloading.cross.MvxCachedImageView` on Android. |
| 76 | +- `Configuration` — Centralized configuration (caching, timeouts, logging, animations, etc.). |
| 77 | +- `ITransformation` — Interface for image transformations (blur, circle, crop, grayscale, etc.). |
| 78 | + |
| 79 | +### Data Resolver Pattern |
| 80 | + |
| 81 | +- `DataResolverResult` supports dual paths: **Stream** (for standard bitmap decoding) or **Decoded** (pre-decoded image, bypasses decoder). XML/vector drawables on Android must use the Decoded path. |
| 82 | +- Platform-specific resolvers: `ResourceDataResolver`, `BundleDataResolver`, `UrlDataResolver`, etc. |
| 83 | + |
| 84 | +## Multi-Targeting |
| 85 | + |
| 86 | +- Target framework versions are centralized in `Directory.Build.props` via properties: |
| 87 | + - `NetVersion` = `net9.0;net10.0` |
| 88 | + - `NetVersionAndroid` = `net9.0-android;net10.0-android` |
| 89 | + - `NetVersionIos` = `net9.0-ios;net10.0-ios` |
| 90 | +- Android uses conditional `TargetPlatformVersion`: 35 for net9.0, 36.1 for net10.0. |
| 91 | + |
| 92 | +## NuGet Packages |
| 93 | + |
| 94 | +The repo produces three packages (with `GeneratePackageOnBuild=true`): |
| 95 | + |
| 96 | +| Package | Project | |
| 97 | +|---|---| |
| 98 | +| `Cross.FFImageLoading.Core` | `source/FFImageLoading/` | |
| 99 | +| `Cross.FFImageLoading.Android` | `source/FFImageLoading.Droid/` | |
| 100 | +| `Cross.FFImageLoading.Ios` | `source/FFImageLoading.Ios/` | |
| 101 | + |
| 102 | +## Adding Transformations |
| 103 | + |
| 104 | +Transformations follow a consistent pattern: |
| 105 | +1. Create a platform-agnostic class in `source/FFImageLoading/Transformations/` inheriting common logic. |
| 106 | +2. Create platform-specific implementations in `source/FFImageLoading.Droid/Transformations/` and `source/FFImageLoading.Ios/Transformations/`, typically extending `TransformationBase`. |
| 107 | +3. Implement the `ITransformation` interface with a `Key` property and `Transform` method. |
0 commit comments