[NUI] Provide method so that user can register properties to group, then they can...
authorFang Xiaohui <xiaohui.fang@samsung.com>
Thu, 3 Jun 2021 10:45:10 +0000 (18:45 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 8 Jun 2021 05:35:32 +0000 (14:35 +0900)
src/Tizen.NUI/src/public/BaseComponents/View.cs
src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs

index 2287381..7e12bc6 100755 (executable)
@@ -28,6 +28,10 @@ namespace Tizen.NUI.BaseComponents
     /// <since_tizen> 3 </since_tizen>
     public partial class View : Container, IResourcesProvider
     {
+        private static HashSet<BindableProperty> positionPropertyGroup = new HashSet<BindableProperty>();
+        private static HashSet<BindableProperty> sizePropertyGroup = new HashSet<BindableProperty>();
+        private static HashSet<BindableProperty> scalePropertyGroup = new HashSet<BindableProperty>();
+
         internal BackgroundExtraData backgroundExtraData;
 
         private bool layoutSet = false;
@@ -53,7 +57,23 @@ namespace Tizen.NUI.BaseComponents
             public ViewSelectorData selectorData;
         }
 
-        static View() { }
+        static View()
+        {
+            RegisterPropertyGroup(PositionProperty, positionPropertyGroup);
+            RegisterPropertyGroup(Position2DProperty, positionPropertyGroup);
+            RegisterPropertyGroup(PositionXProperty, positionPropertyGroup);
+            RegisterPropertyGroup(PositionYProperty, positionPropertyGroup);
+
+            RegisterPropertyGroup(SizeProperty, sizePropertyGroup);
+            RegisterPropertyGroup(Size2DProperty, sizePropertyGroup);
+            RegisterPropertyGroup(SizeWidthProperty, sizePropertyGroup);
+            RegisterPropertyGroup(SizeHeightProperty, sizePropertyGroup);
+
+            RegisterPropertyGroup(ScaleProperty, scalePropertyGroup);
+            RegisterPropertyGroup(ScaleXProperty, scalePropertyGroup);
+            RegisterPropertyGroup(ScaleYProperty, scalePropertyGroup);
+            RegisterPropertyGroup(ScaleZProperty, scalePropertyGroup);
+        }
 
         /// <summary>
         /// Creates a new instance of a view.
index 4e662d1..84d0326 100755 (executable)
@@ -343,6 +343,17 @@ namespace Tizen.NUI.Binding
         }
 
         /// <summary>
+        /// Register the properties which can effect each other in Binding to same group.
+        /// </summary>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static void RegisterPropertyGroup(BindableProperty property, HashSet<BindableProperty> group)
+        {
+            if (!PropertyToGroup.ContainsKey(property))
+            {
+                PropertyToGroup.Add(property, group);
+            }
+        }
+        /// <summary>
         /// Apply the bindings to BindingContext.
         /// </summary>
         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
@@ -662,10 +673,14 @@ namespace Tizen.NUI.Binding
                 context.Attributes &= ~BindableContextAttributes.IsSetFromStyle;
             }
             else
+            {
                 context.Attributes &= ~BindableContextAttributes.IsManuallySet;
+            }
 
             if (fromStyle)
+            {
                 context.Attributes |= BindableContextAttributes.IsSetFromStyle;
+            }
             // else omitted on purpose
 
             bool currentlyApplying = applying;
@@ -878,6 +893,8 @@ namespace Tizen.NUI.Binding
                 }
             }
 
+            PropertyToGroup.TryGetValue(property, out HashSet<BindableProperty> propertyGroup);
+
             if (!silent)
             {
                 if ((!same || raiseOnEqual))
@@ -892,6 +909,27 @@ namespace Tizen.NUI.Binding
                     }
 
                     OnPropertyChanged(property.PropertyName);
+
+                    if (null != propertyGroup)
+                    {
+                        foreach (var relativeProperty in propertyGroup)
+                        {
+                            if (relativeProperty != property)
+                            {
+                                var relativeContext = GetOrCreateContext(relativeProperty);
+                                var relativeBinding = relativeContext.Binding;
+
+                                if (null != relativeBinding)
+                                {
+                                    applying = true;
+                                    relativeBinding.Apply(true);
+                                    applying = false;
+                                }
+
+                                OnPropertyChanged(relativeProperty.PropertyName);
+                            }
+                        }
+                    }
                 }
                 else if (true == same && true == forceSendChangeSignal)
                 {
@@ -903,12 +941,36 @@ namespace Tizen.NUI.Binding
                     }
 
                     OnPropertyChanged(property.PropertyName);
+
+                    if (null != propertyGroup)
+                    {
+                        foreach (var relativeProperty in propertyGroup)
+                        {
+                            if (relativeProperty != property)
+                            {
+                                var relativeContext = GetOrCreateContext(relativeProperty);
+                                var relativeBinding = relativeContext.Binding;
+
+                                if (null != relativeBinding)
+                                {
+                                    applying = true;
+                                    relativeBinding.Apply(true);
+                                    applying = false;
+                                }
+
+                                OnPropertyChanged(relativeProperty.PropertyName);
+                            }
+                        }
+                    }
                 }
 
                 OnPropertyChangedWithData(property);
             }
         }
 
+        private static Dictionary<BindableProperty, HashSet<BindableProperty>> PropertyToGroup { get; }
+            = new Dictionary<BindableProperty, HashSet<BindableProperty>>();
+
         [Flags]
         enum BindableContextAttributes
         {