--- /dev/null
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+
+#if UITEST
+using Xamarin.Forms.Core.UITests;
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+
+namespace Xamarin.Forms.Controls.Issues
+{
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Github, 5518, "Frame Tap Gesture not working when using Visual=\"Material\" in iOS", PlatformAffected.iOS)]
+ public class Issue5518 : TestContentPage
+ {
+
+ protected override void Init()
+ {
+ var stack = new StackLayout();
+
+
+ var frame = new Frame()
+ {
+ Visual = VisualMarker.Material,
+ BackgroundColor = Color.White,
+ AutomationId = "NoContentFrame"
+ };
+
+ var outputLabel1 = new Label() { Text = "", AutomationId = "Output1", HorizontalOptions = LayoutOptions.Center };
+
+ var tapGestureRecognizer = new TapGestureRecognizer();
+ tapGestureRecognizer.Tapped += (s, e) =>
+ {
+ outputLabel1.Text = "Success";
+ };
+
+ frame.GestureRecognizers.Add(tapGestureRecognizer);
+ stack.Children.Add(frame);
+ stack.Children.Add(outputLabel1);
+
+ var frameWithContent = new Frame()
+ {
+ Visual = VisualMarker.Material,
+ Content = new Label() { Text = "I'm label" },
+ AutomationId = "ContentedFrame"
+ };
+
+ var outputLabel2 = new Label() { Text = "", AutomationId = "Output2", HorizontalOptions = LayoutOptions.Center };
+
+ tapGestureRecognizer = new TapGestureRecognizer();
+ tapGestureRecognizer.Tapped += (s, e) =>
+ {
+ outputLabel2.Text = "Success";
+ };
+
+ frameWithContent.GestureRecognizers.Add(tapGestureRecognizer);
+
+ stack.Children.Add(new Label() { Text = "Clicking each frame should cause `Success` text to appear." });
+ stack.Children.Add(frameWithContent);
+ stack.Children.Add(outputLabel2);
+
+ Content = stack;
+ }
+
+ void TapGestureRecognizer_Tapped(object sender, EventArgs e)
+ {
+ DisplayAlert("Frame Tap Gesture", "Work", "Ok");
+ }
+
+#if UITEST
+ [Test]
+ public void FrameTapGestureRecognizer()
+ {
+ RunningApp.WaitForElement("NoContentFrame");
+ RunningApp.Tap("NoContentFrame");
+ Assert.AreEqual("Success", RunningApp.WaitForElement("Output1")[0].ReadText());
+
+ RunningApp.WaitForElement("ContentedFrame");
+ RunningApp.Tap("I'm label");
+ Assert.AreEqual("Success", RunningApp.WaitForElement("Output2")[0].ReadText());
+ }
+#endif
+ }
+}
using System;
using System.ComponentModel;
+using System.Linq;
using CoreAnimation;
using CoreGraphics;
using MaterialComponents;
float _defaultCornerRadius = -1;
VisualElementPackager _packager;
VisualElementTracker _tracker;
+ EventTracker _events;
+
bool _disposed = false;
public event EventHandler<VisualElementChangedEventArgs> ElementChanged;
public Frame Element { get; private set; }
-
+
public override void WillRemoveSubview(UIView uiview)
{
var content = Element?.Content;
_packager.Load();
_tracker = new VisualElementTracker(this);
+
+ _events = new EventTracker(this);
+ _events.LoadEvents(this);
}
Element.PropertyChanged += OnElementPropertyChanged;
}
OnElementChanged(new VisualElementChangedEventArgs(oldElement, element));
+
+ if (element != null)
+ element.SendViewInitialized(this);
+
+ if (!string.IsNullOrEmpty(element?.AutomationId))
+ AccessibilityIdentifier = element.AutomationId;
}
protected override void Dispose(bool disposing)
_tracker.Dispose();
_tracker = null;
+ _events.Dispose();
+ _events = null;
+
if (Element != null)
{
Element.ClearValue(Platform.iOS.Platform.RendererProperty);
if (!Element.HasShadow)
SetShadowElevation(0, UIControlState.Normal);
- // this is set in the theme, so we must always disable it
- Interactable = false;
+ if (Element.GestureRecognizers != null && Element.GestureRecognizers.Any())
+ {
+ Interactable = true;
+
+ // disable ink (ripple) and elevation effect while tapped
+ InkView.Hidden = true;
+ if (Element.HasShadow)
+ SetShadowElevation(1f, UIControlState.Highlighted);
+ }
+ else
+ {
+ // this is set in the theme, so we must always disable it
+ Interactable = false;
+ }
+
}
protected virtual void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
void IVisualElementRenderer.SetElementSize(Size size) =>
Layout.LayoutChildIntoBoundingRegion(Element, new Rectangle(Element.X, Element.Y, size.Width, size.Height));
}
-}
\ No newline at end of file
+}