namespace Xamarin.Forms.Platform.Tizen
{
- public class BoxViewRenderer :
- VisualElementRenderer<BoxView>
+ public class BoxViewRenderer : VisualElementRenderer<BoxView>
{
- static readonly EColor s_defaultColor = EColor.Transparent;
-
ERectangle _control;
public BoxViewRenderer()
SetNativeControl(_control);
}
- if (e.OldElement != null)
- {
- }
-
if (e.NewElement != null)
{
UpdateColor();
base.OnElementChanged(e);
}
- void UpdateColor()
+ protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
- Color colorToSet = Element.Color;
-
- if (colorToSet == Color.Default)
+ if (e.PropertyName == BoxView.ColorProperty.PropertyName)
{
- colorToSet = Element.BackgroundColor;
+ UpdateColor();
}
+ base.OnElementPropertyChanged(sender, e);
+ }
- _control.Color = (colorToSet == Color.Default) ? s_defaultColor : colorToSet.ToNative();
+ protected override void UpdateBackgroundColor()
+ {
+ UpdateColor();
}
- protected override void OnElementPropertyChanged(object sender,
- PropertyChangedEventArgs e)
+ protected override void UpdateOpacity()
+ {
+ UpdateColor();
+ }
+
+ void UpdateColor()
{
- if (e.PropertyName == BoxView.ColorProperty.PropertyName ||
- e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
+ if (Element.Color.IsDefault)
{
- UpdateColor();
+ if (Element.BackgroundColor.IsDefault)
+ {
+ // Set to default color. (Transparent)
+ _control.Color = EColor.Transparent;
+ }
+ else
+ {
+ // Use BackgroundColor only if color is default and background color is not default.
+ _control.Color = Element.BackgroundColor.MultiplyAlpha(Element.Opacity).ToNative();
+ }
+ }
+ else
+ {
+ // Color has higer priority than BackgroundColor.
+ _control.Color = Element.Color.MultiplyAlpha(Element.Opacity).ToNative();
}
- base.OnElementPropertyChanged(sender, e);
}
}
}
HashSet<string> _batchedProperties = new HashSet<string>();
- ERectangle _opacityLayer;
-
internal GestureHandler _gestureHandler;
/// <summary>
var y = ComputeAbsoluteY(Element);
NativeView.Geometry = new Rectangle(x, y, Element.Width, Element.Height).ToPixel();
ApplyTransformation();
- UpdateOpacityLayer();
}
void IVisualElementRenderer.SetElement(VisualElement element)
if (NativeView != null)
{
NativeView.Deleted -= NativeViewDeleted;
- EnsureOpacityLayerIsDestroyed();
NativeView.Unrealize();
SetNativeView(null);
}
{
NativeView.Moved -= OnMoved;
NativeView.Deleted -= NativeViewDeleted;
- EnsureOpacityLayerIsDestroyed();
}
Widget widget = NativeView as Widget;
}
}
+ protected virtual void UpdateOpacity()
+ {
+ if (NativeView is Widget)
+ {
+ (NativeView as Widget).Opacity = (int)(Element.Opacity * 255.0);
+ }
+ else
+ {
+ Log.Warn("{0} uses {1} which does not support opacity", this, NativeView);
+ }
+ }
+
static double ComputeAbsoluteX(VisualElement e)
{
return e.X + (e.RealParent is VisualElement ? Forms.ConvertToScaledDP(Platform.GetRenderer(e.RealParent).NativeView.Geometry.X) : 0.0);
void OnMoved(object sender, EventArgs e)
{
- UpdateOpacityLayer();
ApplyTransformation();
_gestureHandler?.UpdateHitBox();
}
}
}
- void UpdateOpacity()
- {
- if (null != NativeView)
- {
- if (Element.Opacity < 1.0)
- {
- EnsureOpacityLayerExists();
-
- var alpha = (int)(Element.Opacity * 255.0);
- _opacityLayer.Color = new EColor(255, 255, 255, alpha);
- }
- else
- {
- EnsureOpacityLayerIsDestroyed();
- }
- }
- }
-
/// <summary>
/// Updates the IsEnabled property.
/// </summary>
void UpdateIsEnabled()
{
- Widget widget = NativeView as Widget;
+ var widget = NativeView as Widget;
if (widget != null)
{
widget.IsEnabled = Element.IsEnabled;
ApplyTranslation(map, geometry, ref changed);
NativeView.IsMapEnabled = changed;
-
if (changed)
{
NativeView.EvasMap = map;
-
- if (_opacityLayer != null)
- {
- _opacityLayer.IsMapEnabled = true;
- _opacityLayer.EvasMap = map;
- }
}
_gestureHandler?.UpdateHitBox();
}
-
- protected virtual void UpdateOpacityLayer()
- {
- if (_opacityLayer != null)
- {
- _opacityLayer.Geometry = NativeView.Geometry;
- NativeView.SetClip(_opacityLayer);
- }
- }
-
- void EnsureOpacityLayerExists()
- {
- if (_opacityLayer == null)
- {
- _opacityLayer = new ERectangle(NativeView);
- UpdateOpacityLayer();
- _opacityLayer.Show();
- }
- }
-
- void EnsureOpacityLayerIsDestroyed()
- {
- if (_opacityLayer != null)
- {
- NativeView.SetClip(null);
- _opacityLayer.Unrealize();
- _opacityLayer = null;
- }
- }
}
internal static class Settings