Merge branch 'bugfix/size_calculation' into 'develop'

Calculation of size fix

See merge request BPHV_MIPS/mvm_core_ui!112
This commit is contained in:
Pfeil, Scott Robert 2019-08-13 09:35:04 -04:00
commit 18c916eba0
3 changed files with 22 additions and 13 deletions

View File

@ -28,11 +28,11 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
MFStyler.setDefaultMarginsFor(contentView, size: width)
if let topView = topView as? MVMCoreViewProtocol {
topView.updateView(width)
showHeader()
showHeader(width)
}
if let bottomView = bottomView as? MVMCoreViewProtocol {
bottomView.updateView(width)
showFooter()
showFooter(width)
}
self.tableView?.reloadData()
}
@ -102,14 +102,15 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
currentSpaceForCompare = currentSpace * 2;
}
let width = view.bounds.width
if !MVMCoreGetterUtility.cgfequalwiththreshold(newSpace, currentSpaceForCompare, 0.1) {
if fillTop && fillBottom {
// space both
let half = newSpace / 2
topViewBottomConstraint?.constant = half
bottomViewTopConstraint?.constant = half
showHeader()
showFooter()
showHeader(width)
showFooter(width)
} else if fillTop {
// Only top is spaced (half the size if the bottom view is out of the scroll because it needs to be sized as if there are two spacers but there is only one.
if bottomViewOutsideOfScrollArea {
@ -117,11 +118,11 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
} else {
topViewBottomConstraint?.constant = newSpace
}
showHeader()
showHeader(width)
} else if fillBottom {
// Only bottom is spaced.
bottomViewTopConstraint?.constant = newSpace
showFooter()
showFooter(width)
}
}
}
@ -140,7 +141,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
topViewBottomConstraint = headerView.bottomAnchor.constraint(equalTo: topView.bottomAnchor, constant: spaceBelowTopView() ?? 0)
topViewBottomConstraint?.isActive = true
self.headerView = headerView
showHeader()
showHeader(nil)
}
/// Gets the bottom view and adds it to a spacing view, footerView, and then calls showFooter.
@ -156,11 +157,11 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
footerView.rightAnchor.constraint(equalTo: bottomView.rightAnchor).isActive = true
footerView.bottomAnchor.constraint(equalTo: bottomView.bottomAnchor).isActive = true
self.footerView = footerView
showFooter()
showFooter(nil)
}
/// Takes the current headerView and adds it to the tableHeaderView
func showHeader() {
func showHeader(_ sizingWidth: CGFloat?) {
headerView?.removeFromSuperview()
tableView?.tableHeaderView = nil
guard let headerView = headerView else {
@ -176,7 +177,7 @@ open class ThreeLayerTableViewController: MFProgrammaticTableViewController {
}
/// Takes the current footerView and adds it to the tableFooterView
func showFooter() {
func showFooter(_ sizingWidth: CGFloat?) {
footerView?.removeFromSuperview()
safeAreaView?.removeFromSuperview()
guard let footerView = footerView, let tableView = tableView else {

View File

@ -71,8 +71,9 @@ NS_ASSUME_NONNULL_BEGIN
// Gets the constraint height to be whatever space is left in the scroll view.
+ (CGFloat)getVariableConstraintHeight:(CGFloat)currentConstant inScrollView:(nonnull UIScrollView *)scrollView minimumHeight:(CGFloat)minimumHeight;
// Sets the view's frame according to constraint.
/// Sets the view's frame according to constraints.
+ (void)sizeViewToFit:(nullable UIView *)view;
+ (void)sizeViewToFit:(UIView *)view forWidth:(nullable NSNumber *)width;
#pragma mark - Keyboard

View File

@ -119,7 +119,7 @@
#pragma mark - Sizing
+ (CGFloat)getWidth {
UIViewController *controller = [MVMCoreUISession sharedGlobal].splitViewController ?: [MVMCoreUISession sharedGlobal].navigationController ?: [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *controller = [MVMCoreUISession sharedGlobal].splitViewController ?: [MVMCoreUISession sharedGlobal].navigationController;
if (controller) {
return CGRectGetWidth(controller.view.bounds);
} else {
@ -138,7 +138,7 @@
}
+ (CGFloat)getHeightOfView:(nonnull UIView *)view forWidth:(nullable NSNumber *)width {
CGFloat floatWidth = (width ? width.floatValue : CGRectGetWidth([MVMCoreNavigationHandler sharedNavigationHandler].navigationController.view.bounds));
CGFloat floatWidth = (width ? width.floatValue : [MVMCoreUIUtility getWidth]);
return [view systemLayoutSizeFittingSize:CGSizeMake(floatWidth, UILayoutFittingCompressedSize.height) withHorizontalFittingPriority:1000 verticalFittingPriority:250].height;
}
@ -192,6 +192,13 @@
view.frame = frame;
}
+ (void)sizeViewToFit:(UIView *)view forWidth:(nullable NSNumber *)width {
CGFloat height = [MVMCoreUIUtility getHeightOfView:view forWidth:width];
CGRect frame = view.frame;
frame.size.height = height;
view.frame = frame;
}
#pragma mark - Keyboard
+ (void)setScrollViewInsetForKeyboardShow:(nonnull NSNotification *)notification scrollView:(nonnull UIScrollView *)scrollView viewController:(nonnull UIViewController *)viewController rectToScrollTo:(nonnull CGRect (^)(void))rectToScrollTo {