WIP: new closed group vc

pull/689/head
ryanzhao 3 years ago
parent df140584e7
commit e5c3c23e74

@ -25,7 +25,18 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
// MARK: - Components
private lazy var nameTextField = TextField(placeholder: "vc_create_closed_group_text_field_hint".localized())
private lazy var nameTextField = TextField(
placeholder: "vc_create_closed_group_text_field_hint".localized(),
customHeight: 48
)
private lazy var searchBar: ContactsSearchBar = {
let result = ContactsSearchBar()
result.tintColor = Colors.text
result.backgroundColor = .clear
result.delegate = self
return result
}()
private lazy var tableView: TableView = {
let result: TableView = TableView()
@ -40,6 +51,15 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
return result
}()
private lazy var createGroupButton: Button = {
let result = Button(style: .prominentOutline, size: .large)
result.translatesAutoresizingMaskIntoConstraints = false
result.setTitle(NSLocalizedString("CREATE_GROUP_BUTTON_TITLE", comment: ""), for: .normal)
result.addTarget(self, action: #selector(createClosedGroup), for: .touchUpInside)
result.set(.width, to: 160)
return result
}()
// MARK: - Lifecycle
override func viewDidLoad() {
@ -51,10 +71,6 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
let customTitleFontSize = Values.largeFontSize
setNavBarTitle("vc_create_closed_group_title".localized(), customFontSize: customTitleFontSize)
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(createClosedGroup))
doneButton.tintColor = Colors.text
navigationItem.rightBarButtonItem = doneButton
// Set up content
setUpViewHierarchy()
}
@ -95,14 +111,22 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
nameTextField.pin(.leading, to: .leading, of: nameTextFieldContainer, withInset: Values.largeSpacing)
nameTextField.pin(.top, to: .top, of: nameTextFieldContainer, withInset: Values.mediumSpacing)
nameTextFieldContainer.pin(.trailing, to: .trailing, of: nameTextField, withInset: Values.largeSpacing)
nameTextFieldContainer.pin(.bottom, to: .bottom, of: nameTextField, withInset: Values.largeSpacing)
nameTextFieldContainer.pin(.bottom, to: .bottom, of: nameTextField)
mainStackView.addArrangedSubview(nameTextFieldContainer)
let searchBarContainer: UIView = UIView()
searchBarContainer.addSubview(searchBar)
searchBar.pin(.leading, to: .leading, of: searchBarContainer, withInset: Values.largeSpacing)
searchBarContainer.pin(.trailing, to: .trailing, of: searchBar, withInset: Values.largeSpacing)
searchBar.pin([ UIView.VerticalEdge.top, UIView.VerticalEdge.bottom ], to: searchBarContainer)
mainStackView.addArrangedSubview(searchBarContainer)
let separator: UIView = UIView()
separator.backgroundColor = Colors.separator
separator.set(.height, to: Values.separatorThickness)
mainStackView.addArrangedSubview(separator)
tableView.set(.height, to: CGFloat(contactProfiles.count * 65)) // A cell is exactly 65 points high
tableView.set(.height, to: CGFloat(contactProfiles.count * 65 + 100)) // A cell is exactly 65 points high
tableView.set(.width, to: UIScreen.main.bounds.width)
mainStackView.addArrangedSubview(tableView)
@ -113,6 +137,10 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
scrollView.set(.width, to: UIScreen.main.bounds.width)
scrollView.pin(to: view)
view.addSubview(createGroupButton)
createGroupButton.center(.horizontal, in: view)
createGroupButton.pin(.bottom, to: .bottom, of: view, withInset: -Values.largeSpacing)
}
// MARK: - Table View Data Source
@ -127,7 +155,7 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
with: contactProfiles[indexPath.row].id,
profile: contactProfiles[indexPath.row],
isZombie: false,
accessory: .tick(isSelected: selectedContacts.contains(contactProfiles[indexPath.row].id))
accessory: .o(isSelected: selectedContacts.contains(contactProfiles[indexPath.row].id))
)
return cell
@ -222,3 +250,19 @@ final class NewClosedGroupVC: BaseVC, UITableViewDataSource, UITableViewDelegate
SessionApp.homeViewController.wrappedValue?.createNewDM()
}
}
extension NewClosedGroupVC: UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
// searchText = searchText
}
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
searchBar.showsCancelButton = true
return true
}
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
searchBar.showsCancelButton = false
searchBar.resignFirstResponder()
}
}

@ -57,7 +57,6 @@ final class NewConversationVC: BaseVC, UITableViewDelegate, UITableViewDataSourc
result.delegate = self
result.dataSource = self
result.separatorStyle = .none
result.backgroundColor = .clear
if #available(iOS 15.0, *) {
result.sectionHeaderTopPadding = 0
}

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -707,3 +707,4 @@
"EMOJI_REACTS_MORE_REACTORS_MUTIPLE" = "And %@ others have reacted %@ to this message.";
/* New conversation screen*/
"vc_new_conversation_title" = "New Conversation";
"CREATE_GROUP_BUTTON_TITLE" = "Create";

