[NUI][Xaml] Sync patch https://github.com/Samsung/TizenFX/pull/4056 from API9
authorFang Xiaohui <xiaohui.fang@samsung.com>
Wed, 27 Apr 2022 00:59:48 +0000 (08:59 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 27 Apr 2022 05:57:47 +0000 (14:57 +0900)
src/Tizen.NUI/src/internal/XamlBinding/BindingExpression.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextEditorBindableProperty.cs
src/Tizen.NUI/src/public/BaseComponents/TextField.cs
src/Tizen.NUI/src/public/BaseComponents/TextFieldBindableProperty.cs
src/Tizen.NUI/src/public/Layouting/LayoutGroup.cs
src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs
src/Tizen.NUI/src/public/XamlBinding/TypedBinding.cs

index 7eb889a..a239617 100755 (executable)
@@ -186,7 +186,7 @@ namespace Tizen.NUI.Binding
                     return;
                 }
 
-                target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, false);
+                target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted);
             }
             else if (needsSetter && part.LastSetter != null && current != null)
             {
index 0e32c3f..073920e 100755 (executable)
@@ -38,6 +38,7 @@ namespace Tizen.NUI.BaseComponents
         private InputMethodContext inputMethodContext = null;
         private float fontSizeScale = 1.0f;
         private bool hasFontSizeChangedCallback = false;
+        private bool isSettingTextInCSharp = false;
 
         static TextEditor() { }
 
@@ -78,6 +79,8 @@ namespace Tizen.NUI.BaseComponents
             {
                 SetVisible(false);
             }
+
+            TextChanged += TextEditorTextChanged;
         }
 
         internal TextEditor(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true, TextEditorStyle style = null) : base(cPtr, cMemoryOwn, style)
@@ -86,7 +89,8 @@ namespace Tizen.NUI.BaseComponents
             {
                 SetVisible(false);
             }
-            Focusable = true;
+
+            TextChanged += TextEditorTextChanged;
         }
 
         /// <summary>
@@ -177,7 +181,7 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                SetValueAndForceSendChangeSignal(TextProperty, value);
+                SetValue(TextProperty, value);
                 NotifyPropertyChanged();
             }
         }
@@ -2129,28 +2133,6 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        /// Only used by the IL of xaml, will never changed to not hidden.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override bool IsCreateByXaml
-        {
-            get
-            {
-                return base.IsCreateByXaml;
-            }
-            set
-            {
-                base.IsCreateByXaml = value;
-
-                if (value == true)
-                {
-                    this.TextChanged += (obj, e) =>
-                    {
-                        this.Text = e.TextEditor.Text;
-                    };
-                }
-            }
-        }
-
         /// <summary>
         /// The FontSizeScale property. <br />
         /// The default value is 1.0. <br />
@@ -2457,6 +2439,7 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
 
+            TextChanged -= TextEditorTextChanged;
             base.Dispose(type);
         }
 
@@ -2554,6 +2537,14 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private void TextEditorTextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (!isSettingTextInCSharp)
+            {
+                EnforceNotifyBindedInstance(TextProperty);
+            }
+        }
+
         internal new class Property
         {
             internal static readonly int TEXT = Interop.TextEditor.TextGet();
index 3102b43..6964033 100755 (executable)
@@ -33,7 +33,9 @@ namespace Tizen.NUI.BaseComponents
             var textEditor = (TextEditor)bindable;
             if (newValue != null)
             {
+                textEditor.isSettingTextInCSharp = true;
                 Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textEditor.SwigCPtr, TextEditor.Property.TEXT, new Tizen.NUI.PropertyValue((string)newValue));
+                textEditor.isSettingTextInCSharp = false;
             }
         }),
         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
index e9469a3..71072b7 100755 (executable)
@@ -38,6 +38,7 @@ namespace Tizen.NUI.BaseComponents
         private InputMethodContext inputMethodCotext = null;
         private float fontSizeScale = 1.0f;
         private bool hasFontSizeChangedCallback = false;
+        private bool isSettingTextInCSharp = false;
 
         static TextField() { }
 
