feat: support display custom emoji for field name

This commit is contained in:
CMK 2021-05-27 14:57:20 +08:00
parent 6f55c0288c
commit 423bdb2473
4 changed files with 46 additions and 14 deletions

View File

@ -33,18 +33,24 @@ extension ProfileFieldSection {
cell.separatorLineToMarginLeadingLayoutConstraint.constant = margin cell.separatorLineToMarginLeadingLayoutConstraint.constant = margin
// set key // set key
cell.fieldView.titleActiveLabel.configure(field: field.name.value, emojiDict: attribute.emojiDict.value)
cell.fieldView.titleTextField.text = field.name.value cell.fieldView.titleTextField.text = field.name.value
field.name Publishers.CombineLatest(
.removeDuplicates() field.name.removeDuplicates(),
.receive(on: RunLoop.main) attribute.emojiDict.removeDuplicates()
.sink { [weak cell] name in )
guard let cell = cell else { return } .receive(on: RunLoop.main)
cell.fieldView.titleTextField.text = name .sink { [weak cell] name, emojiDict in
} guard let cell = cell else { return }
.store(in: &cell.disposeBag) cell.fieldView.titleActiveLabel.configure(field: name, emojiDict: emojiDict)
cell.fieldView.titleTextField.text = name
}
.store(in: &cell.disposeBag)
// set value // set value
cell.fieldView.valueActiveLabel.configure(field: field.value.value, emojiDict: attribute.emojiDict.value) cell.fieldView.valueActiveLabel.configure(field: field.value.value, emojiDict: attribute.emojiDict.value)
cell.fieldView.valueTextField.text = field.value.value
Publishers.CombineLatest( Publishers.CombineLatest(
field.value.removeDuplicates(), field.value.removeDuplicates(),
attribute.emojiDict.removeDuplicates() attribute.emojiDict.removeDuplicates()
@ -72,9 +78,10 @@ extension ProfileFieldSection {
} }
// setup editing state // setup editing state
cell.fieldView.titleTextField.isEnabled = attribute.isEditing cell.fieldView.titleTextField.isHidden = !attribute.isEditing
cell.fieldView.valueActiveLabel.isHidden = attribute.isEditing
cell.fieldView.valueTextField.isHidden = !attribute.isEditing cell.fieldView.valueTextField.isHidden = !attribute.isEditing
cell.fieldView.titleActiveLabel.isHidden = attribute.isEditing
cell.fieldView.valueActiveLabel.isHidden = attribute.isEditing
// set control hidden // set control hidden
let isHidden = !attribute.isEditing let isHidden = !attribute.isEditing

View File

@ -16,7 +16,8 @@ extension ActiveLabel {
case `default` case `default`
case statusHeader case statusHeader
case statusName case statusName
case profileField case profileFieldName
case profileFieldValue
} }
convenience init(style: Style) { convenience init(style: Style) {
@ -46,7 +47,11 @@ extension ActiveLabel {
font = .systemFont(ofSize: 17, weight: .semibold) font = .systemFont(ofSize: 17, weight: .semibold)
textColor = Asset.Colors.Label.primary.color textColor = Asset.Colors.Label.primary.color
numberOfLines = 1 numberOfLines = 1
case .profileField: case .profileFieldName:
font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 20)
textColor = Asset.Colors.Label.primary.color
numberOfLines = 1
case .profileFieldValue:
font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .regular), maximumPointSize: 20) font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .regular), maximumPointSize: 20)
textColor = Asset.Colors.Label.primary.color textColor = Asset.Colors.Label.primary.color
numberOfLines = 1 numberOfLines = 1

View File

@ -96,8 +96,13 @@ extension ProfileFieldAddEntryCollectionViewCell {
bottomSeparatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)).priority(.defaultHigh), bottomSeparatorLine.heightAnchor.constraint(equalToConstant: UIView.separatorLineHeight(of: self)).priority(.defaultHigh),
]) ])
fieldView.titleTextField.text = L10n.Scene.Profile.Fields.addRow fieldView.titleActiveLabel.isHidden = false
fieldView.titleActiveLabel.configure(field: L10n.Scene.Profile.Fields.addRow, emojiDict: [:])
fieldView.titleTextField.isHidden = true
fieldView.valueActiveLabel.isHidden = false
fieldView.valueActiveLabel.configure(field: " ", emojiDict: [:]) fieldView.valueActiveLabel.configure(field: " ", emojiDict: [:])
fieldView.valueTextField.isHidden = true
addGestureRecognizer(singleTagGestureRecognizer) addGestureRecognizer(singleTagGestureRecognizer)
singleTagGestureRecognizer.addTarget(self, action: #selector(ProfileFieldAddEntryCollectionViewCell.singleTapGestureRecognizerHandler(_:))) singleTagGestureRecognizer.addTarget(self, action: #selector(ProfileFieldAddEntryCollectionViewCell.singleTapGestureRecognizerHandler(_:)))

View File

@ -17,6 +17,14 @@ final class ProfileFieldView: UIView {
let name = PassthroughSubject<String, Never>() let name = PassthroughSubject<String, Never>()
let value = PassthroughSubject<String, Never>() let value = PassthroughSubject<String, Never>()
// for custom emoji display
let titleActiveLabel: ActiveLabel = {
let label = ActiveLabel(style: .profileFieldName)
label.configure(content: "title", emojiDict: [:])
return label
}()
// for editing
let titleTextField: UITextField = { let titleTextField: UITextField = {
let textField = UITextField() let textField = UITextField()
textField.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 20) textField.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 20)
@ -28,7 +36,7 @@ final class ProfileFieldView: UIView {
// for custom emoji display // for custom emoji display
let valueActiveLabel: ActiveLabel = { let valueActiveLabel: ActiveLabel = {
let label = ActiveLabel(style: .profileField) let label = ActiveLabel(style: .profileFieldValue)
label.configure(content: "value", emojiDict: [:]) label.configure(content: "value", emojiDict: [:])
return label return label
}() }()
@ -73,6 +81,12 @@ extension ProfileFieldView {
containerStackView.trailingAnchor.constraint(equalTo: trailingAnchor), containerStackView.trailingAnchor.constraint(equalTo: trailingAnchor),
containerStackView.bottomAnchor.constraint(equalTo: bottomAnchor), containerStackView.bottomAnchor.constraint(equalTo: bottomAnchor),
]) ])
titleActiveLabel.translatesAutoresizingMaskIntoConstraints = false
containerStackView.addArrangedSubview(titleActiveLabel)
NSLayoutConstraint.activate([
titleActiveLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: 44).priority(.defaultHigh),
])
titleTextField.setContentHuggingPriority(.defaultLow - 1, for: .horizontal)
titleTextField.translatesAutoresizingMaskIntoConstraints = false titleTextField.translatesAutoresizingMaskIntoConstraints = false
containerStackView.addArrangedSubview(titleTextField) containerStackView.addArrangedSubview(titleTextField)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
@ -92,6 +106,7 @@ extension ProfileFieldView {
valueTextField.widthAnchor.constraint(greaterThanOrEqualToConstant: 44).priority(.defaultHigh), valueTextField.widthAnchor.constraint(greaterThanOrEqualToConstant: 44).priority(.defaultHigh),
]) ])
titleTextField.isHidden = true
valueTextField.isHidden = true valueTextField.isHidden = true
NotificationCenter.default NotificationCenter.default