Skip to content

Commit

Permalink
[TIMOB-8547] iOS: switch change event gets fired when adding to a vie…
Browse files Browse the repository at this point in the history
…w or window
  • Loading branch information
Max Stepanov committed Apr 5, 2012
1 parent 8c92aee commit 3705d2d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion iphone/Classes/TiUISwitch.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ -(void)setValue_:(id)value
BOOL newValue = [TiUtils boolValue:value];
BOOL animated = !reproxying;
UISwitch * ourSwitch = [self switchView];
if ([ourSwitch isOn] == newValue) {
return;
}
[ourSwitch setOn:newValue animated:animated];

// Don't rely on switchChanged: - isOn can report erroneous values immediately after the value is changed!
// This only seems to happen in 4.2+ - could be an Apple bug.
if (reproxying==NO && [self.proxy _hasListeners:@"change"])
if ((reproxying == NO) && configurationSet && [self.proxy _hasListeners:@"change"])
{
[self.proxy fireEvent:@"change" withObject:[NSDictionary dictionaryWithObject:value forKey:@"value"]];
}
Expand Down
3 changes: 3 additions & 0 deletions iphone/Classes/TiUIView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ void ModifyScrollViewForKeyboardHeightAndContentHeightWithResponderRect(UIScroll
*/
@interface TiUIView : UIView<TiProxyDelegate,LayoutAutosizing>
{
@protected
BOOL configurationSet;

@private
TiProxy *proxy;
TiAnimation *animation;
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUIView.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ -(void)initializeState
-(void)configurationSet
{
// can be used to trigger things after all properties are set
configurationSet = YES;
}

-(void)setProxy:(TiProxy *)p
Expand Down

0 comments on commit 3705d2d

Please sign in to comment.