Skip to content

Commit

Permalink
docs: Add guidelines for implementing WinUI/WinRT features
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Aug 25, 2021
1 parent 4947bc1 commit bde528b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Guidelines for implementing a new WinUI/WinRT API

Implementing a new WinUI/WinRT API generally requires to:
- Find the generated API source file (e.g. `src\Uno.UWP\Generated\3.0.0.0\Windows.Data.Pdf\PdfDocument.cs`)
- Copy the file to the non-generated location (e.g. `src\Uno.UWP\Data.Pdf\PdfDocument.cs`)
- Keep only the members that need to be implemented in the non-generated location
- Remove (completely or partially depending on the platforms) the implemented members in the generated file

If your API implementation is for a specific platform:
- You can use a platform suffix in the source file name (`PdfDocument.android.cs`) so the file is built only for this platform
- Remove the parts that relate to your platform in the `NotImplemented` attribute:
```
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Data.Pdf.PdfPageDimensions Dimensions
{
#endif
```
becomes
```
#if false || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
[global::Uno.NotImplemented("__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::Windows.Data.Pdf.PdfPageDimensions Dimensions
{
#endif
```
when implemented for Android only.
When implementing a feature, try to place as much code as possible in a common source file (a non-suffixed file), so that it is reused across platforms. Make sure to follow [partial classes coding guidelines](code-style.md).
Note that the generated files may be overriden at any point, and placing custom code (aside from changing the `NotImplemented` values) will be overwritten.
2 changes: 2 additions & 0 deletions doc/articles/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@
href: contributing/guidelines/updating-dependencies.md
- name: Guidelines for issue triage
href: contributing/guidelines/issue-triage.md
- name: Guidelines for implementing a new WinUI/WinRT feature
href: contributing/guidelines/implementing-a-new winui-winrt-feature.md
- name: Adding documentation
href: uno-development/doc-on-docs.md
- name: DocFX
Expand Down
15 changes: 15 additions & 0 deletions doc/articles/uno-development/building-uno-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,18 @@ The versions used are centralized in the [Directory.Build.targets](https://githu
locations where `<PackageReference />` are used.

When updating the versions of nuget packages, make sure to update all the .nuspec files in the [Build folder](https://github.com/unoplatform/uno/tree/master/build).

### Running the SyncGenerator tool

Uno Platform uses a tool which synchronizes all WinRT and WinUI APIs with the type implementations already present in Uno. This ensures that all APIs are present for consumers of Uno, even if some are not implemented.

The synchronization process takes the APIs provided by the WinMD files referenced by the `Uno.UWPSyncGenerator.Reference` project and generates stubbed classes for types in the `Generated` folders of Uno.UI, Uno.Foundation and Uno.WinRT projects. If the generated classes have been partially implemented in Uno (in the non-Generated folders), the tool will automatically skip those implemented methods.

The tool needs to be run on Windows because of its dependency on the Windows SDK WinMD files.

To run the synchronization tool:
- Open a `Developer Command Prompt for Visual Studio` (2019 or 2022)
- Go the the `uno\build` folder (not the `uno\src\build` folder)
- Run the `run-api-sync-tool.cmd` script; make sure to follow the instructions

Note that as of Uno 3.10, the tool is manually run for the UWP part of the build and automatically run as part of the CI during the WinUI part of the build.
4 changes: 4 additions & 0 deletions doc/articles/uno-development/contributing-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Whether you're fixing a bug or working on a new feature, [inspecting the visual

See [Uno's code conventions and common patterns here](../contributing/guidelines/code-style.md).

## Implementing a new feature

See how to implement a new [feature here](../contributing/guidelines/implementing-a-new winui-winrt-feature.md).

## Adding tests

Uno's stability rests upon a comprehensive testing suite. A code contribution usually isn't complete without a test.
Expand Down

0 comments on commit bde528b

Please sign in to comment.