@@ -77,7 +78,8 @@ namespace Tizen.NUI.BaseComponents
             {
                 SetVisible(false);
             }
-            Focusable = true;
+
+            TextChanged += TextFieldTextChanged;
         }
 
         internal TextField(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
@@ -86,7 +88,8 @@ namespace Tizen.NUI.BaseComponents
             {
                 SetVisible(false);
             }
-            Focusable = true;
+
+            TextChanged += TextFieldTextChanged;
         }
 
         internal TextField(TextField handle, bool shown = true) : this(Interop.TextField.NewTextField(TextField.getCPtr(handle)), true)
@@ -97,6 +100,8 @@ namespace Tizen.NUI.BaseComponents
             {
                 SetVisible(false);
             }
+
+            TextChanged += TextFieldTextChanged;
         }
 
         internal enum ExceedPolicyType
@@ -230,7 +235,7 @@ namespace Tizen.NUI.BaseComponents
             }
             set
             {
-                SetValueAndForceSendChangeSignal(TextProperty, value);
+                SetValue(TextProperty, value);
                 NotifyPropertyChanged();
             }
         }
@@ -2312,28 +2317,6 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        /// Only used by the IL of xaml, will never changed to not hidden.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override bool IsCreateByXaml
-        {
-            get
-            {
-                return base.IsCreateByXaml;
-            }
-            set
-            {
-                base.IsCreateByXaml = value;
-
-                if (value == true)
-                {
-                    this.TextChanged += (obj, e) =>
-                    {
-                        this.Text = e.TextField.Text;
-                    };
-                }
-            }
-        }
-
         /// <summary>
         /// Get the InputMethodContext instance.
         /// </summary>
@@ -2461,6 +2444,8 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
 
+            TextChanged -= TextFieldTextChanged;
+
             base.Dispose(type);
         }
 
@@ -2562,6 +2547,14 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
+        private void TextFieldTextChanged(object sender, TextChangedEventArgs e)
+        {
+            if (!isSettingTextInCSharp)
+            {
+                EnforceNotifyBindedInstance(TextProperty);
+            }
+        }
+
         internal new class Property
         {
             internal static readonly int TEXT = Interop.TextField.TextGet();
index ff3b7be..bc8ecb6 100755 (executable)
@@ -84,7 +84,9 @@ namespace Tizen.NUI.BaseComponents
             var textField = (TextField)bindable;
             if (newValue != null)
             {
+                textField.isSettingTextInCSharp = true;
                 Tizen.NUI.Object.SetProperty((System.Runtime.InteropServices.HandleRef)textField.SwigCPtr, TextField.Property.TEXT, new Tizen.NUI.PropertyValue((string)newValue));
+                textField.isSettingTextInCSharp = false;
             }
         }),
         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
index 5c972ce..e0a3ac5 100755 (executable)
@@ -678,7 +678,7 @@ namespace Tizen.NUI
             if (bindable == null)
                 throw new ArgumentNullException(nameof(bindable));
 
-            bindable.SetValueCore(property, value, SetValueFlags.None, SetValuePrivateFlags.ManuallySet, false);
+            bindable.SetValueCore(property, value, SetValueFlags.None, SetValuePrivateFlags.ManuallySet);
         }
         internal static void OnChildPropertyChanged(Binding.BindableObject bindable, object oldValue, object newValue)
         {
index bc28a62..8ca03f8 100755 (executable)
@@ -243,18 +243,56 @@ namespace Tizen.NUI.Binding
             SetBinding(targetProperty, binding, false);
         }
 
