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

Maui Community Toolkit Camera trimming bug #9738

Open
ne0rrmatrix opened this issue Jan 31, 2025 · 4 comments
Open

Maui Community Toolkit Camera trimming bug #9738

ne0rrmatrix opened this issue Jan 31, 2025 · 4 comments
Assignees
Labels
Area: Linker Issues when linking assemblies.

Comments

@ne0rrmatrix
Copy link

Android framework version

net9.0-android

Affected platform version

VS 2022, Dotnet Maui 9.102, CommunityTookit Camera

Description

I am trying to figure out how to fix the Maui Community toolkit Camera package. When in debug mode everything works as expected. In Release mode the Zoom in and out do not work. I have isolated it to the sample app trimming out Xamarin.AndroidX.Camera.Core. Adding this to sample app project fixes the bug

<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
   <TrimmerRootDescriptor Include="ILLink.Descriptors.xml"/>
 </ItemGroup> 

The ILLink.Descriptors.xml

<?xml version="1.0" encoding="UTF-8" ?>
<linker>
  <assembly fullname="Xamarin.AndroidX.Camera.Core" />
</linker>

I would prefer to fix the trimming issue and not have to rely on having to ask consumers of a nuget package to add a TrimmerRootDescriptor xml file to csproj. I have included the build Android-arm64 linked folder as a zip file.

linked.zip

Steps to Reproduce

  1. Run this project. https://github.com/CommunityToolkit/Maui/tree/main/samples
  2. Goto Views, open the camera app in Release mode.
  3. Set zoom slider or click to zoom in and out.
  4. Issue is that zoom in and out does not work. Everything else works fine.
  5. Issue does not occur in Debug mode.

Did you find any workaround?

Add a ILLinkDescriptors.xml to sample app and that fixes it. Prevent Xamarin.AndroidX.Camera.Core from being trimmed.

Relevant log output

@ne0rrmatrix ne0rrmatrix added Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Jan 31, 2025
@jonathanpeppers
Copy link
Member

Issue is that zoom in and out does not work. Everything else works fine.

Can you describe more why it doesn't work? Is an exception thrown? Which method doesn't work as expected? Can you share a link to it?

@jonathanpeppers jonathanpeppers self-assigned this Jan 31, 2025
@jonathanpeppers jonathanpeppers removed the needs-triage Issues that need to be assigned. label Jan 31, 2025
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone Jan 31, 2025
@jonathanpeppers jonathanpeppers added Area: Linker Issues when linking assemblies. and removed Area: App Runtime Issues in `libmonodroid.so`. labels Jan 31, 2025
@ne0rrmatrix
Copy link
Author

The min and max zoom report static values of 1 in release mode. In debug mode the values are different. I check that value I want to set is above min value and below max. The value reported for camera max and min is same value in release mode. In debug it shows the cameras values. In release mode it shows static default values.

@ne0rrmatrix
Copy link
Author

Here is link to function I am calling. https://github.com/CommunityToolkit/Maui/blob/d694f5f11d66c15718886c01d370089347822436/src/CommunityToolkit.Maui.Camera/CameraManager.android.cs on line 64 I call

public partial void UpdateZoom(float zoomLevel)
	{
		cameraControl?.SetZoomRatio(zoomLevel);
	}

Here is relevant bindings file: https://github.com/CommunityToolkit/Maui/blob/main/src/CommunityToolkit.Maui.Camera/Views/CameraView.shared.cs
Line 254 - 274

static object CoerceZoom(BindableObject bindable, object value)
	{
		var cameraView = (CameraView)bindable;
		var input = (float)value;

		if (cameraView.SelectedCamera is null)
		{
			return input;
		}

		if (input < cameraView.SelectedCamera.MinimumZoomFactor)
		{
			input = cameraView.SelectedCamera.MinimumZoomFactor;
		}
		else if (input > cameraView.SelectedCamera.MaximumZoomFactor)
		{
			input = cameraView.SelectedCamera.MaximumZoomFactor;
		}

		return input;
	}

@ne0rrmatrix
Copy link
Author

If I remove the check for min and max zoom I can zoom in and out. I have narrowed it down to the min and max zoom are not available. It is simply reporting default values as set by my project for when they are not available. In release mode for what ever reason those values are not available when trimming is on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Linker Issues when linking assemblies.
Projects
None yet
Development

No branches or pull requests

3 participants