Permalink
Browse files

only change barButton state if different

  • Loading branch information...
1 parent 84dfa5f commit 2d0236757ea94d10a7e80b3d4d26c80ae2b18fc7 @ettore committed Mar 12, 2013
Showing with 48 additions and 44 deletions.
  1. +30 −28 CLCGBarButtonItem.m
  2. +18 −16 CLCGTogglerView.m
View
@@ -117,38 +117,40 @@ -(id)initWithImage:(UIImage *)img
-(void)setState:(enum CLCGBarButtonItemState)state
{
- switch (state) {
- case CLCGBarButtonItemStateReady:
- if (mIsSystemItem) {
- // remove customView so that UIBarButtonItem system graphics are rendered
- [self setCustomView:nil];
- } else {
- [mToggler setState:CLCGTogglerFirstView];
- if ([[self title] length] == 0) {
- [self setCustomView:mToggler];
- } else {
+ if (state != mState) {
+ switch (state) {
+ case CLCGBarButtonItemStateReady:
+ if (mIsSystemItem) {
+ // remove customView so that UIBarButtonItem system graphics are rendered
[self setCustomView:nil];
+ } else {
+ [mToggler setState:CLCGTogglerFirstView];
+ if ([[self title] length] == 0) {
+ [self setCustomView:mToggler];
+ } else {
+ [self setCustomView:nil];
+ }
}
- }
- break;
- case CLCGBarButtonItemStateBusy:
- // show the spinner
- [mToggler setState:CLCGTogglerSecondView];
- [self setCustomView:mToggler];
- break;
- case CLCGBarButtonItemStateHidden:
- [mToggler setState:CLCGTogglerFirstView];
- [[mToggler firstView] setHidden:YES];
- if ([[self title] length] > 0) {
- // for a textual button, this will "show" the empty button we created.
+ break;
+ case CLCGBarButtonItemStateBusy:
+ // show the spinner
+ [mToggler setState:CLCGTogglerSecondView];
[self setCustomView:mToggler];
- }
- break;
- default:
- break;
- }
+ break;
+ case CLCGBarButtonItemStateHidden:
+ [mToggler setState:CLCGTogglerFirstView];
+ [[mToggler firstView] setHidden:YES];
+ if ([[self title] length] > 0) {
+ // for a textual button, this will "show" the empty button we created.
+ [self setCustomView:mToggler];
+ }
+ break;
+ default:
+ break;
+ }
- mState = state;
+ mState = state;
+ }
}
View
@@ -107,23 +107,25 @@ -(void)layoutSubviews
-(void)setState:(enum CLCGTogglerState)state
{
- if (CLCGTogglerFirstView == state) {
- [mFirstView setHidden:NO];
- [mSecondView setHidden:YES];
- [mFirstView setAlpha:1.0];
- [mSecondView setAlpha:0.0];
- } else if (CLCGTogglerSecondView == state) {
- [mFirstView setHidden:YES];
- [mSecondView setHidden:NO];
- [mFirstView setAlpha:0.0];
- [mSecondView setAlpha:1.0];
- } else {
- CLCG_ASSERT(NO);
+ if (state != mState) {
+ if (CLCGTogglerFirstView == state) {
+ [mFirstView setHidden:NO];
+ [mSecondView setHidden:YES];
+ [mFirstView setAlpha:1.0];
+ [mSecondView setAlpha:0.0];
+ } else if (CLCGTogglerSecondView == state) {
+ [mFirstView setHidden:YES];
+ [mSecondView setHidden:NO];
+ [mFirstView setAlpha:0.0];
+ [mSecondView setAlpha:1.0];
+ } else {
+ CLCG_ASSERT(NO);
+ }
+
+ mState = state;
+
+ [self setNeedsDisplay];
}
-
- mState = state;
-
- [self setNeedsDisplay];
}

0 comments on commit 2d02367

Please sign in to comment.