Just Commit

This commit is contained in:
砍砍
2024-12-13 14:09:01 +08:00
parent 8333f00aec
commit 1c685fb5a4
5 changed files with 78 additions and 9 deletions
@@ -0,0 +1,14 @@
//
// Ext+UIColor.swift
// Intelligents
//
// Created by on 2024/12/13.
//
import UIKit
extension UIColor {
static var accent: UIColor {
.accent
}
}
@@ -27,11 +27,16 @@ extension ChatTableView {
didSet { update(via: viewModel) }
}
var isBackgroundColorActivated = false {
enum BackgroundColorType {
case clear
case highlight
case warning
case lightGray
}
var backgroundColorType: BackgroundColorType = .clear {
didSet {
roundedBackgroundView.backgroundColor = isBackgroundColorActivated
? .systemGray.withAlphaComponent(0.25)
: .clear
roundedBackgroundView.backgroundColor = backgroundColorType.color
}
}
@@ -40,6 +45,10 @@ extension ChatTableView {
selectionStyle = .none
backgroundColor = .clear
roundedBackgroundView.clipsToBounds = true
roundedBackgroundView.layer.cornerRadius = 8
roundedBackgroundView.layer.masksToBounds = true
contentView.addSubview(roundedBackgroundView)
roundedBackgroundView.translatesAutoresizingMaskIntoConstraints = false
[ // inset half of the container view
@@ -74,3 +83,18 @@ extension ChatTableView {
}
}
}
extension ChatTableView.BaseCell.BackgroundColorType {
var color: UIColor {
switch self {
case .clear:
.clear
case .highlight:
.accent
case .warning:
.systemRed.withAlphaComponent(0.1)
case .lightGray:
.systemGray.withAlphaComponent(0.1)
}
}
}
@@ -68,12 +68,15 @@ extension ChatTableView {
case .system:
avatarView.image = UIImage(systemName: "gearshape.fill")
titleLabel.text = "System".localized()
backgroundColorType = .warning
case .assistant:
avatarView.image = UIImage(named: "spark", in: .module, with: .none)
titleLabel.text = "AFFiNE AI".localized()
backgroundColorType = .lightGray
case .user:
avatarView.image = UIImage(systemName: "person.fill")
titleLabel.text = "You".localized()
backgroundColorType = .clear
}
removableConstraints.forEach { $0.isActive = false }
@@ -40,6 +40,19 @@ class ChatTableView: UIView {
foot.widthAnchor.constraint(equalToConstant: 200).isActive = true
tableView.tableFooterView = foot
tableView.separatorStyle = .none
putMockData()
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError()
}
}
extension ChatTableView {
func putMockData() {
DispatchQueue.main.async {
self.dataSource = [
.init(type: .chat, object: ChatCell.ViewModel(
@@ -85,9 +98,4 @@ class ChatTableView: UIView {
self.tableView.reloadData()
}
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError()
}
}
@@ -0,0 +1,20 @@
{
"colors": [
{
"color": {
"color-space": "srgb",
"components": {
"alpha": "1.000",
"blue": "228",
"green": "148",
"red": "72"
}
},
"idiom": "universal"
}
],
"info": {
"author": "xcode",
"version": 1
}
}