VLCSidebarController.m 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // VLCSidebarController.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 15/06/15.
  6. // Copyright © 2015 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCSidebarController.h"
  9. #import "GHRevealViewController.h"
  10. #import "VLCMenuTableViewController.h"
  11. @interface VLCSidebarController()
  12. {
  13. GHRevealViewController *_revealController;
  14. VLCMenuTableViewController *_menuViewController;
  15. UIViewController *_contentViewController;
  16. }
  17. @end
  18. @implementation VLCSidebarController
  19. + (instancetype)sharedInstance
  20. {
  21. static VLCSidebarController *sharedInstance = nil;
  22. static dispatch_once_t pred;
  23. dispatch_once(&pred, ^{
  24. sharedInstance = [VLCSidebarController new];
  25. });
  26. return sharedInstance;
  27. }
  28. - (instancetype)init
  29. {
  30. self = [super init];
  31. if (!self)
  32. return self;
  33. _revealController = [[GHRevealViewController alloc] initWithNibName:nil bundle:nil];
  34. _revealController.extendedLayoutIncludesOpaqueBars = YES;
  35. _revealController.edgesForExtendedLayout = UIRectEdgeAll;
  36. _menuViewController = [[VLCMenuTableViewController alloc] initWithNibName:nil bundle:nil];
  37. _revealController.sidebarViewController = _menuViewController;
  38. return self;
  39. }
  40. #pragma mark - VC handling
  41. - (UIViewController *)fullViewController
  42. {
  43. return _revealController;
  44. }
  45. - (void)setContentViewController:(UIViewController *)contentViewController
  46. {
  47. contentViewController.view.backgroundColor = [UIColor VLCDarkBackgroundColor];
  48. _revealController.contentViewController = contentViewController;
  49. }
  50. - (UIViewController *)contentViewController
  51. {
  52. return _revealController.contentViewController;
  53. }
  54. #pragma mark - actual work
  55. - (void)selectRowAtIndexPath:(NSIndexPath *)indexPath scrollPosition:(UITableViewScrollPosition)scrollPosition
  56. {
  57. [_menuViewController selectRowAtIndexPath:indexPath
  58. animated:NO
  59. scrollPosition:scrollPosition];
  60. }
  61. - (void)hideSidebar
  62. {
  63. [_revealController toggleSidebar:NO duration:kGHRevealSidebarDefaultAnimationDuration];
  64. }
  65. - (void)toggleSidebar
  66. {
  67. [_revealController toggleSidebar:!_revealController.sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  68. }
  69. @end