When both relative layout width and height constraint is set, child layout is not getting focused.
Description
When I add both relative layout width and height constraints to the stack layout, the Child layouts are not getting focused. It works if I use either height or width constraints but not both.
Steps to Reproduce
- Add relative layout height and width constraints in the stack layout
- Add Entry view and Button inside the stack layout.
- Focus on the Entry view, it should pop up the keyboard on focus.
- Keyboard is not popping up.
Snippet:
<?xml version="1.0" encoding="utf-8" ?>
<rel:RelativeLayout
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:rel="clr-namespace:Microsoft.Maui.Controls.Compatibility;assembly=Microsoft.Maui.Controls"
x:Class="Example.DemoClass"
Padding="10" >
<StackLayout Padding="15" HorizontalOptions="Fill" VerticalOptions="Center" rel:RelativeLayout.HeightConstraint="{ rel:ConstraintExpression
Type=RelativeToParent,
Property=Height,
Factor=1,
Constant=-40}" rel:RelativeLayout.WidthConstraint="{ rel:ConstraintExpression
Type=RelativeToParent,
Property=Width,
Factor=1}">
<Label Text="{Binding WelcomeMessage}" HorizontalOptions="Center" VerticalOptions="Center" Style="{DynamicResource TitleStyle}" Padding="0,0,0,10"/>
<Label Text="{Binding Hint}" HorizontalOptions="Center" Padding="0,0,0,20"/>
<Entry Text="{Binding UserId}" Placeholder="{Binding Placeholder}" VerticalOptions="Center" ReturnType="Done" Keyboard="Email"/>
<Button Text="{Binding ActionButtonTitle}" Command="{Binding RegisterCommand}"/>
</StackLayout>
</rel:RelativeLayout>
Link to public reproduction project repository
NA
Version with bug
6.0.312
Last version that worked well
6.0.312
Affected platforms
Android
Affected platform versions
Android 11
Did you find any workaround?
No response
Relevant log output
No response
Hi @SahanaSShetty. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
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.
Hi @SahanaSShetty. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
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.
I have tried with the latest VS (Version 17.6.0 Preview 1.0), but the issue still exists. Please find the repository: https://github.com/SahanaSShetty/MauiExample
I'm getting the below error if I use the relative layout.
0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception C#
0x1A in Android.Runtime.JNINativeWrapper._unhandled_exception at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:12,5 C#
0x1D in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:23,26 C#
0x17 in System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw C#
0x6 in System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0 C#
0xC in Android.App.SyncContext. at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:36,19 C#
0xE in Java.Lang.Thread.RunnableImplementor.Run at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36,6 C#
0x8 in Java.Lang.IRunnableInvoker.n_Run at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net7.0/android-33/mcw/Java.Lang.IRunnable.cs:84,4 C#
0x8 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:22,5 C#
@shanselman Can you try to build you Design using this : https://github.com/xtuzy/SharpConstraintLayout or Absolute layout may be since Relative is deprecated
Hi @SahanaSShetty. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
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.
@SahanaSShetty That exception is because UseMauiCompability needs to be called on the App Builder, to enable Compatibility library features like RelativeLayout. That exception should actually be a different exception, with a clear exception message that indicates the exact cause and how to fix it, but apparently the user friendly exception gets turned into the non-user friendly exception in this scenario. That's a problem on the MAUI side, and it took me a little while to track this down, but it's a separate problem than this bug and we'll look to fix it separately.
As for this bug, after I added the UseMauiCompatibility call as shown below, I wasn't able to reproduce the bug - I was able to set the focus to the edit control on Android, with the keyboard popping up. Are you able to reproduce, after adding UseMauiCompability?
This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.