diff --git a/React/CoreModules/RCTFPSGraph.m b/React/CoreModules/RCTFPSGraph.m index 23ef7cf69e89d5..6beaf7d16f1d45 100644 --- a/React/CoreModules/RCTFPSGraph.m +++ b/React/CoreModules/RCTFPSGraph.m @@ -32,6 +32,7 @@ @implementation RCTFPSGraph { NSUInteger _minFPS; NSUInteger _length; NSUInteger _height; + CGFloat _scale; } - (instancetype)initWithFrame:(CGRect)frame color:(UIColor *)color @@ -43,6 +44,7 @@ - (instancetype)initWithFrame:(CGRect)frame color:(UIColor *)color _minFPS = 60; _length = (NSUInteger)floor(frame.size.width); _height = (NSUInteger)floor(frame.size.height); + _scale = 60.0 / (CGFloat)_height; _frames = calloc(sizeof(CGFloat), _length); _color = color; @@ -97,11 +99,14 @@ - (void)onTick:(NSTimeInterval)timestamp self->_label.text = [NSString stringWithFormat:@"%lu", (unsigned long)self->_FPS]; }); - CGFloat scale = 60.0 / (CGFloat)_height; + CGFloat previousScale = _scale; + CGFloat targetFps = MAX(_maxFPS, 60.0); + _scale = targetFps / (CGFloat)_height; for (NSUInteger i = 0; i < _length - 1; i++) { - _frames[i] = _frames[i + 1]; + // Move each Frame back one position and adjust to new scale (if there is a new scale) + _frames[i] = _frames[i + 1] * previousScale / _scale; } - _frames[_length - 1] = (double)_FPS / scale; + _frames[_length - 1] = (double)_FPS / _scale; CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, (CGFloat)_height);