Skip to content

Commit

Permalink
Drop support for iOS 14 and remove availability checks (#1357)
Browse files Browse the repository at this point in the history
* Update FluentUI project

* Update FluentUI xcconfig

* Update FluentUI.Demo project

* Update MicrosoftFluentUI.podspec

* Clean up Button

* Clean up CommandBarButton

* Clean up CommandBarButtonGroupView

* Clean up LargeContentViewerModifier

* Clean up Drawer

* Clean up NavigationBar

* Clean up BadgeLabelButton

* Clean up PillButton

* Clean up PillButtonBar

* Clean up SegmentedPillButton

* Clean up SideTabBar

* Clean up TabBarView

* Clean up PillButton v2

* Clean up PillButton v3

* Revert "Update FluentUI project"

This reverts commit 1c97631.

* Update README.md

* Update Package.swift
  • Loading branch information
huwilkes committed Nov 12, 2022
1 parent 43c3a80 commit 4fad398
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 344 deletions.
2 changes: 1 addition & 1 deletion MicrosoftFluentUI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Pod::Spec.new do |s|

# iOS

s.ios.deployment_target = "14.0"
s.ios.deployment_target = "15.0"

s.subspec 'Avatar_ios' do |avatar_ios|
avatar_ios.platform = :ios
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let package = Package(
name: "FluentUI",
defaultLocalization: "en",
platforms: [
.iOS(.v14),
.iOS(.v15),
.macOS(.v10_15),
],
products: [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Fluent UI Apple contains native UIKit and AppKit controls aligned with [Microsof

#### Requirements

- iOS 14+ or macOS 10.15+
- iOS 15+ or macOS 10.15+
- Xcode 14+
- Swift 5.7+

Expand Down
6 changes: 3 additions & 3 deletions ios/FluentUI.Demo/FluentUI.Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DOGFOOD;
Expand Down Expand Up @@ -757,7 +757,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -815,7 +815,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
Expand Down
77 changes: 13 additions & 64 deletions ios/FluentUI/Button/Button.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,9 @@ open class Button: UIButton {
adjustCustomContentEdgeInsetsForImage()
}

if #available(iOS 15.0, *) {
var configuration = self.configuration ?? UIButton.Configuration.plain()
configuration.contentInsets = edgeInsets
self.configuration = configuration
} else {
let left: CGFloat
let right: CGFloat
if effectiveUserInterfaceLayoutDirection == .leftToRight {
left = edgeInsets.leading
right = edgeInsets.trailing
} else {
left = edgeInsets.trailing
right = edgeInsets.leading
}
contentEdgeInsets = UIEdgeInsets(top: edgeInsets.top, left: left, bottom: edgeInsets.bottom, right: right)
}
var configuration = self.configuration ?? UIButton.Configuration.plain()
configuration.contentInsets = edgeInsets
self.configuration = configuration
}
}

Expand All @@ -188,41 +175,15 @@ open class Button: UIButton {

if let image = image(for: .normal) {
size.width += image.size.width
if #available(iOS 15.0, *) {
size.width += style.titleImagePadding
}

if titleLabel?.text?.count ?? 0 == 0 {
size.width -= style.titleImagePadding
if titleLabel?.text?.count ?? 0 > 0 {
size.width += style.titleImagePadding
}
}

return size
}

open override func imageRect(forContentRect contentRect: CGRect) -> CGRect {
var rect = CGRect.zero
if #available(iOS 15, *) {
assertionFailure("imageRect(forContentRect: ) has been deprecated in iOS 15.0")
} else {
rect = super.imageRect(forContentRect: contentRect)

if let image = image {
let imageHeight = image.size.height

// If the entire image doesn't fit in the default rect, increase the rect's height
// to fit the entire image and reposition the origin to keep the image centered.
if imageHeight > rect.size.height {
rect.origin.y -= round((imageHeight - rect.size.height) / 2.0)
rect.size.height = imageHeight
}

rect.size.width = image.size.width
}
}
return rect
}

@objc public init(style: ButtonStyle = .secondaryOutline) {
self.style = style
super.init(frame: .zero)
Expand All @@ -246,11 +207,10 @@ open class Button: UIButton {
titleLabel?.font = style.titleFont
titleLabel?.adjustsFontForContentSizeCategory = true

if #available(iOS 15, *) {
var configuration = UIButton.Configuration.plain()
configuration.contentInsets = edgeInsets
self.configuration = configuration
}
var configuration = UIButton.Configuration.plain()
configuration.contentInsets = edgeInsets
self.configuration = configuration

update()
}

