From 8dd5b57444b323626f1d1d7af65e0e76595bf9b0 Mon Sep 17 00:00:00 2001 From: Lorenzo Blasa Date: Tue, 13 Dec 2022 09:49:46 -0800 Subject: [PATCH] Diagnostic controller improvement Summary: The diagnostics controller is not the best crafted UIViewController. It has many things that should be improved. - This diff just sets the background of the root view to white. At least, that will ensure that its text content is always shown if the screen background happens to be black (same as font colour). - Correct offset calculation, used for scrolling. Effectively, only set it if the content to be displayed no longer fits in the scrollview viewport. Reviewed By: LukeDefeo Differential Revision: D41876904 fbshipit-source-id: e2a89d8f6001e5b626c8df1d0832e77783999b81 --- .../FlipperDiagnosticsViewController.m | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/iOS/FlipperKit/FlipperDiagnosticsViewController.m b/iOS/FlipperKit/FlipperDiagnosticsViewController.m index eb44a813a..4dc5394b3 100644 --- a/iOS/FlipperKit/FlipperDiagnosticsViewController.m +++ b/iOS/FlipperKit/FlipperDiagnosticsViewController.m @@ -37,6 +37,7 @@ static NSString* const kSKCellIdentifier = cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10]; cell.textLabel.text = [self.elements[row][@"state"] stringByAppendingString:self.elements[row][@"name"]]; + return cell; } @@ -52,12 +53,19 @@ static NSString* const kSKCellIdentifier = - (void)viewDidLoad { [super viewDidLoad]; + self.view.backgroundColor = [UIColor whiteColor]; + + self.stateTable = [[UITableView alloc] + initWithFrame:CGRectMake( + 0, 0, self.view.bounds.size.width, STATE_VIEW_HEIGHT)]; + self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake( 0, STATE_VIEW_HEIGHT, self.view.frame.size.width, self.view.frame.size.height - 100 - STATE_VIEW_HEIGHT)]; + self.logLabel = [[UILabel alloc] initWithFrame:CGRectMake( 0, @@ -66,11 +74,9 @@ static NSString* const kSKCellIdentifier = self.scrollView.frame.size.height)]; self.logLabel.numberOfLines = 0; self.logLabel.font = [UIFont systemFontOfSize:10.0f]; + [self.scrollView addSubview:self.logLabel]; - self.stateTable = [[UITableView alloc] - initWithFrame:CGRectMake( - 0, 0, self.view.bounds.size.width, STATE_VIEW_HEIGHT)]; [self.stateTable registerClass:[UITableViewCell class] forCellReuseIdentifier:kSKCellIdentifier]; self.stateTable.rowHeight = 14; @@ -104,10 +110,11 @@ static NSString* const kSKCellIdentifier = [self.logLabel sizeToFit]; self.scrollView.contentSize = self.logLabel.frame.size; - // Scroll to bottom - CGPoint bottomOffset = CGPointMake( - 0, - self.scrollView.contentSize.height - self.scrollView.bounds.size.height); + CGFloat y = 0; + if (self.scrollView.contentSize.height > self.scrollView.bounds.size.height) { + y = self.scrollView.contentSize.height - self.scrollView.bounds.size.height; + } + CGPoint bottomOffset = CGPointMake(0, y); [self.scrollView setContentOffset:bottomOffset animated:YES]; }