summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKangho Hur <kangho.hur@samsung.com>2017-02-28 00:36:00 (GMT)
committerKangho Hur <kangho.hur@samsung.com>2017-02-28 04:23:15 (GMT)
commitbe2d2915c3ac6884b0133c4039213530daedbbc5 (patch)
tree56eff62f8d595564d80d811ad20786da3fbddb32
parentb42f8a2ce06084b0cde93b7761cccbf34ace9877 (diff)
downloadxamarin-forms-be2d2915c3ac6884b0133c4039213530daedbbc5.zip
xamarin-forms-be2d2915c3ac6884b0133c4039213530daedbbc5.tar.gz
xamarin-forms-be2d2915c3ac6884b0133c4039213530daedbbc5.tar.bz2
Renew the VisualElement.Opacityrefs/changes/06/116706/2
- OpacityLayer is no more needed in renderer. - There is a limitation on this chagne - Entry and Label are not support Opacity property anymore. It will be fixed soon when Elm# is support. Change-Id: I52f0fc67fdfda65cf8141cceab877890d260a4e6
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/BoxViewRenderer.cs51
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs74
-rw-r--r--Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json6
3 files changed, 47 insertions, 84 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/BoxViewRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/BoxViewRenderer.cs
index 7a9f756..b065134 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/BoxViewRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/BoxViewRenderer.cs
@@ -4,11 +4,8 @@ using ERectangle = ElmSharp.Rectangle;
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()
@@ -23,10 +20,6 @@ namespace Xamarin.Forms.Platform.Tizen
SetNativeControl(_control);
}
- if (e.OldElement != null)
- {
- }
-
if (e.NewElement != null)
{
UpdateColor();
@@ -35,27 +28,45 @@ namespace Xamarin.Forms.Platform.Tizen
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);
}
}
}
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
index 37a5faf..394ec02 100644
--- a/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/VisualElementRenderer.cs
@@ -44,8 +44,6 @@ namespace Xamarin.Forms.Platform.Tizen
HashSet<string> _batchedProperties = new HashSet<string>();
- ERectangle _opacityLayer;
-
internal GestureHandler _gestureHandler;
/// <summary>
@@ -209,7 +207,6 @@ namespace Xamarin.Forms.Platform.Tizen
var y = ComputeAbsoluteY(Element);
NativeView.Geometry = new Rectangle(x, y, Element.Width, Element.Height).ToPixel();
ApplyTransformation();
- UpdateOpacityLayer();
}
void IVisualElementRenderer.SetElement(VisualElement element)
@@ -309,7 +306,6 @@ namespace Xamarin.Forms.Platform.Tizen
if (NativeView != null)
{
NativeView.Deleted -= NativeViewDeleted;
- EnsureOpacityLayerIsDestroyed();
NativeView.Unrealize();
SetNativeView(null);
}
@@ -425,7 +421,6 @@ namespace Xamarin.Forms.Platform.Tizen
{
NativeView.Moved -= OnMoved;
NativeView.Deleted -= NativeViewDeleted;
- EnsureOpacityLayerIsDestroyed();
}
Widget widget = NativeView as Widget;
@@ -584,6 +579,18 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
+ 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);
@@ -719,7 +726,6 @@ namespace Xamarin.Forms.Platform.Tizen
void OnMoved(object sender, EventArgs e)
{
- UpdateOpacityLayer();
ApplyTransformation();
_gestureHandler?.UpdateHitBox();
}
@@ -752,30 +758,12 @@ namespace Xamarin.Forms.Platform.Tizen
}
}
- 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;
@@ -874,48 +862,12 @@ namespace Xamarin.Forms.Platform.Tizen
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
diff --git a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json
index 8f6afe7..b77e8cb 100644
--- a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json
+++ b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json
@@ -1,6 +1,6 @@
-{
+{
"dependencies": {
- "ElmSharp": "1.1.0-beta-010",
+ "ElmSharp": "1.1.0-beta-011",
"NETStandard.Library": "1.6.0",
"System.Runtime.Serialization.Xml": "4.1.1",
"Tizen.Applications": "1.1.0",
@@ -11,4 +11,4 @@
"imports": "portable-net45+win8+wpa81+wp8"
}
}
-}
+} \ No newline at end of file