Expand Down Expand Up @@ -415,21 +375,10 @@ open class Button: UIButton {
spacing = -spacing
}

if #available(iOS 15.0, *) {
var configuration = self.configuration ?? UIButton.Configuration.plain()
configuration.contentInsets = edgeInsets
configuration.imagePadding = spacing
self.configuration = configuration
} else {
edgeInsets.trailing += spacing
if effectiveUserInterfaceLayoutDirection == .leftToRight {
titleEdgeInsets.left += spacing
titleEdgeInsets.right -= spacing
} else {
titleEdgeInsets.right += spacing
titleEdgeInsets.left -= spacing
}
}
var configuration = self.configuration ?? UIButton.Configuration.plain()
configuration.contentInsets = edgeInsets
configuration.imagePadding = spacing
self.configuration = configuration

isAdjustingCustomContentEdgeInsetsForImage = false
}
Expand Down
46 changes: 15 additions & 31 deletions ios/FluentUI/Command Bar/CommandBarButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,11 @@ class CommandBarButton: UIButton {
/// Disable accessiblity for the button so that the custom view can provide itself or its subviews as the accessilbity element(s)
isAccessibilityElement = false
} else {
if #available(iOS 15.0, *) {
var buttonConfiguration = UIButton.Configuration.plain()
buttonConfiguration.image = item.iconImage
buttonConfiguration.contentInsets = LayoutConstants.contentInsets
buttonConfiguration.background.cornerRadius = 0
configuration = buttonConfiguration
} else {
setImage(item.iconImage, for: .normal)
contentEdgeInsets = LayoutConstants.contentEdgeInsets
}
var buttonConfiguration = UIButton.Configuration.plain()
buttonConfiguration.image = item.iconImage
buttonConfiguration.contentInsets = LayoutConstants.contentInsets
buttonConfiguration.background.cornerRadius = 0
configuration = buttonConfiguration

