Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Align existing splash screen info, minor docs updates #14868

Merged
merged 6 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build/cSpell.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
"Udemy",
"UNOB",
"winui",
"xhdpi",
"xxhdpi",
"xxxhdpi",
"illinker",
"Onoh",
"Findlay",
Expand Down
33 changes: 19 additions & 14 deletions doc/articles/features/file-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ uid: Uno.Features.FileManagement

# File Management

> [!TIP]
> This article covers Uno-specific information for file management. For a full description of the feature and instructions on using it, consult the UWP documentation: https://learn.microsoft.com/en-us/windows/uwp/files/
File management allows shared reading and writing of files across all Uno Platform targets. This includes the ability to read files from the application package, as well as the ability to read and write files from the file system.

* File management allows shared reading and writing of files across all Uno Platform targets
> [!TIP]
> This article covers Uno-specific information for file management. For a full description of the feature and instructions on using it, consult Microsoft's [section](https://learn.microsoft.com/windows/uwp/files/) on the topic.

## Supported features

Expand Down Expand Up @@ -52,26 +52,31 @@ Note that you can view the content of the **IndexedDB** in the Application tab o

## Support for `StorageFile.GetFileFromApplicationUriAsync`

Uno Platform supports the ability to get package files using the [`StorageFile.GetFileFromApplicationUriAsync`](https://docs.microsoft.com/en-us/uwp/api/windows.storage.storagefile.getfilefromapplicationuriasync).
Uno Platform supports the ability to get package files using the [`StorageFile.GetFileFromApplicationUriAsync(Uri)`](https://learn.microsoft.com/uwp/api/windows.storage.storagefile.getfilefromapplicationuriasync) method.

Support per platform may vary:
- On non-WebAssembly targets, the file is available directly as it is a part of the installed package.
- On WebAssembly, the requested file is part of the application package on the remote server and is downloaded on demand to avoid increasing the initial application payload size. After it is requested for the first time, the file is then stored in the browser IndexedDB.
- On WebAssembly targets, the requested file is part of the application package on the remote server and is downloaded on demand to avoid increasing the initial application payload size. After it is requested for the first time, the file is then stored in the browser IndexedDB.
- Otherwise, the file is available directly as it is a part of the installed package.

Here's how to use it:
### General usage instructions

Ensure that a declaration exists in your project file like the following:

```csharp
var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///MyPackageFile.xml"));
var content = await FileIO.ReadTextAsync(file);
```
Given than in the project there's the following declaration:
```xml
<ItemGroup>
<Content Include="MyPackageFile.xml" />
</ItemGroup>
```

A URI with the `ms-appx:///` scheme can then be used to read a file's content:

```csharp
var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///MyPackageFile.xml"));
var content = await FileIO.ReadTextAsync(file);
```

### Support for Library provided assets

Since Uno Platform 4.6, the `GetFileFromApplicationUriAsync` method supports reading assets provided by `ProjectReference` or `PackageReference` libraries, using the following syntax:

Given a library or package named `MyLibrary01`, the following format can be used to read assets:
Expand All @@ -92,6 +97,6 @@ Make sure the server that hosts the file is configured accordingly.

## Support for `CachedFileManager`

For all targets except for UWP/WinUI and WebAssembly, the `CachedFileManager` does not provide any functionality and its methods immediately return. This allows us to easily write code that requires deferring updates on UWP and sharing it across all targets.
For all targets except WinUI/UWP and WebAssembly, the `CachedFileManager` does not provide any functionality and its methods immediately return. This allows us to easily write code that requires deferring updates on Windows but is shared across all targets.

In the case of WebAssembly, the behavior of `CachedFileManager` depends on whether the app uses the **File System Access API** or **Download picker**. This is described in detail in [file pickers documentation](windows-storage-pickers.md#webassembly).
In the case of WebAssembly, the behavior of `CachedFileManager` depends on whether the app uses the **File System Access API** or **Download picker**. This is described extensively within the [documentation](xref:Uno.Features.WSPickers#webassembly) for storage pickers.
58 changes: 33 additions & 25 deletions doc/articles/features/working-with-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Uno Platform automatically processes assets from your app's **Class Library Proj

Support for automatic generation of assets multiple resolutions from SVG or PNG is also provided using [Uno.Resizetizer](xref:Uno.Resizetizer.GettingStarted).

Platform specific assets such as [`BundleResource`](https://learn.microsoft.com/en-us/xamarin/ios/user-interface/controls/image) and [`AndroidAssets`](https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/resources-in-android/android-assets) are also supported on the heads, when required.
Platform-specific assets such as [`BundleResource`](https://learn.microsoft.com/xamarin/ios/user-interface/controls/image) and [`AndroidAssets`](https://learn.microsoft.com/xamarin/android/app-fundamentals/resources-in-android/android-assets) are also supported on the heads, when required.

## Supported asset types

Expand All @@ -31,47 +31,54 @@ At the moment, the following image file types are supported as `Content` assets:

## Adding an asset to your project

This is just like adding an asset to any UWP project. Just make sure to add the asset to a shared project to make it available to all platforms.
This is just like adding an asset to a WinUI project, except assets must be added to the shared project to make them available on all platforms.

1. Add the image file to the `Assets` directory of a shared project.
2. Set the build action to `Content`.
1. Add an image file to the `Assets` directory of the solution's shared project.
2. Select the item and set the build action to `Content`.

Using the asset is done through the `ms-appx:///` scheme.
## Referencing an asset

Here are a few examples:
Use assets added to your shared project with the `ms-appx:///` scheme.

See the examples below for XAML:
```xml
<!-- Relative path without a leading '/' uses assets from the library where the XAML is located -->
<Image Source="Assets/MyImage.png" />
<!-- Explicitly qualify the asset, when used from multiple project libraries -->
<Image Source="ms-appx:///[MyApp]/Assets/MyImage.png" />
```

You can also get assets directly using [StorageFile.GetFileFromApplicationUriAsync](file-management.md).
You can also get assets directly using [StorageFile.GetFileFromApplicationUriAsync](xref:Uno.Features.FileManagement#support-for-storagefilegetfilefromapplicationuriasync).

## Qualify an asset

On UWP, you can use qualifiers to load different assets depending on scale, language, etc.
When developing Windows apps, developers can load different assets at runtime based on attributes that qualify their visibility in the app UX. This allows you to tailor your app to different contexts to better suit users' hardware or language preferences.

For instance, such **qualifiers** can selectively load different assets depending on scale, language, theme preferences, etc. This feature is notably useful when supporting high DPI screens or the norms of differing regions.

[Microsoft: Tailor your resources for language, scale, high contrast, and other qualifiers](https://docs.microsoft.com/en-us/windows/uwp/app-resources/tailor-resources-lang-scale-contrast)
> [!NOTE]
> To become more familiar with qualifiers, check out Microsoft's documentation for a conceptual overview of the feature:
> [Microsoft: Tailor your resources for language, scale, high contrast, and other qualifiers](https://learn.microsoft.com/windows/apps/windows-app-sdk/mrtcore/tailor-resources-lang-scale-contrast)

You can do the same thing with Uno.UI, although only a subset of those qualifiers are supported.
Uno Platform allows you to use this same feature on multiple platforms. However, a subset of those qualifiers currently has support.

### Scale
### Table of scales

Not all scales are supported on all platforms:

| Scale | UWP | iOS | Android |
|-------|:-----------:|:--------:|:-------:|
| `100` | scale-100 | @1x | `mdpi` |
| `125` | scale-125 | N/A | N/A |
| `150` | scale-150 | N/A | `hdpi` |
| `200` | scale-200 | @2x | `xhdpi` |
| `300` | scale-300 | @3x | `xxhdpi` |
| `400` | scale-400 | N/A | `xxxhdpi` |
| Scale | WinUI | iOS/MacCatalyst | Android |
|-------|:-----------:|:---------------:|:-------:|
| `100` | scale-100 | @1x | mdpi |
| `125` | scale-125 | N/A | N/A |
| `150` | scale-150 | N/A | hdpi |
| `200` | scale-200 | @2x | xhdpi |
| `300` | scale-300 | @3x | xxhdpi |
| `400` | scale-400 | N/A | xxxhdpi |

We recommend including assets for each of these scales: `100`, `150`, `200`, `300` and `400`. Only compatible scales will be included to each platform.

*Note: In the Android head project (via the csproj), you can set the `UseHighDPIResources` property to `False` in debug. In those cases, only assets with scale `100` (mdpi) and scale `150` (hdpi) will be included. This reduces deployment time when debugging as fewer assets are processed and transferred to the device or simulator.*
> [!NOTE]
> In the Android head project (via the csproj), you can set the `UseHighDPIResources` property to `False` in debug. In those cases, only assets with scale `100` (mdpi) and scale `150` (hdpi) will be included. This reduces deployment time when debugging as fewer assets are processed and transferred to the device or simulator.

#### Examples

Expand All @@ -87,7 +94,7 @@ We recommend including assets for each of these scales: `100`, `150`, `200`, `30

### Language

Use it as you would on UWP, but keep in mind that some language/region combinations might not work on all platforms.
Use it as you would on WinUI/UWP, but keep in mind that some language or region combinations might not work on all platforms.

The following languages have been verified to work on all platforms:
- `en`
Expand All @@ -112,6 +119,7 @@ The following languages have been verified to work on all platforms:

### Dark theme support

> [!TIP]
> Supported on Android only

A theme qualifier can be specified for the image loader to use an asset based on the current app theme.
Expand All @@ -125,15 +133,15 @@ A theme qualifier can be specified for the image loader to use an asset based on

### Custom (platform)

Sometimes, you might want to use a different asset depending on the platform. Because there is no `platform` qualifier on UWP, Uno Platform provides the `custom` qualifier.
Sometimes, you might want to use a different asset depending on the platform. Because there is no `platform` qualifier on WinUI/UWP, Uno Platform provides the `custom` qualifier.

| Platform | Qualifier value |
|----------|-----------------|
| UWP | `uwp` |
| iOS | `ios` |
| Android | `android` |

Because the `custom` qualifier doesn't have any special meaning on UWP, we have to interpret its value manually.
Because the `custom` qualifier doesn't have any special meaning on WinUI/UWP, we have to interpret its value manually.

On iOS and Android, Uno.UI's `RetargetAssets` task automatically interprets these values and excludes unsupported platforms.

Expand Down Expand Up @@ -178,6 +186,6 @@ private void ConfigureUniversalImageLoader()
}
```

## iOS: referencing bundle images
## iOS/MacCatalyst: referencing bundle images

On iOS, bundle images can be selected using "bundle://" (e.g. bundle:///SplashScreen). When selecting the bundle resource, do not include the zoom factor, nor the file extension.
On iOS/MacCatalyst, bundle images can be selected using "bundle://" (e.g. bundle:///SplashScreen). When selecting the bundle resource, do not include the zoom factor, nor the file extension.
Loading