Просмотр исходного кода

Bug fixes / code cleanup

Also make image preview use checker background
Tanner Bennett лет назад: 6
Родитель
Сommit
fced419509

+ 23 - 0
Classes/Core/Controllers/FLEXTableViewController.h

@@ -34,6 +34,8 @@ extern CGFloat const kFLEXDebounceForExpensiveIO;
 /// Simply calls into initWithStyle:
 - (id)init;
 
+@property (nonatomic) FLEXTableView *tableView;
+
 /// Defaults to NO.
 ///
 /// Setting this to YES will initialize the carousel and the view.
@@ -107,7 +109,28 @@ extern CGFloat const kFLEXDebounceForExpensiveIO;
 /// in the background before updating the UI back on the main queue.
 - (void)onBackgroundQueue:(NSArray *(^)(void))backgroundBlock thenOnMainQueue:(void(^)(NSArray *))mainBlock;
 
+/// Adds up to 3 additional items to the toolbar in right-to-left order.
+///
+/// That is, the first item in the given array will be the rightmost item behind
+/// any existing toolbar items. By default, buttons for bookmarks and tabs are shown.
+///
+/// If you wish to have more control over how the buttons are arranged or which
+/// buttons are displayed, you can access the properties for the pre-existing
+/// toolbar items directly and manually set \c self.toolbarItems by overriding
+/// the \c setupToolbarItems method below.
+- (void)addToolbarItems:(NSArray<UIBarButtonItem *> *)items;
+
+/// Subclasses may override. You should not need to call this method directly.
+- (void)setupToolbarItems;
+
+@property (nonatomic, readonly) UIBarButtonItem *shareToolbarItem;
+@property (nonatomic, readonly) UIBarButtonItem *bookmarksToolbarItem;
+@property (nonatomic, readonly) UIBarButtonItem *openTabsToolbarItem;
+
 /// Whether or not to display the "share" icon in the middle of the toolbar. NO by default.
+///
+/// Turning this on after you have added custom toolbar items will
+/// push off the leftmost toolbar item and shift the others leftward.
 @property (nonatomic) BOOL showsShareToolbarItem;
 /// Called when the share button is pressed.
 /// Default implementation does nothign. Subclasses may override.

+ 81 - 16
Classes/Core/Controllers/FLEXTableViewController.m

@@ -34,9 +34,15 @@ CGFloat const kFLEXDebounceForExpensiveIO = 0.5;
 @property (nonatomic, readonly) UIView *tableHeaderViewContainer;
 
 @property (nonatomic, readonly) BOOL manuallyDeactivateSearchOnDisappear;
+
+@property (nonatomic) UIBarButtonItem *middleToolbarItem;
+@property (nonatomic) UIBarButtonItem *middleLeftToolbarItem;
+@property (nonatomic) UIBarButtonItem *leftmostToolbarItem;
 @end
 
 @implementation FLEXTableViewController
+@dynamic tableView;
+@synthesize showsShareToolbarItem = _showsShareToolbarItem;
 @synthesize tableHeaderViewContainer = _tableHeaderViewContainer;
 @synthesize automaticallyShowsSearchBarCancelButton = _automaticallyShowsSearchBarCancelButton;
 
@@ -211,6 +217,18 @@ CGFloat const kFLEXDebounceForExpensiveIO = 0.5;
     self.view = [FLEXTableView style:self.style];
     self.tableView.dataSource = self;
     self.tableView.delegate = self;
+    
+    _shareToolbarItem = FLEXBarButtonItemSystem(Action, self, @selector(shareButtonPressed));
+    _bookmarksToolbarItem = FLEXBarButtonItemSystem(Bookmarks, self, @selector(showBookmarks));
+    _openTabsToolbarItem = FLEXBarButtonItemSystem(Organize, self, @selector(showTabSwitcher));
+    
+    for (UIBarButtonItem *item in @[_shareToolbarItem, _bookmarksToolbarItem, _openTabsToolbarItem]) {
+        item.width = 60;
+    }
+    
+    self.leftmostToolbarItem = UIBarButtonItem.flex_fixedSpace;
+    self.middleLeftToolbarItem = UIBarButtonItem.flex_fixedSpace;
+    self.middleToolbarItem = UIBarButtonItem.flex_fixedSpace;
 }
 
 - (void)viewDidLoad {
@@ -285,35 +303,86 @@ CGFloat const kFLEXDebounceForExpensiveIO = 0.5;
 }
 
 
