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

[TIMOB-15205] iOS7 : Fire change event when there is actually a change in value. #4695

Merged
merged 2 commits into from
Sep 16, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions iphone/Classes/TiUISwitch.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ -(void)setCenter:(CGPoint)center
- (IBAction)switchChanged:(id)sender
{
NSNumber * newValue = [NSNumber numberWithBool:[(UISwitch *)sender isOn]];
[self.proxy replaceValue:newValue forKey:@"value" notification:NO];
id current = [self.proxy valueForUndefinedKey:@"value"];
[self.proxy replaceValue:newValue forKey:@"value" notification:NO];

//No need to setValue, because it's already been set.
if ([self.proxy _hasListeners:@"change"])
if ([self.proxy _hasListeners:@"change"] && (current != newValue) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While NSNumber bools will be constants and this will work fine, this is technically inaccurate. i.e., this should be:
&& (current != newValue) && ![current isEqual:newValue]

The pointer compare is for nil vs nil. The isEqual is for different objects holding the same value.

{
[self.proxy fireEvent:@"change" withObject:[NSDictionary dictionaryWithObject:newValue forKey:@"value"]];
}
Expand Down