|
|
@ -8,6 +8,9 @@ protocol OpenSeaNonFungibleTokenCardRowViewDelegate: class { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
|
|
|
|
private static let xMargin = CGFloat(7) |
|
|
|
|
|
|
|
private static let yMargin = CGFloat(5) |
|
|
|
|
|
|
|
|
|
|
|
private let mainVerticalStackView: UIStackView = [].asStackView(axis: .vertical, contentHuggingPriority: .required) |
|
|
|
private let mainVerticalStackView: UIStackView = [].asStackView(axis: .vertical, contentHuggingPriority: .required) |
|
|
|
private let thumbnailImageView = UIImageView() |
|
|
|
private let thumbnailImageView = UIImageView() |
|
|
|
private let bigImageBackground = UIView() |
|
|
|
private let bigImageBackground = UIView() |
|
|
@ -92,6 +95,14 @@ class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
private var currentDisplayedImageUrl: URL? |
|
|
|
private var currentDisplayedImageUrl: URL? |
|
|
|
private var checkboxRelatedConstraintsWhenShown = [NSLayoutConstraint]() |
|
|
|
private var checkboxRelatedConstraintsWhenShown = [NSLayoutConstraint]() |
|
|
|
private var checkboxRelatedConstraintsWhenHidden = [NSLayoutConstraint]() |
|
|
|
private var checkboxRelatedConstraintsWhenHidden = [NSLayoutConstraint]() |
|
|
|
|
|
|
|
//Hackish: To get the width of the descriptionLabel in order to calculate the correct height |
|
|
|
|
|
|
|
private var descriptionLabelWidth: CGFloat { |
|
|
|
|
|
|
|
if let fullWidth = viewModel?.width { |
|
|
|
|
|
|
|
return fullWidth - OpenSeaNonFungibleTokenCardRowView.xMargin * 2 - outerHorizontalMargin |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var background = UIView() |
|
|
|
var background = UIView() |
|
|
|
var stateLabel = UILabel() |
|
|
|
var stateLabel = UILabel() |
|
|
@ -108,6 +119,17 @@ class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var additionalHeightToCompensateForAutoLayout: CGFloat { |
|
|
|
|
|
|
|
guard let attributedText = descriptionLabel.attributedText else { return 0 } |
|
|
|
|
|
|
|
let rect = attributedText.boundingRect(with: .init(width: descriptionLabelWidth, height: 1000), options: .usesLineFragmentOrigin, context: nil) |
|
|
|
|
|
|
|
let size = rect.size |
|
|
|
|
|
|
|
//Hackish: Add a bit of allowance. Otherwise it's good for CryptoKitties, but there's no enough space for Chibi Fighters' title |
|
|
|
|
|
|
|
if size.height > 0 { |
|
|
|
|
|
|
|
return size.height + 10 |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
//Just to adhere to protocol |
|
|
|
//Just to adhere to protocol |
|
|
|
var areDetailsVisible = false |
|
|
|
var areDetailsVisible = false |
|
|
|
|
|
|
|
|
|
|
@ -165,8 +187,10 @@ class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
generationStackView, |
|
|
|
generationStackView, |
|
|
|
cooldownStackView |
|
|
|
cooldownStackView |
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
titleLabel.setContentCompressionResistancePriority(.required, for: .vertical) |
|
|
|
|
|
|
|
descriptionLabel.setContentCompressionResistancePriority(.required, for: .vertical) |
|
|
|
|
|
|
|
|
|
|
|
let col0 = [ |
|
|
|
let col0: UIStackView = [ |
|
|
|
spacers.aboveTitle, |
|
|
|
spacers.aboveTitle, |
|
|
|
stateLabel, |
|
|
|
stateLabel, |
|
|
|
spacers.belowState, |
|
|
|
spacers.belowState, |
|
|
@ -213,11 +237,9 @@ class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
background.addSubview(mainVerticalStackView) |
|
|
|
background.addSubview(mainVerticalStackView) |
|
|
|
|
|
|
|
|
|
|
|
// TODO extract constant. Maybe StyleLayout.sideMargin |
|
|
|
// TODO extract constant. Maybe StyleLayout.sideMargin |
|
|
|
let xMargin = CGFloat(7) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: OpenSeaNonFungibleTokenCardRowView.xMargin)) |
|
|
|
let yMargin = CGFloat(5) |
|
|
|
|
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: xMargin)) |
|
|
|
|
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.centerYAnchor.constraint(equalTo: centerYAnchor)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.centerYAnchor.constraint(equalTo: centerYAnchor)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(background.leadingAnchor.constraint(equalTo: checkboxImageView.trailingAnchor, constant: xMargin)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(background.leadingAnchor.constraint(equalTo: checkboxImageView.trailingAnchor, constant: OpenSeaNonFungibleTokenCardRowView.xMargin)) |
|
|
|
if ScreenChecker().isNarrowScreen { |
|
|
|
if ScreenChecker().isNarrowScreen { |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.widthAnchor.constraint(equalToConstant: 20)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.widthAnchor.constraint(equalToConstant: 20)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.heightAnchor.constraint(equalToConstant: 20)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.heightAnchor.constraint(equalToConstant: 20)) |
|
|
@ -226,7 +248,7 @@ class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.widthAnchor.constraint(equalToConstant: 28)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.widthAnchor.constraint(equalToConstant: 28)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.heightAnchor.constraint(equalToConstant: 28)) |
|
|
|
checkboxRelatedConstraintsWhenShown.append(checkboxImageView.heightAnchor.constraint(equalToConstant: 28)) |
|
|
|
} |
|
|
|
} |
|
|
|
checkboxRelatedConstraintsWhenHidden.append(background.leadingAnchor.constraint(equalTo: leadingAnchor, constant: xMargin)) |
|
|
|
checkboxRelatedConstraintsWhenHidden.append(background.leadingAnchor.constraint(equalTo: leadingAnchor, constant: OpenSeaNonFungibleTokenCardRowView.xMargin)) |
|
|
|
if showCheckbox { |
|
|
|
if showCheckbox { |
|
|
|
NSLayoutConstraint.activate(checkboxRelatedConstraintsWhenShown) |
|
|
|
NSLayoutConstraint.activate(checkboxRelatedConstraintsWhenShown) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -261,9 +283,9 @@ class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
NSLayoutConstraint.activate([ |
|
|
|
NSLayoutConstraint.activate([ |
|
|
|
mainVerticalStackView.anchorsConstraint(to: background, edgeInsets: .init(top: marginForBigImageView, left: 0, bottom: 0, right: 0)), |
|
|
|
mainVerticalStackView.anchorsConstraint(to: background, edgeInsets: .init(top: marginForBigImageView, left: 0, bottom: 0, right: 0)), |
|
|
|
|
|
|
|
|
|
|
|
background.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -xMargin), |
|
|
|
background.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -OpenSeaNonFungibleTokenCardRowView.xMargin), |
|
|
|
background.topAnchor.constraint(equalTo: topAnchor, constant: yMargin), |
|
|
|
background.topAnchor.constraint(equalTo: topAnchor, constant: OpenSeaNonFungibleTokenCardRowView.yMargin), |
|
|
|
background.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -yMargin), |
|
|
|
background.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -OpenSeaNonFungibleTokenCardRowView.yMargin), |
|
|
|
|
|
|
|
|
|
|
|
stateLabel.heightAnchor.constraint(equalToConstant: 22), |
|
|
|
stateLabel.heightAnchor.constraint(equalToConstant: 22), |
|
|
|
|
|
|
|
|
|
|
@ -436,6 +458,7 @@ class OpenSeaNonFungibleTokenCardRowView: UIView, TokenCardRowViewProtocol { |
|
|
|
descriptionLabel.attributedText = viewModel.descriptionWithoutConvertingHtml |
|
|
|
descriptionLabel.attributedText = viewModel.descriptionWithoutConvertingHtml |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
descriptionLabel.preferredMaxLayoutWidth = descriptionLabelWidth |
|
|
|
|
|
|
|
|
|
|
|
titleLabel.text = viewModel.title |
|
|
|
titleLabel.text = viewModel.title |
|
|
|
|
|
|
|
|
|
|
|