-        private bool isCreateByXaml = false;
-        /// Only used by the IL of xaml, will never changed to not hidden.
+        /// Internal used, will never changed to not hidden.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public virtual bool IsCreateByXaml
+        public bool IsCreateByXaml
         {
-            get
-            {
-                return isCreateByXaml;
-            }
-            set
+            get;
+            set;
+        }
+
+        /// This will be public opened in next ACR.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void EnforceNotifyBindedInstance(BindableProperty property)
+        {
+            if (null != property)
             {
-                isCreateByXaml = value;
+                BindablePropertyContext context = GetOrCreateContext(property);
+                BindingBase binding = context.Binding;
+
+                var currentlyApplying = applying;
+
+                if (binding != null && !currentlyApplying)
+                {
+                    applying = true;
+                    binding.Apply(true);
+                    applying = false;
+                }
+
+                OnPropertyChanged(property.PropertyName);
+
+                PropertyToGroup.TryGetValue(property, out HashSet<BindableProperty> propertyGroup);
+
+                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);
+                        }
+                    }
+                }
             }
         }
 
@@ -337,25 +375,6 @@ namespace Tizen.NUI.Binding
             }
         }
 
-        internal void SetValueAndForceSendChangeSignal(BindableProperty property, object value)
-        {
-            if (property == null)
-                throw new ArgumentNullException(nameof(property));
-
-            if (true == IsBinded)
-            {
-                if (property.IsReadOnly)
-                    throw new InvalidOperationException(string.Format("The BindableProperty \"{0}\" is readonly.", property.PropertyName));
-
-                SetValueCore(property, value, SetValueFlags.ClearOneWayBindings | SetValueFlags.ClearDynamicResource,
-                    SetValuePrivateFlags.ManuallySet | SetValuePrivateFlags.CheckAccess, true);
-            }
-            else
-            {
-                property.PropertyChanged?.Invoke(this, null, value);
-            }
-        }
-
         /// <summary>
         /// Sets the value of the propertyKey.
         /// </summary>
@@ -691,7 +710,7 @@ namespace Tizen.NUI.Binding
 
         internal void SetValueCore(BindablePropertyKey propertyKey, object value, SetValueFlags attributes = SetValueFlags.None)
         {
-            SetValueCore(propertyKey.BindableProperty, value, attributes, SetValuePrivateFlags.None, false);
+            SetValueCore(propertyKey.BindableProperty, value, attributes, SetValuePrivateFlags.None);
         }
 
         /// <summary>
@@ -703,10 +722,10 @@ namespace Tizen.NUI.Binding
         [EditorBrowsable(EditorBrowsableState.Never)]
         internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes = SetValueFlags.None)
         {
-            SetValueCore(property, value, attributes, SetValuePrivateFlags.Default, false);
+            SetValueCore(property, value, attributes, SetValuePrivateFlags.Default);
         }
 
-        internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes, bool forceSendChangeSignal)
+        internal void SetValueCore(BindableProperty property, object value, SetValueFlags attributes, SetValuePrivateFlags privateAttributes)
         {
             bool checkAccess = (privateAttributes & SetValuePrivateFlags.CheckAccess) != 0;
             bool manuallySet = (privateAttributes & SetValuePrivateFlags.ManuallySet) != 0;
@@ -764,7 +783,7 @@ namespace Tizen.NUI.Binding
             else
             {
                 context.Attributes |= BindableContextAttributes.IsBeingSet;
-                SetValueActual(property, context, value, currentlyApplying, forceSendChangeSignal, attributes, silent);
+                SetValueActual(property, context, value, currentlyApplying, attributes, silent);
 
                 Queue<SetValueArgs> delayQueue = context.DelayedSetters;
                 if (delayQueue != null)
@@ -772,7 +791,7 @@ namespace Tizen.NUI.Binding
                     while (delayQueue.Count > 0)
                     {
                         SetValueArgs s = delayQueue.Dequeue();
-                        SetValueActual(s.Property, s.Context, s.Value, s.CurrentlyApplying, forceSendChangeSignal, s.Attributes);
+                        SetValueActual(s.Property, s.Context, s.Value, s.CurrentlyApplying, s.Attributes);
                     }
 
                     context.DelayedSetters = null;
@@ -930,11 +949,10 @@ namespace Tizen.NUI.Binding
                 return;
 
             SetValueCore(property, value, SetValueFlags.ClearOneWayBindings | SetValueFlags.ClearDynamicResource,
-                (fromStyle ? SetValuePrivateFlags.FromStyle : SetValuePrivateFlags.ManuallySet) | (checkAccess ? SetValuePrivateFlags.CheckAccess : 0),
-                false);
+                (fromStyle ? SetValuePrivateFlags.FromStyle : SetValuePrivateFlags.ManuallySet) | (checkAccess ? SetValuePrivateFlags.CheckAccess : 0));
         }
 
