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
This commit is contained in:
Lorenzo Blasa
2022-12-13 09:49:46 -08:00
committed by Facebook GitHub Bot
parent b686567e2b
commit 8dd5b57444

View File

@@ -37,6 +37,7 @@ static NSString* const kSKCellIdentifier =
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10]; cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10];
cell.textLabel.text = [self.elements[row][@"state"] cell.textLabel.text = [self.elements[row][@"state"]
stringByAppendingString:self.elements[row][@"name"]]; stringByAppendingString:self.elements[row][@"name"]];
return cell; return cell;
} }
@@ -52,12 +53,19 @@ static NSString* const kSKCellIdentifier =
- (void)viewDidLoad { - (void)viewDidLoad {
[super 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] self.scrollView = [[UIScrollView alloc]
initWithFrame:CGRectMake( initWithFrame:CGRectMake(
0, 0,
STATE_VIEW_HEIGHT, STATE_VIEW_HEIGHT,
self.view.frame.size.width, self.view.frame.size.width,
self.view.frame.size.height - 100 - STATE_VIEW_HEIGHT)]; self.view.frame.size.height - 100 - STATE_VIEW_HEIGHT)];
self.logLabel = self.logLabel =
[[UILabel alloc] initWithFrame:CGRectMake( [[UILabel alloc] initWithFrame:CGRectMake(
0, 0,
@@ -66,11 +74,9 @@ static NSString* const kSKCellIdentifier =
self.scrollView.frame.size.height)]; self.scrollView.frame.size.height)];
self.logLabel.numberOfLines = 0; self.logLabel.numberOfLines = 0;
self.logLabel.font = [UIFont systemFontOfSize:10.0f]; self.logLabel.font = [UIFont systemFontOfSize:10.0f];
[self.scrollView addSubview:self.logLabel]; [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] [self.stateTable registerClass:[UITableViewCell class]
forCellReuseIdentifier:kSKCellIdentifier]; forCellReuseIdentifier:kSKCellIdentifier];
self.stateTable.rowHeight = 14; self.stateTable.rowHeight = 14;
@@ -104,10 +110,11 @@ static NSString* const kSKCellIdentifier =
[self.logLabel sizeToFit]; [self.logLabel sizeToFit];
self.scrollView.contentSize = self.logLabel.frame.size; self.scrollView.contentSize = self.logLabel.frame.size;
// Scroll to bottom CGFloat y = 0;
CGPoint bottomOffset = CGPointMake( if (self.scrollView.contentSize.height > self.scrollView.bounds.size.height) {
0, y = self.scrollView.contentSize.height - self.scrollView.bounds.size.height;
self.scrollView.contentSize.height - self.scrollView.bounds.size.height); }
CGPoint bottomOffset = CGPointMake(0, y);
[self.scrollView setContentOffset:bottomOffset animated:YES]; [self.scrollView setContentOffset:bottomOffset animated:YES];
} }