Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fixes KVO native binding #403

Merged
merged 1 commit into from Sep 30, 2016

Conversation

Projects
None yet
4 participants
@rmarinho
Copy link
Member

commented Sep 30, 2016

Description of Change

Keep our native property listener around the same time we keep our proxy, check if we are KVO compliant before adding observer

This fixes a crash when using NativeBinding 2-way without using a event. The KVO implementation wasn't ok, first we need to keep the observer around, nativePropertyListener, and we also need to make sure the a key for our property exists, normally it's a lowercase of XIOS public property. The only way was to catch the exception that the key wasn't found.

Also added a example of how one can make a KVO compliant control to use 2 way binding in iOS without specifying the event.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense
[iOS] Keep our native property listener around the same time we keep …
…our proxy, check if we are KVO compliant before adding observer

@jassmith jassmith merged commit fa2f016 into master Sep 30, 2016

1 of 4 checks passed

Android-UITests Started TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: UI Tests :: OSX Test Cloud Package - Run Android 6.0.1
Details
OSX-Debug-C8 Started TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: OSX Debug
Details
iOS9-UITests Started TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: UI Tests :: OSX Test Cloud Package - Run iOS Unified iOS9
Details
Windows-Debug-C8 Finished TeamCity Build Xamarin.Forms :: Debug :: Cycle8 :: Windows Debug : Tests passed: 3456, ignored: 8
Details
SetValueFromNative<TNativeView>(sender as TNativeView, targetProperty, bindableProperty);
};
SetValueFromNative<TNativeView>(sender as TNativeView, targetProperty, bindableProperty);
//we need to keep the listener around he same time we have the proxy

This comment has been minimized.

Copy link
@samhouts

samhouts Sep 30, 2016

Member

typo in comment

nativePropertyListener = null;
if (ex.Name == "NSUnknownKeyException")
{
System.Diagnostics.Debug.WriteLine("KVO not supported, try specify a UpdateSourceEventName instead.");

This comment has been minimized.

Copy link
@samhouts

samhouts Sep 30, 2016

Member

"try specifying" or "try to specify"

rmarinho added a commit that referenced this pull request Oct 4, 2016

[iOS] Keep our native property listener around the same time we keep …
…our proxy, check if we are KVO compliant before adding observer (#403)

@rmarinho rmarinho deleted the fix-iosnativebinding branch Oct 7, 2016

@samhouts samhouts modified the milestones: 2.3.4, 2.3.3 Jun 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.