summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorRui Marinho <me@ruimarinho.net>2016-09-30 19:48:22 +0100
committerJason Smith <jason.smith@xamarin.com>2016-09-30 11:48:22 -0700
commitfa2f01680d23a813a5b1ab7795151b6dcb0feb7f (patch)
tree74e7d0e301f237cde7a0b1ce4e95d53ebcc80a43 /Xamarin.Forms.Platform.iOS
parentc07c2314f5737d480088319e87ab299b22cb4ddc (diff)
downloadxamarin-forms-fa2f01680d23a813a5b1ab7795151b6dcb0feb7f.tar.gz
xamarin-forms-fa2f01680d23a813a5b1ab7795151b6dcb0feb7f.tar.bz2
xamarin-forms-fa2f01680d23a813a5b1ab7795151b6dcb0feb7f.zip
[iOS] Keep our native property listener around the same time we keep our proxy, check if we are KVO compliant before adding observer (#403)
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs26
-rw-r--r--Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs4
2 files changed, 27 insertions, 3 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs b/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs
index eab88e81..4c3eed98 100644
--- a/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs
+++ b/Xamarin.Forms.Platform.iOS/Extensions/UIViewExtensions.cs
@@ -37,9 +37,31 @@ namespace Xamarin.Forms.Platform.iOS
}
NativeViewPropertyListener nativePropertyListener = null;
- if (bindingBase.Mode == BindingMode.TwoWay) {
+ if (bindingBase.Mode == BindingMode.TwoWay)
+ {
nativePropertyListener = new NativeViewPropertyListener(propertyName);
- view.AddObserver(nativePropertyListener, propertyName, 0, IntPtr.Zero);
+ try
+ {
+ //TODO: We need to figure a way to map the value back to the real objectiveC property.
+ //the X.IOS camelcase property name won't work
+ var key = new Foundation.NSString(propertyName.ToLower());
+ var valueKey = view.ValueForKey(key);
+ if (valueKey != null)
+ {
+ view.AddObserver(nativePropertyListener, key, Foundation.NSKeyValueObservingOptions.New, IntPtr.Zero);
+ }
+ }
+ catch (Foundation.MonoTouchException ex)
+ {
+ nativePropertyListener = null;
+ if (ex.Name == "NSUnknownKeyException")
+ {
+ System.Diagnostics.Debug.WriteLine("KVO not supported, try specify a UpdateSourceEventName instead.");
+ return;
+ }
+ throw ex;
+ }
+
}
NativeBindingHelpers.SetBinding(view, propertyName, bindingBase, nativePropertyListener);
diff --git a/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs b/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs
index 2d872af2..4e6601ef 100644
--- a/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs
+++ b/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs
@@ -17,8 +17,10 @@ namespace Xamarin.Forms.Platform.iOS
public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
{
- if (keyPath == TargetProperty)
+ if (keyPath.ToString().Equals(TargetProperty, StringComparison.InvariantCultureIgnoreCase))
PropertyChanged?.Invoke(ofObject, new PropertyChangedEventArgs(TargetProperty));
+ else
+ base.ObserveValue(keyPath, ofObject, change, context);
}
}
}