2016-03-22 23:02:25 +03:00
|
|
|
using System.ComponentModel;
|
|
|
|
using Android.Views;
|
|
|
|
|
|
|
|
namespace Xamarin.Forms.Platform.Android
|
|
|
|
{
|
|
|
|
public class BoxRenderer : VisualElementRenderer<BoxView>
|
|
|
|
{
|
2016-04-08 19:16:02 +03:00
|
|
|
bool _isInViewCell;
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
public BoxRenderer()
|
|
|
|
{
|
|
|
|
AutoPackage = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnTouchEvent(MotionEvent e)
|
|
|
|
{
|
2016-04-08 19:16:02 +03:00
|
|
|
if (base.OnTouchEvent(e))
|
|
|
|
return true;
|
|
|
|
return !Element.InputTransparent && !_isInViewCell;
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
|
|
|
|
{
|
|
|
|
base.OnElementChanged(e);
|
2016-04-08 19:16:02 +03:00
|
|
|
|
|
|
|
if (e.NewElement != null)
|
|
|
|
{
|
|
|
|
var parent = e.NewElement.Parent;
|
|
|
|
while (parent != null)
|
|
|
|
{
|
|
|
|
if (parent is ViewCell)
|
|
|
|
{
|
|
|
|
_isInViewCell = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parent = parent.Parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-22 23:02:25 +03:00
|
|
|
UpdateBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnElementPropertyChanged(sender, e);
|
|
|
|
|
|
|
|
if (e.PropertyName == BoxView.ColorProperty.PropertyName || e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
|
|
|
|
UpdateBackgroundColor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateBackgroundColor()
|
|
|
|
{
|
|
|
|
Color colorToSet = Element.Color;
|
|
|
|
|
|
|
|
if (colorToSet == Color.Default)
|
|
|
|
colorToSet = Element.BackgroundColor;
|
|
|
|
|
|
|
|
SetBackgroundColor(colorToSet.ToAndroid(Color.Transparent));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|