-        void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, bool forceSendChangeSignal, SetValueFlags attributes, bool silent = false)
+        void SetValueActual(BindableProperty property, BindablePropertyContext context, object value, bool currentlyApplying, SetValueFlags attributes, bool silent = false)
         {
             object original = context.Value;
             bool raiseOnEqual = (attributes & SetValueFlags.RaiseOnEqual) != 0;
@@ -973,71 +991,36 @@ namespace Tizen.NUI.Binding
 
             PropertyToGroup.TryGetValue(property, out HashSet<BindableProperty> propertyGroup);
 
-            if (!silent)
+            if (!silent && (!same || raiseOnEqual))
             {
-                if ((!same || raiseOnEqual))
-                {
-                    property.PropertyChanged?.Invoke(this, original, value);
-
-                    if (binding != null && !currentlyApplying)
-                    {
-                        applying = true;
-                        binding.Apply(true);
-                        applying = false;
-                    }
-
-                    OnPropertyChanged(property.PropertyName);
-
-                    if (null != propertyGroup)
-                    {
-                        foreach (var relativeProperty in propertyGroup)
-                        {
-                            if (relativeProperty != property)
-                            {
-                                var relativeContext = GetOrCreateContext(relativeProperty);
-                                var relativeBinding = relativeContext.Binding;
+                property.PropertyChanged?.Invoke(this, original, value);
 
-                                if (null != relativeBinding)
-                                {
-                                    applying = true;
-                                    relativeBinding.Apply(true);
-                                    applying = false;
-                                }
-
-                                OnPropertyChanged(relativeProperty.PropertyName);
-                            }
-                        }
-                    }
-                }
-                else if (true == same && true == forceSendChangeSignal)
+                if (binding != null && !currentlyApplying)
                 {
-                    if (binding != null && !currentlyApplying)
-                    {
-                        applying = true;
-                        binding.Apply(true);
-                        applying = false;
-                    }
+                    applying = true;
+                    binding.Apply(true);
+                    applying = false;
+                }
 
-                    OnPropertyChanged(property.PropertyName);
+                OnPropertyChanged(property.PropertyName);
 
-                    if (null != propertyGroup)
+                if (null != propertyGroup)
+                {
+                    foreach (var relativeProperty in propertyGroup)
                     {
-                        foreach (var relativeProperty in propertyGroup)
+                        if (relativeProperty != property)
                         {
-                            if (relativeProperty != property)
-                            {
-                                var relativeContext = GetOrCreateContext(relativeProperty);
-                                var relativeBinding = relativeContext.Binding;
-
-                                if (null != relativeBinding)
-                                {
-                                    applying = true;
-                                    relativeBinding.Apply(true);
-                                    applying = false;
-                                }
+                            var relativeContext = GetOrCreateContext(relativeProperty);
+                            var relativeBinding = relativeContext.Binding;
 
-                                OnPropertyChanged(relativeProperty.PropertyName);
+                            if (null != relativeBinding)
+                            {
+                                applying = true;
+                                relativeBinding.Apply(true);
+                                applying = false;
                             }
+
+                            OnPropertyChanged(relativeProperty.PropertyName);
                         }
                     }
                 }
index 7061209..6c68f43 100755 (executable)
@@ -247,7 +247,7 @@ namespace Tizen.NUI.Binding.Internals
                     // Log.Warning("Binding", "{0} can not be converted to type '{1}'", value, property.ReturnType);
                     return;
                 }
-                target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted, false);
+                target.SetValueCore(property, value, SetValueFlags.ClearDynamicResource, BindableObject.SetValuePrivateFlags.Default | BindableObject.SetValuePrivateFlags.Converted);
                 return;
             }