maui icon indicating copy to clipboard operation
maui copied to clipboard

[MAUI 8] IsVisible false is not applied on child controls

Open omghb opened this issue 1 year ago • 12 comments

Description

If IsVisible="False" is set on a Grid then the child controls still return true for IsVisible.

On iOS this creates a bug as the keyboard "Next" button focus the invisible Entry an let the user type text into it.

Steps to Reproduce

  1. Create a new MAUI 8 app
  2. Open MainPage.xaml.cs and replace the content with:
namespace MauiApp1
{
    public partial class MainPage : ContentPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void HiddenEntry2Focused(object sender, FocusEventArgs e)
        {
            Console.WriteLine("Hidden entry: IsVisible: " + hiddenEntry2.IsVisible);
        }

        private void Entry3Focused(object sender, FocusEventArgs e)
        {
            Console.WriteLine("Hidden entry: IsVisible: " + hiddenEntry2.IsVisible);
        }
    }
}
  1. Open MainPage.xaml and replace the content with
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp1.MainPage">
    <ScrollView>
        <VerticalStackLayout Padding="30,0" Spacing="25">
            <Entry Placeholder="entry1" ReturnType="Next"/>

            <Grid IsVisible="False">
                <Entry x:Name="hiddenEntry2" Placeholder="hiddenEntry2" ReturnType="Next" Focused="HiddenEntry2Focused"/>
            </Grid>

            <Entry Placeholder="entry3" ReturnType="Next" Focused="Entry3Focused"/>
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>
  1. Run the App on iOS
  2. Tap into the first entry and tap on the next button.

Result: Keyboard is shown for the hidden entry.

Maui8IosVisibilityIssue

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

omghb avatar Nov 30 '23 15:11 omghb

I tried this and was not able to reproduce this. Archive.zip

mattleibow avatar Nov 30 '23 18:11 mattleibow

Ah, it happens on iOS when using the keyboard "next" button 😱 Seems to work with Tab on Android and Mac.

mattleibow avatar Nov 30 '23 18:11 mattleibow

@tj-devel709 thoughts?

mattleibow avatar Nov 30 '23 18:11 mattleibow

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

ghost avatar Nov 30 '23 18:11 ghost

@mattleibow The keyboard "next" button is working on Android as expected but the code line

Console.WriteLine("Hidden entry: IsVisible: " + hiddenEntry2.IsVisible);

returns true on Android as well. This should be false as the parent Grid has set IsVisible="False".

omghb avatar Dec 01 '23 07:12 omghb

@omghb no, it shouldn't be false. IsVisible on parent stops its rendering and rendering of children, but it doesn't change their properties.

cucumber-sp avatar Dec 02 '23 21:12 cucumber-sp

@omghb no, it shouldn't be false. IsVisible on parent stops its rendering and rendering of children, but it doesn't change their properties.

@cucumber-sp That's not what I would expect. How would I find out (via code) that a Element is not visible (not rendered)?

omghb avatar Dec 05 '23 09:12 omghb

@omghb not sure if there's a built-in solution for this, but I guess you can just go up untile parent is null, if some control has IsVisible set to false return false otherwise true. Make it and extension function and that's it

cucumber-sp avatar Dec 06 '23 14:12 cucumber-sp

Yeah this behavior for the next button seems incorrect, I will take a look at this, thanks!

tj-devel709 avatar Dec 12 '23 21:12 tj-devel709

@omghb not sure if there's a built-in solution for this, but I guess you can just go up untile parent is null, if some control has IsVisible set to false return false otherwise true. Make it and extension function and that's it

@omghb I'm curious what the Visibility property would return.

For ex: var visibility = ( (IView) Content ).Visibility

https://learn.microsoft.com/en-us/dotnet/api/microsoft.maui.iview.visibility?view=net-maui-8.0#microsoft-maui-iview-visibility

bradencohen avatar Dec 21 '23 18:12 bradencohen

@bradencohen The Visibility property returns the same value as IsVisible. The element is hidden and should be Collapsed.

image

omghb avatar Dec 22 '23 12:12 omghb

@jsuarezruiz @mattleibow @omghb @omghb PR: https://github.com/dotnet/maui/pull/20154

kubaflo avatar Jan 25 '24 12:01 kubaflo

I just tested WPF and WinUI 3 and they do not propagate the value. We don't have to follow the WPF way, but will the difference be confusing?

Anyone have any thoughts?

mattleibow avatar Feb 05 '24 16:02 mattleibow

I am asking a question here because before we break symmetry I think we should know any decisions that were made: https://github.com/dotnet/wpf/discussions/8774

mattleibow avatar Feb 05 '24 16:02 mattleibow

Note that WPF has Visibility and IsVisible which are fundamentally different. The former represents the intent for that particular element, the latter is read-only, calculated visibility, which I guess is "propagated" in the sense you are thinking of (i.e. you cannot have IsVisible element until all parents are visible). Does that help?

Seems that this is actually a thing, so I am thinking maybe we should do this now?

mattleibow avatar Feb 05 '24 17:02 mattleibow

Thanks for the improvement in MAUI 8.0.10:

  • #20160

Unfortunately, this fixes the issue only partly. Still not working:

  • Hide an element that has the focus
    • Expected: next focusable element gets the focus
    • Actual: focus stays on the hidden element
  • IsVisible property is not propagated to child controls

omghb avatar Mar 15 '24 07:03 omghb