Perform the initial updateLoop iteration immediately after attaching the view

This commit is contained in:
Cameron Gutman
2020-11-14 16:42:17 -06:00
parent 78f2b8ac47
commit 9b8a179f4a
2 changed files with 28 additions and 18 deletions
+14 -9
View File
@@ -76,11 +76,17 @@ static UIImage* noImage;
#endif #endif
[self updateAppImage]; [self updateAppImage];
[self startUpdateLoop];
return self; return self;
} }
- (void)didMoveToSuperview {
// Start our update loop when we are added to our cell
if (self.superview != nil) {
[self updateLoop];
}
}
- (void) appClicked:(UIView *)view { - (void) appClicked:(UIView *)view {
[_callback appClicked:_app view:view]; [_callback appClicked:_app view:view];
} }
@@ -202,11 +208,12 @@ static UIImage* noImage;
} }
} }
- (void) startUpdateLoop {
[self performSelector:@selector(updateLoop) withObject:self afterDelay:REFRESH_CYCLE];
}
- (void) updateLoop { - (void) updateLoop {
// Stop immediately if the view has been detached
if (self.superview == nil) {
return;
}
// Update the app image if neccessary // Update the app image if neccessary
if ((_appOverlay != nil && ![_app.id isEqualToString:_app.host.currentGame]) || if ((_appOverlay != nil && ![_app.id isEqualToString:_app.host.currentGame]) ||
(_appOverlay == nil && [_app.id isEqualToString:_app.host.currentGame])) { (_appOverlay == nil && [_app.id isEqualToString:_app.host.currentGame])) {
@@ -216,10 +223,8 @@ static UIImage* noImage;
// Update opacity if neccessary // Update opacity if neccessary
[self setAlpha:_app.hidden ? 0.4 : 1.0]; [self setAlpha:_app.hidden ? 0.4 : 1.0];
// Stop updating when we detach from our parent view // Queue the next refresh cycle
if (self.superview != nil) { [self performSelector:@selector(updateLoop) withObject:self afterDelay:REFRESH_CYCLE];
[self performSelector:@selector(updateLoop) withObject:self afterDelay:REFRESH_CYCLE];
}
} }
@end @end
+14 -9
View File
@@ -132,11 +132,17 @@ static const int LABEL_DY = 20;
[self addTarget:self action:@selector(hostClicked) forControlEvents:UIControlEventPrimaryActionTriggered]; [self addTarget:self action:@selector(hostClicked) forControlEvents:UIControlEventPrimaryActionTriggered];
[self updateContentsForHost:host]; [self updateContentsForHost:host];
[self startUpdateLoop];
return self; return self;
} }
- (void)didMoveToSuperview {
// Start our update loop when we are added to our cell
if (self.superview != nil && _host != nil) {
[self updateLoop];
}
}
- (void) updateBounds { - (void) updateBounds {
float x = FLT_MAX; float x = FLT_MAX;
float y = FLT_MAX; float y = FLT_MAX;
@@ -187,17 +193,16 @@ static const int LABEL_DY = 20;
[self updateBounds]; [self updateBounds];
} }
- (void) startUpdateLoop {
[self performSelector:@selector(updateLoop) withObject:self afterDelay:REFRESH_CYCLE];
}
- (void) updateLoop { - (void) updateLoop {
// Stop immediately if the view has been detached
if (self.superview == nil) {
return;
}
[self updateContentsForHost:_host]; [self updateContentsForHost:_host];
// Stop updating when we detach from our parent view // Queue the next refresh cycle
if (self.superview != nil) { [self performSelector:@selector(updateLoop) withObject:self afterDelay:REFRESH_CYCLE];
[self performSelector:@selector(updateLoop) withObject:self afterDelay:REFRESH_CYCLE];
}
} }
- (void) hostLongClicked:(UILongPressGestureRecognizer*)gesture { - (void) hostLongClicked:(UILongPressGestureRecognizer*)gesture {