let accessibilityDescription = item.accessibilityLabel
accessibilityLabel = (accessibilityDescription != nil) ? accessibilityDescription : item.title
Expand Down Expand Up @@ -94,18 +89,12 @@ class CommandBarButton: UIButton {
let title = item.title
let accessibilityDescription = item.accessibilityLabel

if #available(iOS 15.0, *) {
configuration?.image = iconImage
configuration?.title = iconImage != nil ? nil : title
configuration?.image = iconImage
configuration?.title = iconImage != nil ? nil : title

if let font = item.titleFont {
let attributeContainer = AttributeContainer([NSAttributedString.Key.font: font])
configuration?.attributedTitle?.setAttributes(attributeContainer)
}
} else {
setImage(iconImage, for: .normal)
setTitle(iconImage != nil ? nil : title, for: .normal)
titleLabel?.font = item.titleFont
if let font = item.titleFont {
let attributeContainer = AttributeContainer([NSAttributedString.Key.font: font])
configuration?.attributedTitle?.setAttributes(attributeContainer)
}

updateAccentImage(item.accentImage)
Expand Down Expand Up @@ -171,10 +160,9 @@ class CommandBarButton: UIButton {
}

private func updateStyle() {
// TODO: Once iOS 14 support is dropped, this should be converted to a constant (let) that will be initialized by the logic below.
var resolvedBackgroundColor: UIColor = .clear
let resolvedTintColor: UIColor = isSelected ? selectedTintColor : ColorConstants.normalTintColor

let resolvedBackgroundColor: UIColor
if isPersistSelection {
if isSelected {
resolvedBackgroundColor = selectedBackgroundColor
Expand All @@ -183,16 +171,12 @@ class CommandBarButton: UIButton {
} else {
resolvedBackgroundColor = ColorConstants.normalBackgroundColor
}
}

tintColor = resolvedTintColor
if #available(iOS 15.0, *) {
configuration?.baseForegroundColor = resolvedTintColor
configuration?.background.backgroundColor = resolvedBackgroundColor
} else {
backgroundColor = resolvedBackgroundColor
setTitleColor(tintColor, for: .normal)
resolvedBackgroundColor = .clear
}

configuration?.baseForegroundColor = resolvedTintColor
configuration?.background.backgroundColor = resolvedBackgroundColor
}

private func addCustomView(_ view: UIView) {
Expand Down
9 changes: 2 additions & 7 deletions ios/FluentUI/Command Bar/CommandBarButtonGroupView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,8 @@ class CommandBarButtonGroupView: UIView {
}

private func applyInsets() {
if #available(iOS 15.0, *) {
buttons.first?.configuration?.contentInsets.leading += LayoutConstants.leftRightBuffer
buttons.last?.configuration?.contentInsets.trailing += LayoutConstants.leftRightBuffer
} else {
buttons.first?.contentEdgeInsets.left += LayoutConstants.leftRightBuffer
buttons.last?.contentEdgeInsets.right += LayoutConstants.leftRightBuffer
}
buttons.first?.configuration?.contentInsets.leading += LayoutConstants.leftRightBuffer
buttons.last?.configuration?.contentInsets.trailing += LayoutConstants.leftRightBuffer
}

private struct LayoutConstants {
Expand Down
24 changes: 10 additions & 14 deletions ios/FluentUI/Core/SwiftUI+ViewModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,17 @@ struct LargeContentViewerModifier: ViewModifier {
}

func body(content: Content) -> some View {
if #available(iOS 15.0, *) {
if text != nil || image != nil {
content.accessibilityShowsLargeContentViewer({
if let image = image {
Image(uiImage: image)
}
if let text = text {
Text(text)
}
})
} else {
content.accessibilityShowsLargeContentViewer()
}
if text != nil || image != nil {
content.accessibilityShowsLargeContentViewer({
if let image = image {
Image(uiImage: image)
}
if let text = text {
Text(text)
}
})
} else {
content
content.accessibilityShowsLargeContentViewer()
}
}

Expand Down
18 changes: 0 additions & 18 deletions ios/FluentUI/Drawer/DrawerPresentationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -293,24 +293,6 @@ class DrawerPresentationController: UIPresentationController {

if let presentedView = presentedView {
let presentedViewFrame = frameForPresentedViewController(in: presentedView.superview == containerView ? contentView.frame : contentView.bounds)

// On iOS 13 and iOS 14 the safeAreaInsets are not applied when the presentedView is not entirely within the screen bounds.
// As a workaround, additional safe area insets need to be set to compensate.
if #available(iOS 15.0, *) {} else {
let isVerticallyPresentedViewPartiallyOffScreen: Bool = {
// Calculates the origin of the presentedView frame in relation to the device screen.
guard let origin = presentedView.superview?.convert(presentedViewFrame.origin, to: nil), let window = sourceViewController.view.window else {
return false
}

let screenHeight = window.screen.bounds.height
return (presentationDirection == .down && origin.y < 0) ||
(presentationDirection == .up && (origin.y + presentedViewFrame.height - screenHeight) > 0)
}()

presentedViewController.additionalSafeAreaInsets = isVerticallyPresentedViewPartiallyOffScreen ? contentView.safeAreaInsets : .zero
}

presentedView.frame = presentedViewFrame
}

Expand Down
25 changes: 6 additions & 19 deletions ios/FluentUI/Navigation/BadgeLabelButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class BadgeLabelButton: UIButton {

super.init(frame: frame)

if #available(iOS 15.0, *) {
configuration = UIButton.Configuration.plain()
}
configuration = UIButton.Configuration.plain()

NotificationCenter.default.addObserver(self,
selector: #selector(badgeValueDidChange),
Expand Down Expand Up @@ -69,15 +67,9 @@ class BadgeLabelButton: UIButton {

private var badgeFrameOriginX: CGFloat {
let xOrigin: CGFloat = {
if #available(iOS 15.0, *) {
return isLeftToRightUserInterfaceLayoutDirection ?
frame.size.width - (configuration?.contentInsets.leading ?? 0) :
configuration?.contentInsets.trailing ?? 0
} else {
return isLeftToRightUserInterfaceLayoutDirection ?
frame.size.width - contentEdgeInsets.left :
contentEdgeInsets.left
}
return isLeftToRightUserInterfaceLayoutDirection ?
frame.size.width - (configuration?.contentInsets.leading ?? 0) :
configuration?.contentInsets.trailing ?? 0
}()

return (xOrigin - badgeWidth / 2)
Expand Down Expand Up @@ -128,13 +120,8 @@ class BadgeLabelButton: UIButton {
landscapeImage = landscapeImage?.withRenderingMode(.alwaysTemplate)
}

if #available(iOS 15.0, *) {
configuration?.image = traitCollection.verticalSizeClass == .regular ? portraitImage : landscapeImage
configuration?.title = item.title
} else {
setImage(traitCollection.verticalSizeClass == .regular ? portraitImage : landscapeImage, for: .normal)
setTitle(item.title, for: .normal)
}
configuration?.image = traitCollection.verticalSizeClass == .regular ? portraitImage : landscapeImage
configuration?.title = item.title

if let action = item.action {
addTarget(item.target, action: action, for: .touchUpInside)
Expand Down
Loading

0 comments on commit 4fad398

Please sign in to comment.