-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix FXIOS-7985 [v122] Display 3 lines of title for ads (#17819)
* Restrict lines of title for LinkButton * Update colors like in other button * Add comments * Restrict number of lines for ad link * Add FakespotAdLinkButton * Use new button * Remove new code * Simplify code (cherry picked from commit aba3d15)
- Loading branch information
1 parent
9e6548f
commit 4af4dc4
Showing
4 changed files
with
91 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/ | ||
|
||
import UIKit | ||
import ComponentLibrary | ||
|
||
class FakespotAdLinkButton: LinkButton { | ||
private struct UX { | ||
static let numberOfLines: Int = 3 | ||
} | ||
|
||
private var previousFrame: CGRect = .zero | ||
|
||
override public var frame: CGRect { | ||
didSet { | ||
guard previousFrame != frame else { return } | ||
|
||
previousFrame = frame | ||
invalidateIntrinsicContentSize() | ||
} | ||
} | ||
|
||
override public func configure(viewModel: LinkButtonViewModel) { | ||
super.configure(viewModel: viewModel) | ||
|
||
guard let config = configuration else { | ||
return | ||
} | ||
|
||
var updatedConfiguration = config | ||
updatedConfiguration.titleLineBreakMode = .byTruncatingTail | ||
|
||
configuration = updatedConfiguration | ||
layoutIfNeeded() | ||
} | ||
|
||
override public func layoutSubviews() { | ||
super.layoutSubviews() | ||
|
||
guard let titleLabel else { return } | ||
|
||
// hack to be able to restrict the number of lines displayed | ||
titleLabel.numberOfLines = UX.numberOfLines | ||
sizeToFit() | ||
} | ||
|
||
override public var intrinsicContentSize: CGSize { | ||
guard let title = titleLabel, | ||
let configuration | ||
else { | ||
return super.intrinsicContentSize | ||
} | ||
|
||
let widthContentInset = configuration.contentInsets.leading + configuration.contentInsets.trailing | ||
let heightContentInset = configuration.contentInsets.top + configuration.contentInsets.bottom | ||
|
||
let availableWidth = frame.width - widthContentInset | ||
let size = title.sizeThatFits(CGSize(width: availableWidth, height: .greatestFiniteMagnitude)) | ||
|
||
return CGSize(width: size.width + widthContentInset, | ||
height: size.height + heightContentInset) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters