Skip to content

Triggering a change with the ContainerView results in incorrect things #12116

@mattleibow

Description

@mattleibow

Description

Some aspects of the view, such as Gestures on Android (and maybe iOS if this is merged: #12108), are attached to the container view. As a result, when the container view is removed the whole gesture set is missing.

Steps to Reproduce

  1. File | New | Maui app (I lie, I used the sandbox app)
  2. Paste this code:
    var stack = new VerticalStackLayout();
    
    var view1 = new Label
    {
    	Text = "Started with NO container",
    	// no shadow
    	GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => Debug.WriteLine("view 1")) } }
    };
    stack.Add(view1);
    
    var view2 = new Label
    {
    	Text = "Started WITH a container",
    	Shadow = new Shadow(),
    	GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => Debug.WriteLine("view 2")) } }
    };
    stack.Add(view2);
    
    var view3 = new Image
    {
    	Source = ImageSource.FromFile("dotnet_bot.png"),
    	WidthRequest = 80,
    	HeightRequest = 80,
    	// no background
    	GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => Debug.WriteLine("view 3")) } }
    };
    stack.Add(view3);
    
    var view4 = new Image
    {
    	Source = ImageSource.FromFile("dotnet_bot.png"),
    	WidthRequest = 80,
    	HeightRequest = 80,
    	Background = new SolidColorBrush(Colors.Red),
    	GestureRecognizers = { new TapGestureRecognizer { Command = new Command(() => Debug.WriteLine("view 4")) } }
    };
    stack.Add(view4);
    
    var btn = new Button
    {
    	BackgroundColor = Colors.Orange,
    	Text = "OK",
    	Command = new Command(() =>
    	{
    		view1.Shadow = new Shadow(); // causes a container view to be added
    		view2.Shadow = null; // causes the container view to be removed
    		view3.Background = new SolidColorBrush(Colors.Red); // causes a container view to be added
    		view4.Background = null; // causes the container view to be removed
    	})
    };
    stack.Add(btn);
    
    Content = stack;
  3. Tap the labels and observe both log to the console
  4. Tap the button
  5. Observe that only the first label logs

NOTE: there is a bug on iOS where setting the background to null does not actually remove the background... (#12117) so for now replace with Shadow and you get the same issue.

This is because in the first case, a container was added and the gestures are still attached to the label. In the second case, the gestures were attached to the container that is now removed from the view hierarchy.

Even if this was perfect, I am not sure how this plays with controls that respond to taps - for example buttons. Will attaching gestures stop normal button things? If so, will it change when it is on the container? Is this a valid case of a button and a tap gesture on that button? Should adding a gesture trigger a new container?

In a perfect world, we have 2 behaviours - with and without containers!

Link to public reproduction project repository

:)

Version with bug

7.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, Windows, macOS, Other (Tizen, Linux, etc. not supported by Microsoft directly)

Affected platform versions

All

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions