Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite TwoLineTitleView to use autolayout #1

Merged
merged 38 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7fe5b71
Move currentStyle definition
May 8, 2023
9ae7f3b
Remove "Button" from label/image variable names
May 8, 2023
70e304b
Add 12x12 and 16x16 chevrons
May 8, 2023
8ef9732
Use UIStackViews instead of manual layout
May 9, 2023
d6b2a8d
Use different size images for different title accessories
May 9, 2023
08f4fb4
Fix SwiftLint complaint
May 9, 2023
f38cce6
Make 12x12 and 16x16 chevrons change color properly
May 9, 2023
e73ab5a
Ensure image views maintain their aspect ratios
May 9, 2023
630e80d
Remove layoutSubviews override
May 9, 2023
634f52a
Reenable accessibility stuff in initializer
May 9, 2023
8578899
Initial color settings
May 9, 2023
f5764fa
Remove "TwoLineTitleView in UIStackView" hack
May 9, 2023
a26f008
Fix text highlighting
May 10, 2023
c47b77f
Remove old layout code
May 10, 2023
9c517fe
Remove unneeded titleSpacing method
May 10, 2023
3347772
containerStackView -> containingStackView
May 10, 2023
a96661d
TwoLineTitleView can still be a UIView
May 10, 2023
42479dd
Remove 20x20 chevrons
May 10, 2023
9d639ef
These calls are no longer needed thanks to autolayout
May 10, 2023
ea96c43
Remove some unneeded variables
May 10, 2023
d63c26b
Ensure 44x44 minimum
May 10, 2023
1e67580
Consolidate comments
May 10, 2023
06b9c2d
Remove unnecessary variable
May 10, 2023
1e8a82b
Fix SwiftLint complaint
May 10, 2023
0e8e5cf
Define minimumTouchSize in one place
May 10, 2023
d40437f
titleLineStackView -> makeEmptyTitleLineStackView
May 10, 2023
8d34269
Revert "Revert #1699"
May 10, 2023
2b1b1bd
Resolve yet another complaint from SwiftLint
May 10, 2023
c3b2720
EasyTapButton.minimumTouchSize doesn't need to be public
May 10, 2023
537bca6
Fix TwoLineTitleView bottom sheets in demo app
May 10, 2023
21ca0da
Edit TwoLineTitleView.resources.xcfilelist
May 10, 2023
bbbb056
Group NSLayoutConstraints together
May 10, 2023
24ee01c
Revert "Group NSLayoutConstraints together"
May 10, 2023
90ccf85
Use a single boolean flag for accessory image size
May 10, 2023
d871873
Another SwiftLint warning
May 10, 2023
344179c
Build container stack views at init time (this saves on binary size)
May 10, 2023
f14a5e8
Add view hierarchy
May 11, 2023
130fd35
Revert "Revert "Group NSLayoutConstraints together""
May 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import UIKit

