Skip to content

Commit

Permalink
Merge branch 'main' into FixWindowsMediaSourceDisposalBug
Browse files Browse the repository at this point in the history
  • Loading branch information
ne0rrmatrix authored Feb 4, 2025
2 parents dcd70c0 + 62f4e2d commit d317525
Show file tree
Hide file tree
Showing 83 changed files with 1,147 additions and 469 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ env:
LATEST_NET_VERSION: '9.0.x'
PathToCommunityToolkitAnalyzersBenchmarkCsproj: 'src/CommunityToolkit.Maui.Analyzers.Benchmarks/CommunityToolkit.Maui.Analyzers.Benchmarks.csproj'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
run_benchmarks:
name: Run Benchmarks
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-15]

Expand Down
30 changes: 21 additions & 9 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ env:
PathToCommunityToolkitMediaElementCsproj: 'src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj'
PathToCommunityToolkitMapsCsproj: 'src/CommunityToolkit.Maui.Maps/CommunityToolkit.Maui.Maps.csproj'
PathToCommunityToolkitSampleCsproj: 'samples/CommunityToolkit.Maui.Sample/CommunityToolkit.Maui.Sample.csproj'
PathToCommunityToolkitUnitTestCsproj: 'src/CommunityToolkit.Maui.UnitTests/CommunityToolkit.Maui.UnitTests.csproj'
PathToCommunityToolkitUnitTestCsproj: 'src/CommunityToolkit.Maui.UnitTests'
PathToCommunityToolkitAnalyzersCsproj: 'src/CommunityToolkit.Maui.Analyzers/CommunityToolkit.Maui.Analyzers.csproj'
PathToCommunityToolkitCameraAnalyzersCsproj: 'src/CommunityToolkit.Maui.Camera.Analyzers/CommunityToolkit.Maui.Camera.Analyzers.csproj'
PathToCommunityToolkitMediaElementAnalyzersCsproj: 'src/CommunityToolkit.Maui.MediaElement.Analyzers/CommunityToolkit.Maui.MediaElement.Analyzers.csproj'
Expand All @@ -41,16 +41,21 @@ env:
PathToCommunityToolkitAnalyzersCodeFixCsproj: 'src/CommunityToolkit.Maui.Analyzers.CodeFixes/CommunityToolkit.Maui.Analyzers.CodeFixes.csproj'
PathToCommunityToolkitCameraAnalyzersCodeFixCsproj: 'src/CommunityToolkit.Maui.Camera.Analyzers.CodeFixes/CommunityToolkit.Maui.Camera.Analyzers.CodeFixes.csproj'
PathToCommunityToolkitMediaElementAnalyzersCodeFixCsproj: 'src/CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes/CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes.csproj'
PathToCommunityToolkitAnalyzersUnitTestCsproj: 'src/CommunityToolkit.Maui.Analyzers.UnitTests/CommunityToolkit.Maui.Analyzers.UnitTests.csproj'
PathToCommunityToolkitAnalyzersUnitTestCsproj: 'src/CommunityToolkit.Maui.Analyzers.UnitTests'
PathToCommunityToolkitAnalyzersBenchmarkCsproj: 'src/CommunityToolkit.Maui.Analyzers.Benchmarks/CommunityToolkit.Maui.Analyzers.Benchmarks.csproj'
CommunityToolkitSampleApp_Xcode_Version: '16.2'
CommunityToolkitLibrary_Xcode_Version: '16.2'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build_sample:
name: Build Sample App using Latest .NET SDK
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-15]
steps:
Expand Down Expand Up @@ -90,9 +95,8 @@ jobs:
build_library:
name: Build Library
runs-on: ${{ matrix.os }}
env:
VSTEST_TESTHOST_SHUTDOWN_TIMEOUT: 1100 # Fixes "The active test run was aborted. Reason: Test host process crashed"
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-15]
steps:
Expand Down Expand Up @@ -189,16 +193,24 @@ jobs:
- name: 'Build CommunityToolkit.Maui'
run: dotnet build ${{ env.PathToLibrarySolution }} -c Release -p:PackageVersion=${{ env.NugetPackageVersion }} -p:Version=${{ env.NugetPackageVersion }}

