From ec09b4e165ea5314b72a3a3463ec5b01cad41d89 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 15 May 2024 14:27:56 +0300 Subject: [PATCH] fix widget constraints --- .../Map/OAMapHudViewController.xib | 4 +- .../Controllers/Map/OAMapInfoController.mm | 88 ++---------- .../Map/Widgets/OATextInfoWidget.h | 2 +- .../Map/Widgets/OATextInfoWidget.mm | 130 ++++++++++-------- .../Widgets/OAWidgetPanelViewController.xib | 6 +- .../Widgets/WidgetPageViewController.swift | 10 +- .../Widgets/WidgetPanelViewController.swift | 45 +++--- 7 files changed, 121 insertions(+), 164 deletions(-) diff --git a/Sources/Controllers/Map/OAMapHudViewController.xib b/Sources/Controllers/Map/OAMapHudViewController.xib index d58939c097..08e54707b2 100644 --- a/Sources/Controllers/Map/OAMapHudViewController.xib +++ b/Sources/Controllers/Map/OAMapHudViewController.xib @@ -128,7 +128,7 @@ - + @@ -279,7 +279,7 @@ - + diff --git a/Sources/Controllers/Map/OAMapInfoController.mm b/Sources/Controllers/Map/OAMapInfoController.mm index 4575433cbd..308a92f93f 100644 --- a/Sources/Controllers/Map/OAMapInfoController.mm +++ b/Sources/Controllers/Map/OAMapInfoController.mm @@ -398,13 +398,7 @@ - (void)updateShadowView:(ShadowPathView *)view - (void) layoutWidgets { - BOOL portrait = ![OAUtilities isLandscape]; - BOOL hasTopWidgets = [_topPanelController hasWidgets]; - BOOL hasTopSpecialWidgets = [_topPanelController.specialPanelController hasWidgets]; - BOOL hasLeftWidgets = [_leftPanelController hasWidgets]; - BOOL hasBottomWidgets = [_bottomPanelController hasWidgets]; - BOOL hasRightWidgets = [_rightPanelController hasWidgets]; [self configureLayerWidgets:hasTopWidgets]; if (_alarmControl && _alarmControl.superview && !_alarmControl.hidden) @@ -420,63 +414,15 @@ - (void) layoutWidgets _rulerControl.center = _rulerControl.superview.center; } - _mapHudViewController.topWidgetsViewWidthConstraint.constant = [OAUtilities isLandscapeIpadAware] ? kInfoViewLandscapeWidthPad : DeviceScreenWidth; - - if ((hasTopWidgets || hasTopSpecialWidgets) && _lastUpdateTime == 0) + if ((hasTopWidgets || [_topPanelController.specialPanelController hasWidgets]) && _lastUpdateTime == 0) [[OARootViewController instance].mapPanel updateToolbar]; - if (hasTopWidgets) - { - _mapHudViewController.topWidgetsViewHeightConstraint.constant = [_topPanelController calculateContentSize].height; - _mapHudViewController.topWidgetsView.layer.masksToBounds = NO; - - [self updateShadowView:_topShadowContainerView direction:ShadowPathDirectionBottom]; - } - else - { - _mapHudViewController.topWidgetsViewHeightConstraint.constant = 0.; - _mapHudViewController.topWidgetsView.layer.masksToBounds = YES; - } - - if (hasTopSpecialWidgets) - { - _mapHudViewController.middleWidgetsViewYConstraint.constant = kWidgetsTopPadding; - CGSize specialPanelSize = [_topPanelController.specialPanelController calculateContentSize]; - _mapHudViewController.middleWidgetsViewWidthConstraint.constant = specialPanelSize.width; - _mapHudViewController.middleWidgetsViewHeightConstraint.constant = specialPanelSize.height; - } - else - { - _mapHudViewController.middleWidgetsViewHeightConstraint.constant = 0.; - } - - if (hasLeftWidgets) - { - CGSize leftSize = [_leftPanelController calculateContentSize]; - CGFloat pageControlHeight = _leftPanelController.pages.count > 1 ? 16 : 0; - _mapHudViewController.leftWidgetsViewHeightConstraint.constant = leftSize.height + pageControlHeight + (_leftPanelController.view.layer.borderWidth * 2); - _mapHudViewController.leftWidgetsViewWidthConstraint.constant = leftSize.width; - } - else - { - _mapHudViewController.leftWidgetsViewHeightConstraint.constant = 0.; - _mapHudViewController.leftWidgetsViewWidthConstraint.constant = 0.; - } - - _mapHudViewController.bottomWidgetsViewWidthConstraint.constant = [OAUtilities isLandscapeIpadAware] ? kInfoViewLandscapeWidthPad : DeviceScreenWidth; - if (hasBottomWidgets) - { - _mapHudViewController.bottomWidgetsViewHeightConstraint.constant = [_bottomPanelController calculateContentSize].height; - _mapHudViewController.bottomWidgetsView.layer.masksToBounds = NO; - - [self updateShadowView:_bottomShadowContainerView direction:ShadowPathDirectionTop]; - } - else - { - _mapHudViewController.bottomWidgetsViewHeightConstraint.constant = 0; - _mapHudViewController.bottomWidgetsView.layer.masksToBounds = YES; - } + _mapHudViewController.topWidgetsView.layer.masksToBounds = !hasTopWidgets; + [self updateShadowView:_topShadowContainerView direction:ShadowPathDirectionBottom]; + _mapHudViewController.middleWidgetsViewYConstraint.constant = kWidgetsTopPadding; + _mapHudViewController.bottomWidgetsView.layer.masksToBounds = ![_bottomPanelController hasWidgets]; + [self updateShadowView:_bottomShadowContainerView direction:ShadowPathDirectionTop]; OAMapRendererView *mapView = [OARootViewController instance].mapPanel.mapViewController.mapView; CGFloat topOffset = _mapHudViewController.topWidgetsViewHeightConstraint.constant; @@ -487,30 +433,19 @@ - (void) layoutWidgets bottomOffset += _mapHudViewController.bottomBarViewHeightConstraint.constant; [mapView setTopOffsetOfViewSize:topOffset bottomOffset:bottomOffset]; - if (hasRightWidgets) - { - CGSize rightSize = [_rightPanelController calculateContentSize]; - CGFloat pageControlHeight = _rightPanelController.pages.count > 1 ? 16 : 0; - _mapHudViewController.rightWidgetsViewHeightConstraint.constant = rightSize.height + pageControlHeight + (_rightPanelController.view.layer.borderWidth * 2); - _mapHudViewController.rightWidgetsViewWidthConstraint.constant = rightSize.width; - } - else - { - _mapHudViewController.rightWidgetsViewHeightConstraint.constant = 0.; - _mapHudViewController.rightWidgetsViewWidthConstraint.constant = 0.; - } CGFloat leftRightWidgetsViewTopConstraintConstant = hasTopWidgets ? 1 : 0; if ([OAUtilities isLandscapeIpadAware]) { - if (hasLeftWidgets) + if ([_leftPanelController hasWidgets] || [_rightPanelController hasWidgets]) { leftRightWidgetsViewTopConstraintConstant = _mapHudViewController.topWidgetsViewHeightConstraint.constant > 0 ? -_mapHudViewController.topWidgetsViewHeightConstraint.constant : kWidgetsTopPadding; - } else + } + else { leftRightWidgetsViewTopConstraintConstant = -_mapHudViewController.topWidgetsViewHeightConstraint.constant + 16; } } - + _mapHudViewController.leftWidgetsViewTopConstraint.constant = _mapHudViewController.rightWidgetsViewTopConstraint.constant = leftRightWidgetsViewTopConstraintConstant; @@ -519,7 +454,7 @@ - (void) layoutWidgets if (_lastUpdateTime == 0) [[OARootViewController instance].mapPanel updateToolbar]; - if (portrait) + if (![OAUtilities isLandscape]) { _downloadMapWidget.frame = CGRectMake(0, _mapHudViewController.statusBarView.frame.size.height, DeviceScreenWidth, 155.); } @@ -647,6 +582,7 @@ - (void) recreateControls:(BOOL)registerWidgets [_mapWidgetRegistry updateWidgetsInfo:[[OAAppSettings sharedManager].applicationMode get]]; [self recreateWidgetsPanel:_topPanelController panel:OAWidgetsPanel.topPanel appMode:appMode]; + [_topPanelController.specialPanelController updateWidgetSizes]; [self recreateWidgetsPanel:_bottomPanelController panel:OAWidgetsPanel.bottomPanel appMode:appMode]; [self recreateWidgetsPanel:_leftPanelController panel:OAWidgetsPanel.leftPanel appMode:appMode]; [self recreateWidgetsPanel:_rightPanelController panel:OAWidgetsPanel.rightPanel appMode:appMode]; diff --git a/Sources/Controllers/Map/Widgets/OATextInfoWidget.h b/Sources/Controllers/Map/Widgets/OATextInfoWidget.h index 3e8ea73aaa..8021072072 100644 --- a/Sources/Controllers/Map/Widgets/OATextInfoWidget.h +++ b/Sources/Controllers/Map/Widgets/OATextInfoWidget.h @@ -41,7 +41,7 @@ @property (nonatomic, strong, nullable) UILabel *titleOrEmptyLabel; @property (nonatomic, strong, nullable) UILabel *unitOrEmptyLabel; @property (nonatomic, strong, nullable) UILabel *valueLabel; -@property (nonatomic, strong, nullable) UIView *iconWidgetView; +@property (nonatomic, strong, nullable) UIStackView *iconWidgetStackView; @property (nonatomic) OACommonWidgetSizeStyle *widgetSizePref; @property (strong) BOOL(^updateInfoFunction)(); diff --git a/Sources/Controllers/Map/Widgets/OATextInfoWidget.mm b/Sources/Controllers/Map/Widgets/OATextInfoWidget.mm index 7cff7af2a9..c1b9526c2b 100644 --- a/Sources/Controllers/Map/Widgets/OATextInfoWidget.mm +++ b/Sources/Controllers/Map/Widgets/OATextInfoWidget.mm @@ -134,10 +134,12 @@ - (void)updateSimpleLayout [verticalStackView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:16], [verticalStackView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-16], ]]; - _verticalStackViewSimpleWidgetTopConstraint = [verticalStackView.topAnchor constraintEqualToAnchor:self.topAnchor constant:0]; + + CGFloat topBottomPadding = [OAWidgetSizeStyleObjWrapper getTopBottomPaddingWithType:self.widgetSizeStyle]; + _verticalStackViewSimpleWidgetTopConstraint = [verticalStackView.topAnchor constraintEqualToAnchor:self.topAnchor constant:topBottomPadding]; _verticalStackViewSimpleWidgetTopConstraint.active = YES; - _verticalStackViewSimpleWidgetBottomConstraint = [verticalStackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:0]; + _verticalStackViewSimpleWidgetBottomConstraint = [verticalStackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-topBottomPadding]; _verticalStackViewSimpleWidgetBottomConstraint.active = YES; // Create the topNameUnitStackView @@ -154,9 +156,6 @@ - (void)updateSimpleLayout auto nameView = [UIView new]; nameView.translatesAutoresizingMaskIntoConstraints = NO; [self.topNameUnitStackView addArrangedSubview:nameView]; - [NSLayoutConstraint activateConstraints:@[ - [nameView.heightAnchor constraintGreaterThanOrEqualToConstant:11] - ]]; // Create the name label ("SPEED") self.nameLabel = [UILabel new]; @@ -170,31 +169,28 @@ - (void)updateSimpleLayout [self.nameLabel.trailingAnchor constraintEqualToAnchor:nameView.trailingAnchor], [self.nameLabel.bottomAnchor constraintEqualToAnchor:nameView.bottomAnchor] ]]; - + self.unitView = [UIView new]; self.unitView.translatesAutoresizingMaskIntoConstraints = NO; [self.topNameUnitStackView addArrangedSubview:self.unitView]; - [NSLayoutConstraint activateConstraints:@[ - [self.unitView.heightAnchor constraintGreaterThanOrEqualToConstant:11], - [self.unitView.widthAnchor constraintGreaterThanOrEqualToConstant:15] - ]]; self.unitView.hidden = _subtext.length == 0; - + + CGFloat unitsFontSize = [OAWidgetSizeStyleObjWrapper getUnitsFontSizeForType:self.widgetSizeStyle]; + // Create the unit label ("KM/H") self.unitLabel = [UILabel new]; self.unitLabel.translatesAutoresizingMaskIntoConstraints = NO; - self.unitLabel.font = [UIFont scaledSystemFontOfSize:[OAWidgetSizeStyleObjWrapper getUnitsFontSizeForType:self.widgetSizeStyle] weight:UIFontWeightMedium]; + self.unitLabel.font = [UIFont scaledSystemFontOfSize:unitsFontSize weight:UIFontWeightMedium]; self.unitLabel.textColor = [UIColor colorNamed:ACColorNameWidgetUnitsColor]; [self.unitView addSubview:self.unitLabel]; [NSLayoutConstraint activateConstraints:@[ - [self.unitLabel.topAnchor constraintEqualToAnchor:self.unitView.topAnchor], [self.unitLabel.leadingAnchor constraintEqualToAnchor:self.unitView.leadingAnchor], [self.unitLabel.trailingAnchor constraintEqualToAnchor:self.unitView.trailingAnchor], - [self.unitLabel.bottomAnchor constraintEqualToAnchor:self.unitView.bottomAnchor], + [self.unitLabel.centerYAnchor constraintEqualToAnchor:self.unitView.centerYAnchor], [self.unitLabel.widthAnchor constraintGreaterThanOrEqualToConstant:15] ]]; - + // Create the _contentStackViewSimpleWidget _contentStackViewSimpleWidget = [UIStackView new]; _contentStackViewSimpleWidget.translatesAutoresizingMaskIntoConstraints = NO; @@ -203,32 +199,58 @@ - (void)updateSimpleLayout _contentStackViewSimpleWidget.distribution = UIStackViewDistributionFill; [verticalStackView addArrangedSubview:_contentStackViewSimpleWidget]; - self.iconWidgetView = [UIView new]; - self.iconWidgetView.translatesAutoresizingMaskIntoConstraints = NO; - [_contentStackViewSimpleWidget addArrangedSubview:self.iconWidgetView]; + self.iconWidgetStackView = [UIStackView new]; + self.iconWidgetStackView.translatesAutoresizingMaskIntoConstraints = NO; + self.iconWidgetStackView.axis = UILayoutConstraintAxisVertical; + self.iconWidgetStackView.alignment = UIStackViewAlignmentFill; + self.iconWidgetStackView.distribution = UIStackViewDistributionFill; + + CGFloat valueFontSize = [OAWidgetSizeStyleObjWrapper getValueFontSizeForType:self.widgetSizeStyle]; + self.iconWidgetStackView.spacing = valueFontSize > imageSide ? ((valueFontSize - imageSide) / 2) : 0; + + [_contentStackViewSimpleWidget addArrangedSubview:self.iconWidgetStackView]; + + UIView *topMargin = [UIView new]; + topMargin.backgroundColor = UIColor.clearColor; + topMargin.translatesAutoresizingMaskIntoConstraints = NO; + [NSLayoutConstraint activateConstraints:@[ - [self.iconWidgetView.heightAnchor constraintGreaterThanOrEqualToConstant:30], - [self.iconWidgetView.widthAnchor constraintEqualToConstant:30] + [topMargin.heightAnchor constraintEqualToConstant:0], + [topMargin.widthAnchor constraintEqualToConstant:imageSide], ]]; - + + [self.iconWidgetStackView addArrangedSubview:topMargin]; + _imageView = [UIImageView new]; UIImage *image = [UIImage imageNamed:_icon]; - if (_iconColor) { + if (_iconColor) + { [self setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]]; [_imageView setTintColor:_iconColor]; _iconColor = nil; - } else { + } + else + { [self setImage:image]; } _imageView.translatesAutoresizingMaskIntoConstraints = NO; - [self.iconWidgetView addSubview:_imageView]; [NSLayoutConstraint activateConstraints:@[ - [_imageView.heightAnchor constraintEqualToConstant:30], - [_imageView.widthAnchor constraintEqualToConstant:30], - [_imageView.centerXAnchor constraintEqualToAnchor:self.iconWidgetView.centerXAnchor], - [_imageView.centerYAnchor constraintEqualToAnchor:self.iconWidgetView.centerYAnchor] + [_imageView.widthAnchor constraintEqualToConstant:imageSide] ]]; - + + [self.iconWidgetStackView addArrangedSubview:_imageView]; + + UIView *bottomMargin = [UIView new]; + bottomMargin.backgroundColor = UIColor.clearColor; + bottomMargin.translatesAutoresizingMaskIntoConstraints = NO; + + [NSLayoutConstraint activateConstraints:@[ + [bottomMargin.heightAnchor constraintEqualToConstant:0], + [bottomMargin.widthAnchor constraintEqualToConstant:imageSide], + ]]; + + [self.iconWidgetStackView addArrangedSubview:bottomMargin]; + auto valueUnitOrEmptyView = [UIView new]; valueUnitOrEmptyView.translatesAutoresizingMaskIntoConstraints = NO; [_contentStackViewSimpleWidget addArrangedSubview:valueUnitOrEmptyView]; @@ -239,8 +261,14 @@ - (void)updateSimpleLayout self.valueLabel.adjustsFontSizeToFitWidth = YES; self.valueLabel.minimumScaleFactor = 0.3; self.valueLabel.textColor = [UIColor colorNamed:ACColorNameWidgetValueColor]; + self.valueLabel.font = [UIFont scaledSystemFontOfSize:valueFontSize weight:UIFontWeightSemibold]; [valueUnitOrEmptyView addSubview:self.valueLabel]; - + + [NSLayoutConstraint activateConstraints:@[ + [self.valueLabel.leadingAnchor constraintEqualToAnchor:valueUnitOrEmptyView.leadingAnchor], + [self.valueLabel.centerYAnchor constraintEqualToAnchor:valueUnitOrEmptyView.centerYAnchor] + ]]; + _contentUnitStackViewSimpleWidget = [UIStackView new]; _contentUnitStackViewSimpleWidget.translatesAutoresizingMaskIntoConstraints = NO; _contentUnitStackViewSimpleWidget.axis = UILayoutConstraintAxisVertical; @@ -254,6 +282,7 @@ - (void)updateSimpleLayout self.titleOrEmptyLabel.allowsDefaultTighteningForTruncation = YES; self.titleOrEmptyLabel.textColor = [UIColor colorNamed:ACColorNameWidgetUnitsColor]; self.titleOrEmptyLabel.textAlignment = NSTextAlignmentRight; + self.titleOrEmptyLabel.font = [UIFont scaledSystemFontOfSize:unitsFontSize weight:UIFontWeightMedium]; [_contentUnitStackViewSimpleWidget addArrangedSubview:self.titleOrEmptyLabel]; // Create the unitOrEmptyLabel ("KM/H") @@ -262,17 +291,10 @@ - (void)updateSimpleLayout self.unitOrEmptyLabel.allowsDefaultTighteningForTruncation = YES; self.unitOrEmptyLabel.textColor = [UIColor colorNamed:ACColorNameWidgetUnitsColor]; self.unitOrEmptyLabel.textAlignment = NSTextAlignmentRight; + self.unitOrEmptyLabel.font = [UIFont scaledSystemFontOfSize:unitsFontSize weight:UIFontWeightMedium]; [_contentUnitStackViewSimpleWidget addArrangedSubview:self.unitOrEmptyLabel]; - - [NSLayoutConstraint activateConstraints:@[ - [self.valueLabel.topAnchor constraintEqualToAnchor:valueUnitOrEmptyView.topAnchor], - [self.valueLabel.leadingAnchor constraintEqualToAnchor:valueUnitOrEmptyView.leadingAnchor], - [self.valueLabel.bottomAnchor constraintEqualToAnchor:valueUnitOrEmptyView.bottomAnchor], - [self.valueLabel.heightAnchor constraintGreaterThanOrEqualToConstant:30] - ]]; - + [NSLayoutConstraint activateConstraints:@[ - [_contentUnitStackViewSimpleWidget.centerYAnchor constraintEqualToAnchor:valueUnitOrEmptyView.centerYAnchor], [_contentUnitStackViewSimpleWidget.leadingAnchor constraintEqualToAnchor:self.valueLabel.trailingAnchor constant:3], [_contentUnitStackViewSimpleWidget.trailingAnchor constraintEqualToAnchor:valueUnitOrEmptyView.trailingAnchor], ]]; @@ -285,8 +307,8 @@ - (void)updateSimpleLayout [_contentStackViewSimpleWidget addArrangedSubview:self.emptyViewRightPlaceholderFullRow]; [NSLayoutConstraint activateConstraints:@[ - [self.emptyViewRightPlaceholderFullRow.widthAnchor constraintEqualToAnchor:_imageView.widthAnchor], - [self.emptyViewRightPlaceholderFullRow.heightAnchor constraintGreaterThanOrEqualToConstant:30] + [self.emptyViewRightPlaceholderFullRow.topAnchor constraintEqualToAnchor:_contentStackViewSimpleWidget.topAnchor], + [self.emptyViewRightPlaceholderFullRow.bottomAnchor constraintEqualToAnchor:_contentStackViewSimpleWidget.bottomAnchor] ]]; _shadowButton = [[UIButton alloc] initWithFrame:CGRectZero]; @@ -319,8 +341,7 @@ - (void)commonLayout ]]; [NSLayoutConstraint activateConstraints:@[ - [_textView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-6], - [_textView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-10] + [_textView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor] ]]; self.topTextAnchor = [_textView.topAnchor constraintEqualToAnchor:self.topAnchor constant:5]; self.topTextAnchor.active = YES; @@ -496,10 +517,13 @@ - (void)configureSimpleLayout CGFloat unitsFontSize = [OAWidgetSizeStyleObjWrapper getUnitsFontSizeForType:self.widgetSizeStyle]; CGFloat paddingBetweenIconAdndValue = [OAWidgetSizeStyleObjWrapper getPaddingBetweenIconAdndValueWithType:self.widgetSizeStyle]; + self.iconWidgetStackView.spacing = valueFontSize > imageSide ? ((valueFontSize - imageSide) / 2) : 0; + self.nameLabel.font = [UIFont scaledSystemFontOfSize:labelFontSize weight:UIFontWeightMedium]; self.nameLabel.textColor = _contentTitleColor; - self.valueLabel.font = [UIFont scaledSystemFontOfSize:valueFontSize weight:UIFontWeightSemibold]; self.valueLabel.textColor = _primaryColor; + self.valueLabel.font = [UIFont scaledSystemFontOfSize:valueFontSize weight:UIFontWeightSemibold]; + self.valueLabel.textColor = _primaryColor; self.unitLabel.font = [UIFont scaledSystemFontOfSize:unitsFontSize weight:UIFontWeightMedium]; self.unitLabel.textColor = _unitsColor; @@ -516,13 +540,13 @@ - (void)configureSimpleLayout CGFloat topBottomPadding = [OAWidgetSizeStyleObjWrapper getTopBottomPaddingWithType:self.widgetSizeStyle]; _verticalStackViewSimpleWidgetTopConstraint.constant = topBottomPadding; - _verticalStackViewSimpleWidgetBottomConstraint.constant = -(topBottomPadding - 2); + _verticalStackViewSimpleWidgetBottomConstraint.constant = -topBottomPadding; BOOL isVisibleIcon = false; if (_appMode && _showIconPref) { isVisibleIcon = [_showIconPref get:_appMode]; - self.iconWidgetView.hidden = !isVisibleIcon; + self.iconWidgetStackView.hidden = !isVisibleIcon; _contentStackViewSimpleWidget.spacing = 0; } _shadowButton.accessibilityValue = [self combine:_text subtext:_subtext]; @@ -531,19 +555,20 @@ - (void)configureSimpleLayout self.unitView.hidden = YES; self.unitOrEmptyLabel.text = @""; self.titleOrEmptyLabel.text = @""; - _unitOrEmptyLabelWidthConstraint.constant = 0; + _contentUnitStackViewSimpleWidget.hidden = YES; } else { - _unitOrEmptyLabelWidthConstraint.constant = (self.isFullRow || self.widgetSizeStyle != EOAWidgetSizeStyleSmall) ? 0 : 20; if (self.widgetSizeStyle == EOAWidgetSizeStyleSmall) { self.unitView.hidden = YES; self.titleOrEmptyLabel.text = [_contentTitle upperCase]; self.unitOrEmptyLabel.text = [_subtext upperCase]; + _contentUnitStackViewSimpleWidget.hidden = NO; } else { + _contentUnitStackViewSimpleWidget.hidden = YES; self.titleOrEmptyLabel.text = @""; self.unitOrEmptyLabel.text = @""; self.unitView.hidden = NO; @@ -658,7 +683,7 @@ - (void) adjustViewSize { if (self.isSimpleLayout) return; - CGFloat leadingOffset = _imageView.hidden ? 3 : 39; + CGFloat leadingOffset = _imageView.hidden ? 3 : (imageSide + 6); //9 _leadingTextAnchor.constant = leadingOffset; [_textView sizeToFit]; @@ -667,20 +692,17 @@ - (void) adjustViewSize CGFloat currentWidth = MAX(tf.size.width, _imageView.hidden ? fullTextWidth : minTextWidth); // TODO: need a more flexible solution for OAUtilities.isLandscapeIpadAware (topWidgetsViewWidthConstraint.constant) - CGFloat widthLimit = [[OARootViewController instance].mapPanel hasTopWidget] ? 120 : [UIScreen mainScreen].bounds.size.width / 2 - 40; + CGFloat widthLimit = [[OARootViewController instance].mapPanel hasTopWidget] && [OAUtilities isLandscape] ? 120 : [UIScreen mainScreen].bounds.size.width / 2 - 40; tf.size.width = currentWidth > widthLimit ? widthLimit : currentWidth; CGRect f = self.frame; f.size.width = leadingOffset + tf.size.width + 4 + 10; CGFloat topBottomOffset = 10; CGFloat height = tf.size.height + topBottomOffset; - if (UIScreen.mainScreen.traitCollection.preferredContentSizeCategory <= UIContentSizeCategoryLarge) { + if (UIScreen.mainScreen.traitCollection.preferredContentSizeCategory <= UIContentSizeCategoryLarge) f.size.height = minWidgetHeight; - } else - { f.size.height = height < minWidgetHeight ? minWidgetHeight : height; - } self.frame = f; } diff --git a/Sources/Controllers/Map/Widgets/OAWidgetPanelViewController.xib b/Sources/Controllers/Map/Widgets/OAWidgetPanelViewController.xib index 8a2b5c7a04..223b660a06 100644 --- a/Sources/Controllers/Map/Widgets/OAWidgetPanelViewController.xib +++ b/Sources/Controllers/Map/Widgets/OAWidgetPanelViewController.xib @@ -25,11 +25,11 @@ - + - + @@ -38,7 +38,7 @@ - + diff --git a/Sources/Controllers/Map/Widgets/WidgetPageViewController.swift b/Sources/Controllers/Map/Widgets/WidgetPageViewController.swift index 4df8c071c4..46957a7c75 100644 --- a/Sources/Controllers/Map/Widgets/WidgetPageViewController.swift +++ b/Sources/Controllers/Map/Widgets/WidgetPageViewController.swift @@ -85,7 +85,7 @@ final class WidgetPageViewController: UIViewController { height = fittingSize.height } else { let lastVisibleWidget = widgetViews.last(where: { !$0.isHidden }) - for widget in widgetViews { + for widget in widgetViews where !widget.isHidden { widget.showBottomSeparator(widget != lastVisibleWidget) widget.translatesAutoresizingMaskIntoConstraints = false widget.adjustSize() @@ -95,9 +95,7 @@ final class WidgetPageViewController: UIViewController { rect.size.width = width widget.frame = rect } - if !widget.isHidden { - height += widget.frame.size.height - } + height += widget.frame.size.height if UIScreen.main.traitCollection.preferredContentSizeCategory > .large { widget.updateHeightConstraint(with: NSLayoutConstraint.Relation.greaterThanOrEqual, constant: widget.frame.size.height, priority: .defaultHigh) @@ -160,8 +158,8 @@ extension WidgetPageViewController { } } // show right separator - items.enumerated().forEach { idx, widget in - widget.showRightSeparator(idx != items.count - 1) + visibleWidgets.enumerated().forEach { idx, widget in + widget.showRightSeparator(idx != visibleWidgets.count - 1) } } updateHorizontalSeparatorVisibilityAndBackground(for: stackView.subviews) diff --git a/Sources/Controllers/Map/Widgets/WidgetPanelViewController.swift b/Sources/Controllers/Map/Widgets/WidgetPanelViewController.swift index ed7a295fcc..ed83dd6ae6 100644 --- a/Sources/Controllers/Map/Widgets/WidgetPanelViewController.swift +++ b/Sources/Controllers/Map/Widgets/WidgetPanelViewController.swift @@ -105,7 +105,7 @@ final class WidgetPanelViewController: UIViewController, OAWidgetListener { func calculateContentSize() -> CGSize { var width: CGFloat = 0 - var height: CGFloat = pages.isEmpty ? 0 : Self.contentHeight + var height: CGFloat = 0 if hasWidgets() { for (idx, page) in pages.enumerated() { let widgetSize = (page as? WidgetPageViewController)?.layoutWidgets() ?? (0, 0) @@ -115,6 +115,9 @@ final class WidgetPanelViewController: UIViewController, OAWidgetListener { width = max(width, widgetSize.0) } height = max(height, Self.contentHeight) + if width == 0, isHorizontal { + width = (OAUtilities.isLandscapeIpadAware() ? CGFloat(kInfoViewLandscapeWidthPad) : OAUtilities.calculateScreenWidth()) + } } return CGSize(width: width, height: height) @@ -189,10 +192,8 @@ final class WidgetPanelViewController: UIViewController, OAWidgetListener { func hasWidgets() -> Bool { if !widgetPages.isEmpty { for widgetPage in widgetPages { - for widget in widgetPage { - if !widget.isHidden { - return true - } + for widget in widgetPage where !widget.isHidden { + return true } } } @@ -226,9 +227,7 @@ final class WidgetPanelViewController: UIViewController, OAWidgetListener { pageContainerView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: isHorizontal ? 0 : Self.borderWidth), pageContainerView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: isHorizontal ? 0 : -Self.borderWidth), pageContainerView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: isHorizontal ? 0 : Self.borderWidth), - pageContainerView.bottomAnchor.constraint(equalTo: pageControl.topAnchor), - pageContainerView.widthAnchor.constraint(equalToConstant: 0), - pageContainerView.heightAnchor.constraint(equalToConstant: Self.contentHeight) + pageContainerView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: isHorizontal ? 0 : -Self.borderWidth) ]) // Add the page view controller as a child view controller @@ -257,24 +256,26 @@ final class WidgetPanelViewController: UIViewController, OAWidgetListener { guard UIApplication.shared.mainScene != nil else { return } let contentSize = calculateContentSize() let mapHudViewController = OARootViewController.instance().mapPanel.hudViewController + let frameHeight = 4.0 if self == mapHudViewController?.mapInfoController?.leftPanelController { - mapHudViewController?.leftWidgetsViewWidthConstraint.constant = contentSize.width + let pageHeight = mapHudViewController?.mapInfoController.leftPanelController.pageControlHeightConstraint.constant ?? 0.0 + mapHudViewController?.leftWidgetsViewWidthConstraint.constant = contentSize.width > 0 ? contentSize.width + frameHeight : 0 + mapHudViewController?.leftWidgetsViewHeightConstraint.constant = contentSize.height > 0 + ? contentSize.height + pageHeight + frameHeight : 0 } else if self == mapHudViewController?.mapInfoController?.rightPanelController { - mapHudViewController?.rightWidgetsViewWidthConstraint.constant = contentSize.width + let pageHeight = mapHudViewController?.mapInfoController.rightPanelController.pageControlHeightConstraint.constant ?? 0.0 + mapHudViewController?.rightWidgetsViewWidthConstraint.constant = contentSize.width > 0 ? contentSize.width + frameHeight : 0 + mapHudViewController?.rightWidgetsViewHeightConstraint.constant = contentSize.height > 0 + ? contentSize.height + pageHeight + frameHeight : 0 } else if self == mapHudViewController?.mapInfoController?.topPanelController.specialPanelController { mapHudViewController?.middleWidgetsViewWidthConstraint.constant = contentSize.width mapHudViewController?.middleWidgetsViewHeightConstraint.constant = contentSize.height - } - - // Update the height constraint of the container view - for constraint in pageContainerView.constraints { - if constraint.firstItem === pageContainerView { - if constraint.firstAttribute == .height { - constraint.constant = contentSize.height - } else if constraint.firstAttribute == .width { - constraint.constant = contentSize.width - } - } + } else if self == mapHudViewController?.mapInfoController?.topPanelController { + mapHudViewController?.topWidgetsViewWidthConstraint.constant = contentSize.width + mapHudViewController?.topWidgetsViewHeightConstraint.constant = contentSize.height + } else if self == mapHudViewController?.mapInfoController?.bottomPanelController { + mapHudViewController?.bottomWidgetsViewWidthConstraint.constant = contentSize.width + mapHudViewController?.bottomWidgetsViewHeightConstraint.constant = contentSize.height } view.isHidden = !hasWidgets() view.layoutIfNeeded() @@ -338,7 +339,7 @@ extension WidgetPanelViewController: UIPageViewControllerDelegate { func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { guard completed, let currentVC = pageViewController.viewControllers?.first, - let _ = pages.firstIndex(of: currentVC) else { return } + pages.firstIndex(of: currentVC) != nil else { return } isInTransition = false pageControl.currentPage = currentIndex updateContainerSize()