-#pragma mark - Private
+#pragma mark - Toolbar, Public
 
 - (void)setupToolbarItems {
-    UIBarButtonItem *emptySpaceOrShare = UIBarButtonItem.flex_fixedSpace;
-    if (self.showsShareToolbarItem) {
-        emptySpaceOrShare = FLEXBarButtonItemSystem(Action, self, @selector(shareButtonPressed));
+    if (!self.isViewLoaded) {
+        return;
     }
     
     self.toolbarItems = @[
-        UIBarButtonItem.flex_fixedSpace,
-        UIBarButtonItem.flex_flexibleSpace,
-        UIBarButtonItem.flex_fixedSpace,
+        self.leftmostToolbarItem,
         UIBarButtonItem.flex_flexibleSpace,
-        UIBarButtonItem.flex_fixedSpace,
+        self.middleLeftToolbarItem,
         UIBarButtonItem.flex_flexibleSpace,
-        emptySpaceOrShare,
+        self.middleLeftToolbarItem,
         UIBarButtonItem.flex_flexibleSpace,
-        FLEXBarButtonItemSystem(Bookmarks, self, @selector(showBookmarks)),
+        self.bookmarksToolbarItem,
         UIBarButtonItem.flex_flexibleSpace,
-        FLEXBarButtonItemSystem(Organize, self, @selector(showTabSwitcher)),
+        self.openTabsToolbarItem,
     ];
     
     // Disable tabs entirely when not presented by FLEXExplorerViewController
     UIViewController *presenter = self.navigationController.presentingViewController;
     if (![presenter isKindOfClass:[FLEXExplorerViewController class]]) {
-        self.toolbarItems.lastObject.enabled = NO;
+        self.openTabsToolbarItem.enabled = NO;
+    }
+}
+
+- (void)addToolbarItems:(NSArray<UIBarButtonItem *> *)items {
+    if (self.showsShareToolbarItem) {
+        // Share button is in the middle, skip middle button
+        if (items.count > 0) {
+            self.middleLeftToolbarItem = items[0];
+        }
+        if (items.count > 1) {
+            self.leftmostToolbarItem = items[1];
+        }
+    } else {
+        // Add buttons right-to-left
+        if (items.count > 0) {
+            self.middleToolbarItem = items[0];
+        }
+        if (items.count > 1) {
+            self.middleLeftToolbarItem = items[1];
+        }
+        if (items.count > 2) {
+            self.leftmostToolbarItem = items[2];
+        }
     }
+    
+    [self setupToolbarItems];
 }
 
+- (void)setShowsShareToolbarItem:(BOOL)showShare {
+    if (_showsShareToolbarItem != showShare) {
+        _showsShareToolbarItem = showShare;
+        
+        if (showShare) {
+            // Push out leftmost item
+            self.leftmostToolbarItem = self.middleLeftToolbarItem;
+            self.middleLeftToolbarItem = self.middleToolbarItem;
+            
+            // Use share for middle
+            self.middleToolbarItem = self.shareToolbarItem;
+        } else {
+            // Remove share, shift custom items rightward
+            self.middleToolbarItem = self.middleLeftToolbarItem;
+            self.middleLeftToolbarItem = self.leftmostToolbarItem;
+            self.leftmostToolbarItem = UIBarButtonItem.flex_fixedSpace;
+        }
+    }
+    
+    [self setupToolbarItems];
+}
+
+- (void)shareButtonPressed {
+
+}
+
+
+#pragma mark - Private
+
 - (void)debounce:(void(^)(void))block {
     [self.debounceTimer invalidate];
     
@@ -443,10 +512,6 @@ CGFloat const kFLEXDebounceForExpensiveIO = 0.5;
     [self presentViewController:nav animated:YES completion:nil];
 }
 
-- (void)shareButtonPressed {
-
-}
-
 
 #pragma mark - Search Bar
 

+ 4 - 0
Classes/ExplorerInterface/FLEXExplorerViewController.m

@@ -149,6 +149,10 @@ typedef NS_ENUM(NSUInteger, FLEXExplorerMode) {
 }
 
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
+    if (self.window.isKeyWindow) {
+        [self.window resignKeyWindow];
+    }
+    
     UIViewController *viewControllerToAsk = [self viewControllerForRotationAndOrientation];
     UIInterfaceOrientationMask supportedOrientations = [FLEXUtility infoPlistSupportedInterfaceOrientationsMask];
     if (viewControllerToAsk && ![viewControllerToAsk isKindOfClass:[self class]]) {

+ 0 - 4
Classes/ExplorerInterface/FLEXWindowManagerController.m

@@ -38,10 +38,6 @@
     }
     
     [self disableToolbar];
-    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
-        initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissAnimated)
-    ];
-    
     [self reloadData];
 }
 