- name: Run All Unit Tests
run: dotnet test -c Release ${{ env.PathToLibrarySolution }} --settings ".runsettings" --collect "XPlat code coverage" --logger trx --results-directory ${{ runner.temp }}
- name: Run CommunityToolkit Analyzers UnitTests
run: |
cd ${{ env.PathToCommunityToolkitAnalyzersUnitTestCsproj }}
dotnet run -c Release --results-directory "${{ runner.temp }}" --coverage --coverage-output "${{ runner.temp }}/ut-analyzers.cobertura.xml" --coverage-output-format cobertura --report-xunit
- name: Run CommunityToolkit UnitTests
run: |
cd ${{ env.PathToCommunityToolkitUnitTestCsproj }}
dotnet run -c Release --results-directory "${{ runner.temp }}" --coverage --coverage-output "${{ runner.temp }}/ut.cobertura.xml" --coverage-output-format cobertura --report-xunit
- name: Publish Test Results
if: runner.os == 'Windows'
if: runner.os == 'Windows' && (${{ success() || failure() }})
uses: actions/upload-artifact@v4
with:
name: Test Results
name: Test Results ${{ github.run_number }} ${{ runner.os }}
path: |
${{ runner.temp }}/**/*.trx
${{ runner.temp }}/*.xunit
${{ runner.temp }}/*cobertura.xml
- name: Pack CommunityToolkit.Maui.Core NuGet
run: dotnet pack -c Release ${{ env.PathToCommunityToolkitCoreCsproj }} -p:PackageVersion=${{ env.NugetPackageVersion }}
Expand Down
61 changes: 38 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Having that said, if you are a first-timer and you could use some help please re

Furthermore, for anyone, we would like you to take into consideration the following guidelines.

## Kindness

### Make an effort to be nice

If you disagree, that's fine. We don't think about everything the same way, be respectful and at some point decide to agree to disagree. If a decision needs to be made, try to involve at least one other person without continuing an endless discussion.
Expand All @@ -20,13 +22,13 @@ During a code review try to make a habit out of it to say at least one nice thin

Remember English is not everyones native language. Written communication always lacks non-verbal communication. With written communication in a language that is not your native tongue it is even harder to express certain emotions.

Always assume that people mean to do right. Try to read a sentence a couple of times over and take things more literal. Try to place yourself in their shoes and see the message beyond the actual words.
Always assume that people mean to do right. Try to read a sentence a couple of times over and take things more literal. Try to place yourself in their shoes and see the message beyond the actual words.

Things might come across different than they were intended, please keep that in mind and always check to see how someone meant it. If you're not sure, pull someone offline in a private channel on Twitter or email and chat about it for a bit. Maybe even jump on a call to collaborate. We're living in the 21st century, all the tools are there, why not use them to get to know each other and be friends?!

Besides language, we understand that contributing to open-source mostly happens in your spare time. Remember that priorities might change and we can only spend our time once. This works as a two-way street: don't expect things to be solved instantly, but also please let us know if you do not have the capacity to finish work you have in progress. There is no shame in that. That way it's clear to other people that they can step in and take over.

### THANK YOU!
### THANK YOU

Lastly, a big thank you for spending your precious time on our project. We appreciate any effort you make to help us with this project.

Expand All @@ -45,7 +47,7 @@ We will take appropriate actions and measures if necessary.
1. Install latest stable [.NET SDK](https://dotnet.microsoft.com/en-us/download)
1. Install .NET MAUI workloads (we recommend using Visual Studio installer)

> You will need to complete a Contribution License Agreement before any pull request can be accepted. Complete the CLA at https://cla.dotnetfoundation.org/. This will also be triggered whenever you open a PR and the link should guide you through it.
> You will need to complete a Contribution License Agreement before any pull request can be accepted. Complete the CLA at <https://cla.dotnetfoundation.org/>. This will also be triggered whenever you open a PR and the link should guide you through it.
## Reporting a bug

Expand All @@ -59,10 +61,10 @@ We always request a reproduction sample, and that's not to make your life hard o
And most important: **Please, help us to help you ❤️**


## Opening a PR process

### TL;DR

* Find an issue/feature, make sure that the issue/feature has been `Approved` and is welcomed (also see [New Features](https://github.com/CommunityToolkit/Maui#submitting-a-new-feature))
* Fork repository
* Create branch
Expand All @@ -73,13 +75,16 @@ And most important: **Please, help us to help you ❤️**

### Please consider

#### Tabs vs. Spaces?!
#### Tabs vs. Spaces?

[Tabs](https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/).

#### Make your changes small, don't keep adding

We love your enthusiasm, but small changes and small PRs are easier to digest. We're all doing this in our spare time, it is easier to review a couple of small things and merge that and iterate from there than to have a PR with 100+ files changed that will sit there forever.

#### Added features should have tests, a sample and documentation

We like quality as much as the next person, so please provide tests.

In addition, we would want a new feature or change to be as clear as possible for other developers. Please add a sample to the sample app as part of your PR and also provide a PR to our [documentation repository](https://github.com/MicrosoftDocs/CommunityToolkit).
Expand All @@ -88,67 +93,75 @@ In addition, we would want a new feature or change to be as clear as possible fo

If you are unsure on where to locate the changes you need to make then please use the following section and flowchart.

![](https://user-images.githubusercontent.com/13558917/145694198-7addbd35-0e5f-4816-b351-759a01ec2672.png)
![New Code Workflow](https://user-images.githubusercontent.com/13558917/145694198-7addbd35-0e5f-4816-b351-759a01ec2672.png)

### CommunityToolkit.Maui.Core

In general, this project will have all the basement to develop our Toolkit, including some primitive types, interfaces and base classes, base views, and common code. This will be referenced by other Frameworks/Toolkit based on .NET MAUI that wants to have the same features that us.

Here we will have some:
We ask that all classes in `CommunityToolkit.Maui.Core` are `public`. This allows developers to extend `CommunityToolkit.Maui.Core`. The `[EditorBrowsable(EditorBrowsableState.Never)]` attribute can be added to classes that we don't recommend developers discovering.

- BaseViews, could be Views that will be used by other Views, like PaddingButton (that's used by Snackbar) or the MauiPopup (used by Popup) that will be a native control implemented in a way that can work with our handler. This same approach is used here
Here is an example of classes that will

- Primitives, which will be base types that can be used by everyone, like our MathOperator. So other frameworks may not have the concept of Behavior or Converter but they can mimic them as helper classes/methods and use our primitives.
* BaseViews, could be Views that will be used by other Views, like PaddingButton (that's used by Snackbar) or the MauiPopup (used by Popup) that will be a native control implemented in a way that can work with our handler. This same approach is used here

- Common Code, this will be all generic code (platform-specific or not) that can be used by other Frameworks/Toolkits
* Primitives, which will be base types that can be used by everyone, like our MathOperator. So other frameworks may not have the concept of Behavior or Converter but they can mimic them as helper classes/methods and use our primitives.

- Layout Managers, were introduced on .NET MAUI and they live on Microsoft.Maui.Core so makes sense to have our managers on Core as well.
* Common Code, this will be all generic code (platform-specific or not) that can be used by other Frameworks/Toolkits

- Handlers, on Core will be the most general Handler with the majority of features.
* Layout Managers, were introduced on .NET MAUI and they live on Microsoft.Maui.Core so makes sense to have our managers on Core as well.

### CommunityToolkit.Maui:
* Handlers, on Core will be the most general Handler with the majority of features.

### CommunityToolkit.Maui

This project has a reference to the Core project. Here will live the implementation of our Controls, Views, Behaviors, Animations, etc. In other words, this project will work with the .NET MAUI and will be MVVM friendly. Also, other Toolkits/Frameworks can reference this package if needed.

Here we will have some:

- View Implementation, with BindableProperties, support to attach effects, behaviors, triggers, and all that jazz.
* View Implementation, with BindableProperties, support to attach effects, behaviors, triggers, and all that jazz.

- Platform Configuration, that is Platform-specific features, that can relate to some control - like the ArrowDirection that is part of Popup and works just on iOS - or the application itself - like the StatusBarColorEffect from XCT.
* Platform Configuration, that is Platform-specific features, that can relate to some control - like the ArrowDirection that is part of Popup and works just on iOS - or the application itself - like the StatusBarColorEffect from XCT.

- Handlers Implementation, We will add to our PropertyMapper and/or CommandMapper any Platform Configuration that some Handler/View may have. We also can implement here some features that we think will not be great to have on Core. Here is a reference for this
* Handlers Implementation, We will add to our PropertyMapper and/or CommandMapper any Platform Configuration that some Handler/View may have. We also can implement here some features that we think will not be great to have on Core. Here is a reference for this

- Layout, will be the implementation of ours custom layouts and will use the Layout Managers on Core
* Layout, will be the implementation of ours custom layouts and will use the Layout Managers on Core

## Contributing Code - Best Practices

### Debug Logging

* Always use `Trace.WriteLine()` instead of `Debug.WriteLine` for debug logging because `Debug.WriteLine` is removed by the compiler in Release builds

### Methods Returning Task and ValueTask

* Always include a `CancellationToken` as a parameter to every method returning `Task` or `ValueTask`
* If the method is public, provide a the default value for the `CancellationToken` (eg `CancellationToken token = default`)
* If the method is not publc, do not provide a default value for the `CancellationToken`
* Use `CancellationToken.ThrowIfCancellationRequested()` to verify the `CancellationToken`

### Enums

* Always use `Unknown` at index 0 for return types that may have a value that is not known
* Always use `Default` at index 0 for option types that can use the system default option
* Follow naming guidelines for tense... `SensorSpeed` not `SensorSpeeds`
* Assign values (0,1,2,3) for all enums

### Property Names

* Include units only if one of the platforms includes it in their implementation. For instance HeadingMagneticNorth implies degrees on all platforms, but PressureInHectopascals is needed since platforms don't provide a consistent API for this.

### Units

* Use the standard units and most well accepted units when possible. For instance Hectopascals are used on UWP/Android and iOS uses Kilopascals so we have chosen Hectopascals.

### Pattern matching

#### Null checking

* Prefer using `is` when checking for null instead of `==`.

e.g.
e.g.

```csharp
// null
Expand Down Expand Up @@ -180,9 +193,10 @@ if (something is Bucket bucket)
```

### File Scoped Namespaces

* Use [file scoped namespaces](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces) to help reduce code verbosity.

e.g.
e.g.

```csharp
namespace CommunityToolkit.Maui.Converters;
Expand Down Expand Up @@ -215,13 +229,13 @@ In other words, `NotImplementedException` implies that a feature is still in dev

### Bug Fixes

If you're looking for something to fix, please browse [open issues](https://github.com/CommunityToolkit/Maui/issues).
If you're looking for something to fix, please browse [open issues](https://github.com/CommunityToolkit/Maui/issues).

Follow the style used by the [.NET Foundation](https://github.com/dotnet/runtime/blob/master/docs/coding-guidelines/coding-style.md), with two primary exceptions:

- We do not use the `private` keyword as it is the default accessibility level in C#.
- We will **not** use `_` or `s_` as a prefix for internal or private field names
- We will use `camelCaseFieldName` for naming internal or private fields in both instance and static implementations
* We do not use the `private` keyword as it is the default accessibility level in C#.
* We will **not** use `_` or `s_` as a prefix for internal or private field names
* We will use `camelCaseFieldName` for naming internal or private fields in both instance and static implementations

Read and follow our [Pull Request template](https://github.com/CommunityToolkit/Maui/blob/main/.github/PULL_REQUEST_TEMPLATE.md)

Expand All @@ -230,6 +244,7 @@ Read and follow our [Pull Request template](https://github.com/CommunityToolkit/
To propose a change or new feature, review the guidance on [Submitting a New Feature](https://github.com/CommunityToolkit/Maui#submitting-a-new-feature).

#### Non-Starter Topics

The following topics should generally not be proposed for discussion as they are non-starters:

* Large renames of APIs
Expand Down
File renamed without changes.
2 changes: 2 additions & 0 deletions samples/CommunityToolkit.Maui.Sample.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3ED2C978-9DDB-48FE-8C5A-521B254F18A3}"
ProjectSection(SolutionItems) = preProject
..\.editorconfig = ..\.editorconfig
..\.github\workflows\benchmarks.yml = ..\.github\workflows\benchmarks.yml
..\Directory.Build.props = ..\Directory.Build.props
..\Directory.Build.targets = ..\Directory.Build.targets
..\.github\workflows\dotnet-build.yml = ..\.github\workflows\dotnet-build.yml
..\global.json = ..\global.json
EndProjectSection
EndProject
Expand Down
4 changes: 2 additions & 2 deletions samples/CommunityToolkit.Maui.Sample/Models/PopupSize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ public PopupSizeConstants(IDeviceDisplay deviceDisplay)
{
Tiny = new(100, 100);
Small = new(300, 300);
Medium = new(0.7 * (deviceDisplay.MainDisplayInfo.Width / deviceDisplay.MainDisplayInfo.Density), 0.6 * (deviceDisplay.MainDisplayInfo.Height / deviceDisplay.MainDisplayInfo.Density));
Large = new(0.9 * (deviceDisplay.MainDisplayInfo.Width / deviceDisplay.MainDisplayInfo.Density), 0.8 * (deviceDisplay.MainDisplayInfo.Height / deviceDisplay.MainDisplayInfo.Density));
Medium = new(0.4 * (deviceDisplay.MainDisplayInfo.Width / deviceDisplay.MainDisplayInfo.Density), 0.6 * (deviceDisplay.MainDisplayInfo.Height / deviceDisplay.MainDisplayInfo.Density));
Large = new(0.5 * (deviceDisplay.MainDisplayInfo.Width / deviceDisplay.MainDisplayInfo.Density), 0.8 * (deviceDisplay.MainDisplayInfo.Height / deviceDisplay.MainDisplayInfo.Density));
}

// examples for fixed sizes
Expand Down
Loading

0 comments on commit d317525

Please sign in to comment.