@ -11,6 +11,7 @@ final class UserCell: UITableViewCell {
case none
case lock
case tick(isSelected: Bool)
case o(isSelected: Bool)
case x
}
@ -35,6 +36,8 @@ final class UserCell: UITableViewCell {
return result
}()
private lazy var roundSelectionView = RoundSelectionView()
private lazy var separator: UIView = {
let result: UIView = UIView()
@ -80,7 +83,8 @@ final class UserCell: UITableViewCell {
UIView.hSpacer(Values.mediumSpacing),
displayNameLabel,
spacer,
accessoryImageView
accessoryImageView,
roundSelectionView
]
)
stackView.axis = .horizontal
@ -134,26 +138,64 @@ final class UserCell: UITableViewCell {
)
switch accessory {
case .none: accessoryImageView.isHidden = true
case .none:
accessoryImageView.isHidden = true
roundSelectionView.isHidden = true
case .lock:
roundSelectionView.isHidden = true
accessoryImageView.isHidden = false
accessoryImageView.image = #imageLiteral(resourceName: "ic_lock_outline").withRenderingMode(.alwaysTemplate)
accessoryImageView.tintColor = Colors.text.withAlphaComponent(Values.mediumOpacity)
case .tick(let isSelected):
roundSelectionView.isHidden = true
let icon: UIImage = (isSelected ? #imageLiteral(resourceName: "CircleCheck") : #imageLiteral(resourceName: "Circle"))
accessoryImageView.isHidden = false
accessoryImageView.image = icon.withRenderingMode(.alwaysTemplate)
accessoryImageView.tintColor = Colors.text
case .x:
roundSelectionView.isHidden = true
accessoryImageView.isHidden = false
accessoryImageView.image = #imageLiteral(resourceName: "X").withRenderingMode(.alwaysTemplate)
accessoryImageView.contentMode = .center
accessoryImageView.tintColor = Colors.text
case .o(let isSelected):
accessoryImageView.isHidden = true
roundSelectionView.isHidden = false
roundSelectionView.update(isSelected: isSelected)
}
let alpha: CGFloat = (isZombie ? 0.5 : 1)
[ profilePictureView, displayNameLabel, accessoryImageView ].forEach { $0.alpha = alpha }
}
}
fileprivate class RoundSelectionView: UIView {
private lazy var centralView: UIView = {
let result = UIView()
result.backgroundColor = Colors.accent
return result
}()
init() {
super.init(frame: CGRect.zero)
self.addSubview(centralView)
self.set(.width, to: 20)
self.set(.height, to: 20)
self.layer.cornerRadius = 10
self.layer.borderWidth = 1
self.layer.borderColor = Colors.text.cgColor
centralView.pin(to: self, withInset: 3)
centralView.layer.cornerRadius = 7
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func update(isSelected: Bool) {
centralView.isHidden = !isSelected
}
}

@ -13,6 +13,19 @@ public final class SearchBar : UISearchBar {
}
}
public final class ContactsSearchBar : UISearchBar {
public override init(frame: CGRect) {
super.init(frame: frame)
setUpContactSearchStyle()
}
public required init?(coder: NSCoder) {
super.init(coder: coder)
setUpContactSearchStyle()
}
}
public extension UISearchBar {
func setUpSessionStyle() {
@ -31,4 +44,21 @@ public extension UISearchBar {
searchTextPositionAdjustment = UIOffset(horizontal: 2, vertical: 0)
setPositionAdjustment(UIOffset(horizontal: -4, vertical: 0), for: UISearchBar.Icon.clear)
}
func setUpContactSearchStyle() {
searchBarStyle = .minimal
barStyle = .default
tintColor = Colors.text
let searchImage = #imageLiteral(resourceName: "searchbar_search").withTint(Colors.text)!
setImage(searchImage, for: .search, state: .normal)
let clearImage = #imageLiteral(resourceName: "searchbar_clear").withTint(Colors.text)!
setImage(clearImage, for: .clear, state: .normal)
let searchTextField: UITextField = self.searchTextField
searchTextField.backgroundColor = .white // The search bar background color
searchTextField.textColor = Colors.text
searchTextField.attributedPlaceholder = NSAttributedString(string: "Search Contacts", attributes: [ .foregroundColor : Colors.searchBarPlaceholder ])
setPositionAdjustment(UIOffset(horizontal: 4, vertical: 0), for: UISearchBar.Icon.search)
searchTextPositionAdjustment = UIOffset(horizontal: 2, vertical: 0)
setPositionAdjustment(UIOffset(horizontal: -4, vertical: 0), for: UISearchBar.Icon.clear)
}
}

@ -50,4 +50,5 @@ public final class Colors : NSObject {
@objc public static var sessionMessageRequestsTitle: UIColor { UIColor(named: "session_message_requests_title")! }
@objc public static var sessionMessageRequestsInfoText: UIColor { UIColor(named: "session_message_requests_info_text")! }
@objc public static var sessionEmojiPlusButtonBackground: UIColor { UIColor(named: "session_emoji_plus_button_background")! }
@objc public static var sessionContactsSearchBarBackground: UIColor { UIColor(named: "session_contacts_search_bar_background")! }
}

@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0xFF",
"green" : "0xFF",
"red" : "0xFF"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x00",
"green" : "0x00",
"red" : "0x00"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading…
Cancel
Save