Skip to content

Commit

Permalink
SafetyElement: Add property emphasizedBody (#1381)
Browse files Browse the repository at this point in the history
* SafetyElementViewModel: Add property emphasizedBody

* ElementContentView: Add label to content

* ElementContentView: Minor cleanup

* Add to snapshot test
  • Loading branch information
bstien authored Sep 23, 2024
1 parent ece2b24 commit 5d3c8d6
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 19 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ class SafetyElementsDemoView: UIView {
SafetyElementViewModel(
title: "Bytterett",
icon: UIImage(named: .warranty),
body: "Denne bilen selges med bytterett fra forhandler. Det betyr at du som kjøper har mulighet til å bytte den mot en annen bil, i henhold til forhandlerens vilkår. Dette kan du gjøre dersom bilen du har kjøpt av en eller annen grunn ikke tilfredsstiller dine forventninger eller behov. Produktet tilbys for at du som kjøper skal føle deg helt trygg på at du ender opp med riktig bil for ditt behov.",
body: "Denne bilen selges med bytterett fra forhandler. Det betyr at du som kjøper har mulighet til å bytte den mot en annen bil, i henhold til forhandlerens vilkår.",
bottomLink: nil
),
SafetyElementViewModel(
title: "Bytterett",
icon: UIImage(named: .warranty),
body: "Denne bilen selges med bytterett fra forhandler.",
emphasizedBody: "Denne bilen selges med bytterett fra forhandler.",
bottomLink: nil
),
SafetyElementViewModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//
// Copyright © 2020 FINN AS. All rights reserved.
//
import Warp

public protocol SafetyElementContentViewDelegate: AnyObject {
Expand All @@ -9,10 +6,18 @@ public protocol SafetyElementContentViewDelegate: AnyObject {

public extension SafetyElementsView {
class ElementContentView: UIView {

// MARK: - Public properties

public weak var delegate: SafetyElementContentViewDelegate?

// MARK: - Private properties

private let linkButtonStyle = Button.Style.link.overrideStyle(normalFont: .body)
private var topLink: LinkButtonViewModel?
private var bottomLink: LinkButtonViewModel?
private lazy var topLinkButton: Button = makeExternalLinkButton(onTap: #selector(didTapOnTopLink))
private lazy var bottomLinkButton: Button = makeExternalLinkButton(onTap: #selector(didTapOnBottomLink))

private lazy var contentStackView: UIStackView = {
let stackView = UIStackView(withAutoLayout: true)
Expand All @@ -22,17 +27,21 @@ public extension SafetyElementsView {
return stackView
}()

private let linkButtonStyle = Button.Style.link.overrideStyle(normalFont: .body)

private lazy var contentLabel: Label = {
let label = Label(style: .body, withAutoLayout: true)
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
return label
}()

private lazy var topLinkButton: Button = makeExternalLinkButton(onTap: #selector(didTapOnTopLink))
private lazy var bottomLinkButton: Button = makeExternalLinkButton(onTap: #selector(didTapOnBottomLink))
private lazy var emphasizedContentLabel: Label = {
let label = Label(style: .bodyStrong, withAutoLayout: true)
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
return label
}()

// MARK: - Init

public override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -41,43 +50,65 @@ public extension SafetyElementsView {

public required init?(coder aDecoder: NSCoder) { fatalError() }

// MARK: - Public methods

public func configure(with viewModel: SafetyElementViewModel) {
configure(with: viewModel.body, topLink: viewModel.topLink, bottomLink: viewModel.bottomLink)
configure(
with: viewModel.body,
emphasizedContent: viewModel.emphasizedBody,
topLink: viewModel.topLink,
bottomLink: viewModel.bottomLink
)
}

public func configure(
with content: String,
emphasizedContent: String? = nil,
topLink: LinkButtonViewModel? = nil,
bottomLink: LinkButtonViewModel? = nil
) {
self.topLink = topLink
self.bottomLink = bottomLink
contentLabel.text = content

if let topLink = topLink {
if let emphasizedContent {
emphasizedContentLabel.text = emphasizedContent
emphasizedContentLabel.isHidden = false
} else {
emphasizedContentLabel.isHidden = true
}

if let topLink {
topLinkButton.setTitle(topLink.buttonTitle, for: .normal)
topLinkButton.isHidden = false
} else {
topLinkButton.isHidden = true
}

if let bottomLink = bottomLink {
if let bottomLink {
bottomLinkButton.setTitle(bottomLink.buttonTitle, for: .normal)
bottomLinkButton.isHidden = false
} else {
bottomLinkButton.isHidden = true
}
}

// MARK: - Setup

private func setup() {
addSubview(contentStackView)

contentStackView.addArrangedSubview(topLinkButton)
contentStackView.addArrangedSubview(contentLabel)
contentStackView.addArrangedSubview(bottomLinkButton)
contentStackView.addArrangedSubviews([
topLinkButton,
contentLabel,
emphasizedContentLabel,
bottomLinkButton,
])
contentStackView.fillInSuperviewLayoutMargins()
}

// MARK: - Private methods

@objc private func didTapOnBottomLink() {
guard let bottomLink = bottomLink else { return }
didTap(on: bottomLink)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
//
// Copyright © 2020 FINN AS. All rights reserved.
//

import Foundation

public struct SafetyElementViewModel {
public let title: String
public let icon: UIImage
public let body: String
public let emphasizedBody: String?
public let topLink: LinkButtonViewModel?
public let bottomLink: LinkButtonViewModel?

public init(title: String, icon: UIImage, body: String, topLink: LinkButtonViewModel? = nil, bottomLink: LinkButtonViewModel? = nil) {
public init(
title: String,
icon: UIImage,
body: String,
emphasizedBody: String? = nil,
topLink: LinkButtonViewModel? = nil,
bottomLink: LinkButtonViewModel? = nil
) {
self.title = title
self.icon = icon
self.body = body
self.emphasizedBody = emphasizedBody
self.topLink = topLink
self.bottomLink = bottomLink
}
Expand Down

0 comments on commit 5d3c8d6

Please sign in to comment.