class TwoLineTitleViewDemoController: DemoController {
private typealias UINavigationItemModifier = (UINavigationItem) -> Void
private typealias TwoLineTitleViewFactory = () -> TwoLineTitleView
private typealias TwoLineTitleViewFactory = (_ forBottomSheet: Bool) -> TwoLineTitleView

private static func createDemoTitleView() -> TwoLineTitleView {
private static func createDemoTitleView(forBottomSheet: Bool) -> TwoLineTitleView {
let twoLineTitleView = TwoLineTitleView()

// Give it a visible margin so we can confirm it centers properly
twoLineTitleView.widthAnchor.constraint(equalToConstant: 200).isActive = true
twoLineTitleView.layer.borderWidth = GlobalTokens.stroke(.width10)
twoLineTitleView.layer.borderColor = GlobalTokens.neutralColor(.grey50).cgColor
if !forBottomSheet {
// Give it a visible margin so we can confirm it centers properly
twoLineTitleView.widthAnchor.constraint(equalToConstant: 200).isActive = true
twoLineTitleView.layer.borderWidth = GlobalTokens.stroke(.width10)
twoLineTitleView.layer.borderColor = GlobalTokens.neutralColor(.grey50).cgColor
}

return twoLineTitleView
}
Expand All @@ -30,7 +32,7 @@ class TwoLineTitleViewDemoController: DemoController {
animatesWhenPressed: Bool = true,
accessoryType: TwoLineTitleView.AccessoryType = .none) -> TwoLineTitleViewFactory {
return {
let twoLineTitleView = createDemoTitleView()
let twoLineTitleView = createDemoTitleView(forBottomSheet: $0)
twoLineTitleView.setup(title: title,
titleImage: titleImage,
subtitle: subtitle,
Expand All @@ -48,17 +50,6 @@ class TwoLineTitleViewDemoController: DemoController {
return navigationItem
}

private static func makeNavigationTitleView(_ navigationItemModifier: UINavigationItemModifier) -> TwoLineTitleView {
let twoLineTitleView = createDemoTitleView()

let aNavigationItem = UINavigationItem()
navigationItemModifier(aNavigationItem)

twoLineTitleView.setup(navigationItem: aNavigationItem)

return twoLineTitleView
}

private let exampleSetupFactories: [TwoLineTitleViewFactory] = [
makeStandardTitleView(title: "Title here", subtitle: "Optional subtitle", animatesWhenPressed: false),
makeStandardTitleView(title: "Custom image", titleImage: UIImage(named: "ic_fluent_star_16_regular"), animatesWhenPressed: false),
Expand Down Expand Up @@ -102,7 +93,7 @@ class TwoLineTitleViewDemoController: DemoController {
addTitle(text: "Made by calling TwoLineTitleView.setup(...)")
exampleSetupFactories.enumerated().forEach {
(offset, element) in
let twoLineTitleView = element()
let twoLineTitleView = element(false)
allExamples.append(twoLineTitleView)

let button = Button()
Expand All @@ -116,7 +107,7 @@ class TwoLineTitleViewDemoController: DemoController {
addTitle(text: "Made from UINavigationItem")
exampleNavigationItems.enumerated().forEach {
(offset, navigationItem) in
let twoLineTitleView = Self.createDemoTitleView()
let twoLineTitleView = Self.createDemoTitleView(forBottomSheet: false)
twoLineTitleView.setup(navigationItem: navigationItem)
allExamples.append(twoLineTitleView)

Expand All @@ -136,7 +127,7 @@ class TwoLineTitleViewDemoController: DemoController {
}

@objc private func setupButtonWasTapped(sender: UIButton) {
let titleView = exampleSetupFactories[sender.tag]()
let titleView = exampleSetupFactories[sender.tag](true)
showBottomSheet(with: titleView)
}

Expand All @@ -147,6 +138,7 @@ class TwoLineTitleViewDemoController: DemoController {
// There can be multiple of these on screen at the same time. All the currently presented transient sheets
// are tracked in presentedTransientSheets.
let secondarySheetController = BottomSheetController(headerContentView: titleView, expandedContentView: sheetContentView)
secondarySheetController.headerContentHeight = 44
secondarySheetController.collapsedContentHeight = 100
secondarySheetController.isHidden = true
secondarySheetController.shouldAlwaysFillWidth = false
Expand Down
4 changes: 3 additions & 1 deletion ios/FluentUI/EasyTapButton/EasyTapButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import UIKit

@objc(MSFEasyTapButton)
open class EasyTapButton: UIButton {
var minTapTargetSize = CGSize(width: 44.0, height: 44.0)
static let minimumTouchSize = CGSize(width: 44, height: 44)

var minTapTargetSize: CGSize = minimumTouchSize

open override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
let growX = max(0, (minTapTargetSize.width - bounds.size.width) / 2)
Expand Down
33 changes: 17 additions & 16 deletions ios/FluentUI/Label/Label.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import UIKit
open class Label: UILabel, TokenizedControlInternal {
@objc open var colorStyle: TextColorStyle = .regular {
didSet {
labelTextColor = nil
updateTextColor()
}
}

@objc open var style: AliasTokens.TypographyTokens {
get {
return AliasTokens.TypographyTokens(rawValue: textStyle.rawValue)!
Expand All @@ -24,9 +24,9 @@ open class Label: UILabel, TokenizedControlInternal {
self.textStyle = FluentTheme.TypographyToken(rawValue: newValue.rawValue)!
}
}

@objc open var textStyle: FluentTheme.TypographyToken = .body1 {
didSet {
labelFont = nil
updateFont()
}
}
Expand All @@ -43,16 +43,20 @@ open class Label: UILabel, TokenizedControlInternal {
}

open override var textColor: UIColor! {
didSet {
labelTextColor = textColor
updateTextColor()
get {
return tokenSet[.textColor].uiColor
}
set {
tokenSet[.textColor] = .uiColor { newValue }
}
}

open override var font: UIFont! {
didSet {
labelFont = font
updateFont()
get {
return tokenSet[.font].uiFont
amgleitman marked this conversation as resolved.
Show resolved Hide resolved
}
set {
tokenSet[.font] = .uiFont { newValue }
}
}

Expand Down Expand Up @@ -103,9 +107,9 @@ open class Label: UILabel, TokenizedControlInternal {
}

private func initialize() {
// textColor and font are assigned in super.init to a default value and so we need to reset our cache afterwards
labelTextColor = nil
labelFont = nil
// textColor and font in the tokenSet are assigned in super.init to a default value and so we need to remove the override
tokenSet.removeOverride(.textColor)
tokenSet.removeOverride(.font)

updateFont()
updateTextColor()
Expand All @@ -129,7 +133,7 @@ open class Label: UILabel, TokenizedControlInternal {
return
}

let labelFont = labelFont ?? tokenSet[.font].uiFont
let labelFont = tokenSet[.font].uiFont
if maxFontSize > 0 && labelFont.pointSize > maxFontSize {
super.font = labelFont.withSize(maxFontSize)
} else {
Expand All @@ -142,17 +146,14 @@ open class Label: UILabel, TokenizedControlInternal {
guard !isUsingCustomAttributedText else {
return
}
super.textColor = labelTextColor ?? tokenSet[.textColor].uiColor
super.textColor = tokenSet[.textColor].uiColor
}

@objc private func handleContentSizeCategoryDidChange() {
if adjustsFontForContentSizeCategory {
labelFont = nil
updateFont()
}
}

private var labelTextColor: UIColor?
private var labelFont: UIFont?
private var isUsingCustomAttributedText: Bool = false
}
4 changes: 1 addition & 3 deletions ios/FluentUI/Navigation/NavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -855,9 +855,7 @@ open class NavigationBar: UINavigationBar, TokenizedControlInternal, TwoLineTitl
customTitleView.delegate = self
}

// For the time being, we need to embed the TwoLineTitleView inside a UIStackView
// in order to make its labels resize properly according to content size changes.
navigationItem.titleView = UIStackView(arrangedSubviews: [customTitleView])
navigationItem.titleView = customTitleView
}

// MARK: Content expansion/contraction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "ic_fluent_chevron_down_12_filled.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "ic_fluent_chevron_down_16_filled.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"images" : [
{
"filename" : "ic_fluent_chevron_right_12_filled.pdf",
"idiom" : "universal",
"filename" : "ic_chevron_right_20_outlined.pdf",
"language-direction" : "left-to-right"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"images" : [
{
"filename" : "ic_fluent_chevron_right_16_filled.pdf",
"idiom" : "universal",
"filename" : "ic_chevron_down_20_outlined.pdf"
"language-direction" : "left-to-right"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
}
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
chevron-down-20x20.imageset
chevron-right-20x20.imageset
chevron-down-12x12.imageset
chevron-down-16x16.imageset
chevron-right-12x12.imageset
chevron-right-16x16.imageset
Loading