dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.94k stars 533 forks source link

DesignMode.IsDesignModeEnabled not working as expected. #7765

Closed mattleibow closed 1 year ago

mattleibow commented 1 year ago

Issue moved from dotnet/maui#7773


From @beto-rodriguez on Sunday, June 5, 2022 6:07:45 PM

Description

The DesignMode.IsDesignModeEnabled is not working as it should. The property value is true even when it is running inside the Android emulator:

true if the applications is being run in a previewer, false is the applications is being run on a device or emulator.

Steps to Reproduce

  1. Clone https://github.com/beto-rodriguez/MauiDesignModeBug
  2. Run the application and see the output console.

If ran on WinUI:

image

If ran on Android emulator:

image

You can find additional information about this issue at https://github.com/dotnet/maui/issues/7350

Version with bug

6.0 Release Candidate 3

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 12 (at least)

Did you find any workaround?

No

Relevant log output

No response

mattleibow commented 1 year ago

Issue moved from dotnet/maui#7773


From @kristinx0211 on Monday, June 6, 2022 5:03:09 AM

verified repro on android 12 with vs 17.3.0 Preview 3.0 [32605.41.main]. image

jpobst commented 1 year ago

@mattleibow DesignMode.IsDesignModeEnabled seems to be an API provided by MAUI and does not seem to call into any XA function. Can you clarify where in XA the issue potentially is?

ghost commented 1 year ago

Hi @mattleibow. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

mattleibow commented 1 year ago

I was just moving an issue from @beto-rodriguez

beto-rodriguez commented 1 year ago

I do not know know if this issue belongs to Xamarin or MAUI but you can reproduce the issue in the provided repo.

mattleibow commented 1 year ago

Maybe we need to go back to the OG issue. You are saying that the property says it is not in design mode when on the emulator? I think that behavior is correct as the emulator is not design mode. It is a running app in a valid environment.

Are you looking for a way to determine a device vs emulator? This is sometimes had as emulators try their best to pretend. But you can maybe try the essentials api DeviceInfo and is the type physical vs emulator.

beto-rodriguez commented 1 year ago

The problem I see is that the property does not behave as the documentation says, the docs say:

true if the applications is being run in a previewer, false is the applications is being run on a device or emulator.

So according to the docs, it seems like a bug.

In my case this issue causes that a SkiaSharp-based control is not drawn in the emulator, you can find more info about the case at https://github.com/dotnet/maui/issues/7350.

beto-rodriguez commented 1 year ago

In the case of LiveCharts, the issue is that I cannot load SkiaSharp in the designer (not sure if possible), So when the chart is in the designer, I just do not draw the control. That seems to work fine, but only in MAUI the library has this issue.

jpobst commented 1 year ago

This is a MAUI API, so I don't think there's anything for XA to do here. https://github.com/dotnet/maui/blob/ff02f57419b5337e430cc9d9fc4d6c28577876a4/src/Controls/src/Core/DesignMode.cs#L6

Closing. If this is still an issue it needs to go back to the original MAUI issue or a new MAUI issue.