[NUI] Listen text changed event so that can notify binded instance when Text is chang...
authorFang Xiaohui <xiaohui.fang@samsung.com>
Wed, 23 Mar 2022 03:09:34 +0000 (11:09 +0800)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 27 Apr 2022 02:44:42 +0000 (11:44 +0900)
src/Tizen.NUI/src/public/BaseComponents/TextEditor.cs
src/Tizen.NUI/src/public/BaseComponents/TextField.cs
src/Tizen.NUI/src/public/XamlBinding/BindableObject.cs

index 3c86d87..37e9706 100755 (executable)
@@ -1843,28 +1843,32 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        /// Only used by the IL of xaml, will never changed to not hidden.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override bool IsCreateByXaml
+        internal override bool IsBinded
         {
             get
             {
-                return base.IsCreateByXaml;
+                return base.IsBinded;
             }
             set
             {
-                base.IsCreateByXaml = value;
+                base.IsBinded = value;
 
                 if (value == true)
                 {
-                    this.TextChanged += (obj, e) =>
-                    {
-                        this.Text = e.TextEditor.Text;
-                    };
+                    TextChanged += TextEditorTextChanged;
+                }
+                else
+                {
+                    TextChanged -= TextEditorTextChanged;
                 }
             }
         }
 
+        private void TextEditorTextChanged(object sender, TextChangedEventArgs e)
+        {
+            ForceNotifyBindedInstance(TextProperty);
+        }
+
         /// <summary>
         /// The FontSizeScale property. <br />
         /// The default value is 1.0. <br />
@@ -2115,6 +2119,11 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
 
+            if (IsBinded)
+            {
+                TextChanged -= TextEditorTextChanged;
+            }
+
             base.Dispose(type);
         }
 
index 3e74893..7c008a6 100755 (executable)
@@ -2017,28 +2017,32 @@ namespace Tizen.NUI.BaseComponents
             }
         }
 
-        /// Only used by the IL of xaml, will never changed to not hidden.
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public override bool IsCreateByXaml
+        internal override bool IsBinded
         {
             get
             {
-                return base.IsCreateByXaml;
+                return base.IsBinded;
             }
             set
             {
-                base.IsCreateByXaml = value;
+                base.IsBinded = value;
 
                 if (value == true)
                 {
-                    this.TextChanged += (obj, e) =>
-                    {
-                        this.Text = e.TextField.Text;
-                    };
+                    TextChanged += TextEditorTextChanged;
+                }
+                else
+                {
+                    TextChanged -= TextEditorTextChanged;
                 }
             }
         }
 
+        private void TextEditorTextChanged(object sender, TextChangedEventArgs e)
+        {
+            ForceNotifyBindedInstance(TextProperty);
+        }
+
         /// <summary>
         /// Get the InputMethodContext instance.
         /// </summary>
@@ -2161,6 +2165,11 @@ namespace Tizen.NUI.BaseComponents
                 }
             }
 
+            if (IsBinded)
+            {
+                TextChanged -= TextEditorTextChanged;
+            }
+
             base.Dispose(type);
         }
 
index 7897d25..c42b12c 100755 (executable)
@@ -209,19 +209,12 @@ 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.
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public virtual bool IsCreateByXaml
+        public bool IsCreateByXaml
         {
-            get
-            {
-                return isCreateByXaml;
-            }
-            set
-            {
-                isCreateByXaml = value;
-            }
+            get;
+            set;
         }
 
         /// <summary>
@@ -286,6 +279,48 @@ namespace Tizen.NUI.Binding
             }
         }
 
+        /// This will be public opened in next ACR.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public void ForceNotifyBindedInstance(BindableProperty property)
+        {
+            if (null != property)
+            {
+                BindablePropertyContext context = GetOrCreateContext(property);
+
+                if (null != context?.Binding)
+                {
+                    applying = true;
+                    context.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);
+                        }
+                    }
+                }
+            }
+        }
+
         /// <summary>
         /// Sets the value of the propertyKey.
         /// </summary>
@@ -736,7 +771,7 @@ namespace Tizen.NUI.Binding
             }
         }
 
-        internal bool IsBinded
+        internal virtual bool IsBinded
         {
             get;
             set;