+ 16 - 1
Classes/ExplorerInterface/Tabs/FLEXTabsViewController.m

@@ -42,7 +42,6 @@
     self.navigationController.hidesBarsOnSwipe = NO;
     self.tableView.allowsMultipleSelectionDuringEditing = YES;
     
-    [FLEXTabList.sharedList updateSnapshotForActiveTab];
     [self reloadData:NO];
 }
 
@@ -51,6 +50,19 @@
     [self setupDefaultBarItems];
 }
 
+- (void)viewDidAppear:(BOOL)animated {
+    [super viewDidAppear:animated];
+    
+    // Instead of updating the active snapshot before we present,
+    // we update it after we present to avoid pre-presenation latency
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [FLEXTabList.sharedList updateSnapshotForActiveTab];
+        [self reloadData:NO];
+        [self.tableView reloadData];
+    });
+}
+
+
 #pragma mark - Private
 
 /// @param trackActiveTabDelta whether to check if the active
@@ -132,6 +144,7 @@
     return presenter;
 }
 
+
 #pragma mark Button Actions
 
 - (void)dismissAnimated {
@@ -237,6 +250,7 @@
     [self.tableView deleteRowsAtIndexPaths:allRows withRowAnimation:UITableViewRowAnimationAutomatic];
 }
 
+
 #pragma mark - Table View Data Source
 
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@@ -267,6 +281,7 @@
     return cell;
 }
 
+
 #pragma mark - Table View Delegate
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

+ 6 - 2
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXTableListViewController.m

@@ -43,16 +43,20 @@
 
     self.showsSearchBar = YES;
     [self getAllTables];
+    
+    // Compose query button //
 
-    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
+    UIBarButtonItem *composeQuery = [[UIBarButtonItem alloc]
         initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
         target:self
         action:@selector(queryButtonPressed)
     ];
     // Cannot run custom queries on realm databases
-    self.navigationItem.rightBarButtonItem.enabled = [self.dbm
+    composeQuery.enabled = [self.dbm
         respondsToSelector:@selector(executeStatement:)
     ];
+    
+    [self addToolbarItems:@[composeQuery]];
 }
     
 - (void)queryButtonPressed {

+ 0 - 4
Classes/GlobalStateExplorers/FLEXLiveObjectsTableViewController.m

@@ -30,10 +30,6 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
 
 @implementation FLEXLiveObjectsTableViewController
 
-- (void)loadView {
-    self.tableView = [FLEXTableView flexDefaultTableView];
-}
-
 - (void)viewDidLoad {
     [super viewDidLoad];
 

+ 24 - 23
Classes/Network/FLEXNetworkMITMViewController.m

@@ -33,29 +33,6 @@
 
 @implementation FLEXNetworkMITMViewController
 
-#pragma mark - Initialization
-
-- (id)init {
-    self = [super initWithStyle:UITableViewStylePlain];
-    if (self) {
-        [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleNewTransactionRecordedNotification:) name:kFLEXNetworkRecorderNewTransactionNotification object:nil];
-        [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleTransactionUpdatedNotification:) name:kFLEXNetworkRecorderTransactionUpdatedNotification object:nil];
-        [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleTransactionsClearedNotification:) name:kFLEXNetworkRecorderTransactionsClearedNotification object:nil];
-        [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(handleNetworkObserverEnabledStateChangedNotification:) name:kFLEXNetworkObserverEnabledStateChangedNotification object:nil];
-        self.title = @"📡  Network";
-        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:@selector(settingsButtonTapped:)];
-
-        // Needed to avoid search bar showing over detail pages pushed on the nav stack
-        // see https://asciiwwdc.com/2014/sessions/228
-        self.definesPresentationContext = YES;
-    }
-    return self;
-}
-
-- (void)dealloc {
-    [NSNotificationCenter.defaultCenter removeObserver:self];
-}
-
 #pragma mark - Lifecycle
 
 - (void)viewDidLoad {
@@ -70,6 +47,7 @@
     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
     self.tableView.rowHeight = [FLEXNetworkTransactionTableViewCell preferredCellHeight];
 
+    [self registerForNotifications];
     [self updateTransactions];
 }
 
