From c57c3b430491b9a19c71c07a8da1788f250c7594 Mon Sep 17 00:00:00 2001 From: CMK Date: Mon, 18 Apr 2022 10:47:55 +0800 Subject: [PATCH] feat: make adaptive profile card layout on iPad when search tab display as compact column --- .../MastodonUI/View/Content/ProfileCardView.swift | 13 +++++++++++-- .../View/Control/ProfileStatusDashboardView.swift | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView.swift b/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView.swift index eb500b7c..95424b7e 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Content/ProfileCardView.swift @@ -78,6 +78,8 @@ public final class ProfileCardView: UIView { return metaText }() + let infoContainer = UIStackView() + let statusDashboardView = ProfileStatusDashboardView() let relationshipActionButtonShadowContainer = ShadowBackgroundContainer() @@ -206,8 +208,8 @@ extension ProfileCardView { container.setCustomSpacing(16, after: bioMetaTextAdaptiveMarginContainerView) // infoContainer: H - [ statusDashboardView | (spacer) | relationshipActionButton ] - let infoContainer = UIStackView() infoContainer.axis = .horizontal + infoContainer.spacing = 8 let infoContainerAdaptiveMarginContainerView = AdaptiveMarginContainerView() infoContainerAdaptiveMarginContainerView.contentView = infoContainer infoContainerAdaptiveMarginContainerView.margin = ProfileCardView.contentMargin @@ -225,7 +227,7 @@ extension ProfileCardView { relationshipActionButton.trailingAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.trailingAnchor), relationshipActionButton.bottomAnchor.constraint(equalTo: relationshipActionButtonShadowContainer.bottomAnchor), relationshipActionButton.widthAnchor.constraint(greaterThanOrEqualToConstant: ProfileCardView.friendshipActionButtonSize.width).priority(.required - 1), - relationshipActionButton.heightAnchor.constraint(equalToConstant: ProfileCardView.friendshipActionButtonSize.height).priority(.defaultHigh), + relationshipActionButton.heightAnchor.constraint(equalToConstant: ProfileCardView.friendshipActionButtonSize.height).priority(.required - 10), ]) let bottomPadding = UIView() @@ -243,6 +245,13 @@ extension ProfileCardView { viewModel.userInterfaceStyle = traitCollection.userInterfaceStyle } + + public override func layoutSubviews() { + super.layoutSubviews() + + let isCompactAdaptive = bounds.width < 350 + infoContainer.axis = isCompactAdaptive ? .vertical : .horizontal + } } diff --git a/MastodonSDK/Sources/MastodonUI/View/Control/ProfileStatusDashboardView.swift b/MastodonSDK/Sources/MastodonUI/View/Control/ProfileStatusDashboardView.swift index 7d8e4fbc..320c1e90 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Control/ProfileStatusDashboardView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Control/ProfileStatusDashboardView.swift @@ -55,7 +55,7 @@ extension ProfileStatusDashboardView { containerStackView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh), ]) - let spacing: CGFloat = UIView.isZoomedMode ? 4 : 16 + let spacing: CGFloat = UIView.isZoomedMode ? 4 : 12 containerStackView.spacing = spacing containerStackView.axis = .horizontal containerStackView.distribution = .fillEqually