From 06413b26dfca81556c922cd7179eac885007472d Mon Sep 17 00:00:00 2001 From: Michael Starke Date: Wed, 30 Dec 2020 22:27:13 +0100 Subject: [PATCH] Reverted changes for context bar view since the layout was broken --- MacPass/EntryView.xib | 39 +++++++++++----------- MacPass/MPEntryViewController.m | 58 ++++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 25 deletions(-) diff --git a/MacPass/EntryView.xib b/MacPass/EntryView.xib index 792b0846..15367d18 100644 --- a/MacPass/EntryView.xib +++ b/MacPass/EntryView.xib @@ -1,30 +1,31 @@ - + - + - - + + - - - + + + + - + - + - + @@ -240,16 +241,14 @@ - - - - - - - - - - + + + + + + + + diff --git a/MacPass/MPEntryViewController.m b/MacPass/MPEntryViewController.m index 0cec65ac..261cbf6a 100644 --- a/MacPass/MPEntryViewController.m +++ b/MacPass/MPEntryViewController.m @@ -70,16 +70,21 @@ NSString *const _MPTableStringCellView = @"StringCell"; NSString *const _MPTableSecurCellView = @"PasswordCell"; @interface MPEntryViewController () { + BOOL _isDisplayingContextBar; BOOL _didUnlock; } @property (strong) MPContextBarViewController *contextBarViewController; @property (strong) NSArray *filteredEntries; -@property (strong) IBOutlet NSStackView *stackView; @property (weak) IBOutlet NSTableView *entryTable; @property (assign) MPDisplayMode displayMode; + +/* Constraints */ +@property (strong) IBOutlet NSLayoutConstraint *tableToTopConstraint; +@property (strong) NSLayoutConstraint *contextBarTopConstraint; + @property (nonatomic, strong) MPEntryTableDataSource *dataSource; @end @@ -93,6 +98,7 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if(self) { + _isDisplayingContextBar = NO; _displayMode = MPDisplayModeEntries; _entryArrayController = [[NSArrayController alloc] init]; _dataSource = [[MPEntryTableDataSource alloc] init]; @@ -537,14 +543,56 @@ NSString *const _MPTableSecurCellView = @"PasswordCell"; } - (void)_showContextBar { - if(self.stackView.views.count == 1) { - [self.stackView insertArrangedSubview:self.contextBarViewController.view atIndex:0]; + if(_isDisplayingContextBar) { + return; } - self.contextBarViewController.view.hidden = NO; + _isDisplayingContextBar = YES; + if(!self.contextBarViewController.view.superview) { + [self.view addSubview:self.contextBarViewController.view]; + NSView *contextBar = self.contextBarViewController.view; + NSView *scrollView = self.entryTable.enclosingScrollView; + NSDictionary *views = NSDictionaryOfVariableBindings(scrollView, contextBar); + + /* Pin to the left */ + [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[contextBar]|" options:0 metrics:nil views:views]]; + /* Pin height and to top of entry table */ + [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[contextBar(==30)]-0-[scrollView]" options:0 metrics:nil views:views]]; + /* Create the top constraint for the filter bar where we can change the constant instead of removing/adding constraints all the time */ + self.contextBarTopConstraint = [NSLayoutConstraint constraintWithItem:contextBar + attribute:NSLayoutAttributeTop + relatedBy:NSLayoutRelationEqual + toItem:self.view + attribute:NSLayoutAttributeTop + multiplier:1 + constant:-31]; + } + /* Add the view for the first time */ + [self.view removeConstraint:self.tableToTopConstraint]; + [self.view addConstraint:self.contextBarTopConstraint]; + [self.view layout]; + self.contextBarTopConstraint.constant = 0; + + [NSAnimationContext runAnimationGroup:^(NSAnimationContext* context) { + context.duration = STATUS_BAR_ANIMATION_TIME; + context.allowsImplicitAnimation = YES; + [self.view layoutSubtreeIfNeeded]; + } completionHandler:nil]; } - (void)_hideContextBar { - self.contextBarViewController.view.hidden = YES; + if(!_isDisplayingContextBar) { + return; // nothing to do; + } + self.contextBarTopConstraint.constant = -31; + [self.view addConstraint:self.tableToTopConstraint]; + + [NSAnimationContext runAnimationGroup:^(NSAnimationContext* context) { + context.duration = STATUS_BAR_ANIMATION_TIME; + context.allowsImplicitAnimation = YES; + [self.view layoutSubtreeIfNeeded]; + } completionHandler:^{ + self->_isDisplayingContextBar = NO; + }]; } #pragma mark Validation