@@ -83,6 +61,29 @@
     }
 }
 
+- (void)dealloc {
+    [NSNotificationCenter.defaultCenter removeObserver:self];
+}
+
+- (void)registerForNotifications {
+    NSDictionary *notifications = @{
+        kFLEXNetworkRecorderNewTransactionNotification:
+            NSStringFromSelector(@selector(handleNewTransactionRecordedNotification:)),
+        kFLEXNetworkRecorderTransactionUpdatedNotification:
+            NSStringFromSelector(@selector(handleTransactionUpdatedNotification:)),
+        kFLEXNetworkRecorderTransactionsClearedNotification:
+            NSStringFromSelector(@selector(handleTransactionsClearedNotification:)),
+        kFLEXNetworkObserverEnabledStateChangedNotification:
+            NSStringFromSelector(@selector(handleNetworkObserverEnabledStateChangedNotification:)),
+    };
+    
+    for (NSString *name in notifications.allKeys) {
+        [NSNotificationCenter.defaultCenter addObserver:self
+            selector:NSSelectorFromString(notifications[name]) name:name object:nil
+        ];
+    }
+}
+
 
 #pragma mark - Private
 

+ 3 - 4
Classes/ObjectExplorers/FLEXObjectExplorerViewController.m

@@ -60,7 +60,7 @@
        customSection:(FLEXTableViewSection *)customSection {
     NSParameterAssert(target);
     
-    self = [super init];
+    self = [super initWithStyle:UITableViewStyleGrouped];
     if (self) {
         _object = target;
         _explorer = explorer;
@@ -74,13 +74,12 @@
 #pragma mark - View controller lifecycle
 
 - (void)loadView {
-    FLEXTableView *tableView = [[FLEXTableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
-    self.tableView = tableView;
+    [super loadView];
 
     // Register cell classes
     for (FLEXTableViewSection *section in self.allSections) {
         if (section.cellRegistrationMapping) {
-            [tableView registerCells:section.cellRegistrationMapping];
+            [self.tableView registerCells:section.cellRegistrationMapping];
         }
     }
 }

+ 5 - 1
Classes/Utility/Categories/UIBarButtonItem+FLEX.m

@@ -8,6 +8,8 @@
 
 #import "UIBarButtonItem+FLEX.h"
 
+#pragma clang diagnostic ignored "-Wincomplete-implementation"
+
 @implementation UIBarButtonItem (FLEX)
 
 + (UIBarButtonItem *)flex_flexibleSpace {
@@ -15,7 +17,9 @@
 }
 
 + (UIBarButtonItem *)flex_fixedSpace {
-    return [self systemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
+    UIBarButtonItem *fixed = [self systemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
+    fixed.width = 60;
+    return fixed;
 }
 
 + (instancetype)systemItem:(UIBarButtonSystemItem)item target:(id)target action:(SEL)action {

+ 4 - 2
Classes/ViewHierarchy/FLEXImagePreviewViewController.m

@@ -6,15 +6,17 @@
 //  Copyright (c) 2014 Flipboard. All rights reserved.
 //
 
-#import "FLEXColor.h"
 #import "FLEXImagePreviewViewController.h"
 #import "FLEXUtility.h"
+#import "FLEXColor.h"
+#import "FLEXResources.h"
 
 @interface FLEXImagePreviewViewController () <UIScrollViewDelegate>
 @property (nonatomic) UIImage *image;
 @property (nonatomic) UIScrollView *scrollView;
 @property (nonatomic) UIImageView *imageView;
 @end
+
 #pragma mark -
 @implementation FLEXImagePreviewViewController
 
@@ -51,7 +53,7 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     
-    self.view.backgroundColor = FLEXColor.scrollViewBackgroundColor;
+    self.view.backgroundColor = [UIColor colorWithPatternImage:FLEXResources.checkerPattern];
     
     self.imageView = [[UIImageView alloc] initWithImage:self.image];
     self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];

+ 7 - 0
Classes/ViewHierarchy/TreeExplorer/FLEXHierarchyTableViewController.m

@@ -91,8 +91,15 @@ typedef NS_ENUM(NSUInteger, FLEXHierarchyScope) {
     [self updateDisplayedViews];
 }
 
+- (void)viewWillAppear:(BOOL)animated {
+    [super viewWillAppear:animated];
+    
+    [self disableToolbar];
+}
+
 - (void)viewDidAppear:(BOOL)animated {
     [super viewDidAppear:animated];
+    
     [self trySelectCellForSelectedView];
 }