ScreenTracesTestScreensListViewController.m 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Non-google3 relative import to support building with Xcode.
  15. #import "ScreenTracesTestScreensListViewController.h"
  16. #import "ScreenTraceTestViewControllers/FastLargeTableViewController.h"
  17. #import "ScreenTraceTestViewControllers/FrozenFramesViewController.h"
  18. #import "ScreenTraceTestViewControllers/SlowLargeTableViewController.h"
  19. /** Reuse identifier of cell that displays name of test screen. */
  20. static NSString *const kTestScreenCellReuseIdentifier = @"TestScreenCell";
  21. /** Name of cell that opens a slow rendering table view with many cells. */
  22. static NSString *const largeSlowTableViewCellName = @"Slow Table View";
  23. /** Name of cell that opens a fairly fast rendering table view with many cells. */
  24. static NSString *const largeFastTableViewCellName = @"Fast Table View";
  25. /** Name of cell that opens a view to reliably reproduce frozen frames. */
  26. static NSString *const frozenFramesViewController = @"Frozen Frames";
  27. @interface ScreenTracesTestScreensListViewController ()
  28. /** Array of names of test screens in the catalog. */
  29. @property(nonatomic) NSArray *screenList;
  30. @end
  31. @implementation ScreenTracesTestScreensListViewController
  32. - (NSArray *)screenList {
  33. if (!_screenList) {
  34. _screenList =
  35. @[ largeSlowTableViewCellName, largeFastTableViewCellName, frozenFramesViewController ];
  36. }
  37. return _screenList;
  38. }
  39. - (void)viewDidLoad {
  40. [super viewDidLoad];
  41. [self.tableView registerClass:[UITableViewCell class]
  42. forCellReuseIdentifier:kTestScreenCellReuseIdentifier];
  43. self.navigationItem.title = @"Select Test Screen";
  44. self.navigationItem.accessibilityLabel = @"Select Test Screen";
  45. }
  46. #pragma mark - Table view data source
  47. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  48. return 1;
  49. }
  50. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  51. return self.screenList.count;
  52. }
  53. - (UITableViewCell *)tableView:(UITableView *)tableView
  54. cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  55. UITableViewCell *cell =
  56. [tableView dequeueReusableCellWithIdentifier:kTestScreenCellReuseIdentifier];
  57. cell.textLabel.text = [self.screenList objectAtIndex:indexPath.row];
  58. cell.accessibilityLabel = [self.screenList objectAtIndex:indexPath.row];
  59. return cell;
  60. }
  61. #pragma mark Table view delegate
  62. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  63. NSString *selectedCellName = [self.screenList objectAtIndex:indexPath.row];
  64. UIViewController *viewControllerToShow;
  65. if ([selectedCellName isEqualToString:largeSlowTableViewCellName]) {
  66. viewControllerToShow = [[SlowLargeTableViewController alloc] initWithNibName:nil bundle:nil];
  67. } else if ([selectedCellName isEqualToString:largeFastTableViewCellName]) {
  68. viewControllerToShow = [[FastLargeTableViewController alloc] initWithNibName:nil bundle:nil];
  69. } else if ([selectedCellName isEqualToString:frozenFramesViewController]) {
  70. viewControllerToShow = [[FrozenFramesViewController alloc] initWithNibName:nil bundle:nil];
  71. }
  72. if (viewControllerToShow) {
  73. [self.splitViewController showDetailViewController:viewControllerToShow sender:self];
  74. }
  75. }
  76. @end