Fix new conversation button sizes

pull/133/head
Niels Andriesse 6 years ago
parent 0820e6ee34
commit eb26487d06

@ -42,15 +42,13 @@ final class NewConversationButtonSet : UIView {
verticalButtonConstraints[createNewClosedGroupButton] = createNewClosedGroupButton.pin(.bottom, to: .bottom, of: self, withInset: -inset) verticalButtonConstraints[createNewClosedGroupButton] = createNewClosedGroupButton.pin(.bottom, to: .bottom, of: self, withInset: -inset)
addSubview(mainButton) addSubview(mainButton)
mainButton.center(.horizontal, in: self) mainButton.center(.horizontal, in: self)
mainButton.pin(.bottom, to: .bottom, of: self) mainButton.pin(.bottom, to: .bottom, of: self, withInset: -inset)
let width = 3 * Values.newConversationButtonExpandedSize + 2 * spacing let width = 2 * Values.newConversationButtonExpandedSize + 2 * spacing + Values.newConversationButtonCollapsedSize
set(.width, to: width) set(.width, to: width)
let height = 2 * Values.newConversationButtonExpandedSize + spacing let height = Values.newConversationButtonExpandedSize + spacing + Values.newConversationButtonCollapsedSize
set(.height, to: height) set(.height, to: height)
collapse(withAnimation: false) collapse(withAnimation: false)
isUserInteractionEnabled = true isUserInteractionEnabled = true
let mainButtonTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleMainButtonTapped))
mainButton.addGestureRecognizer(mainButtonTapGestureRecognizer)
let joinOpenGroupButtonTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleJoinOpenGroupButtonTapped)) let joinOpenGroupButtonTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleJoinOpenGroupButtonTapped))
joinOpenGroupButton.addGestureRecognizer(joinOpenGroupButtonTapGestureRecognizer) joinOpenGroupButton.addGestureRecognizer(joinOpenGroupButtonTapGestureRecognizer)
let createNewPrivateChatButtonTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleCreateNewPrivateChatButtonTapped)) let createNewPrivateChatButtonTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleCreateNewPrivateChatButtonTapped))
@ -60,7 +58,6 @@ final class NewConversationButtonSet : UIView {
} }
// MARK: Interaction // MARK: Interaction
@objc private func handleMainButtonTapped() { expand(isUserDragging: false) }
@objc private func handleJoinOpenGroupButtonTapped() { delegate?.joinOpenGroup() } @objc private func handleJoinOpenGroupButtonTapped() { delegate?.joinOpenGroup() }
@objc private func handleCreateNewPrivateChatButtonTapped() { delegate?.createNewPrivateChat() } @objc private func handleCreateNewPrivateChatButtonTapped() { delegate?.createNewPrivateChat() }
@objc private func handleCreateNewClosedGroupButtonTapped() { delegate?.createNewClosedGroup() } @objc private func handleCreateNewClosedGroupButtonTapped() { delegate?.createNewClosedGroup() }
@ -161,7 +158,7 @@ final class NewConversationButtonSet : UIView {
self.layoutIfNeeded() self.layoutIfNeeded()
button.frame = frame button.frame = frame
button.layer.cornerRadius = size / 2 button.layer.cornerRadius = size / 2
button.addGlow(ofSize: size) button.setGlow(to: size, with: Colors.newConversationButtonShadow)
button.backgroundColor = Colors.accent button.backgroundColor = Colors.accent
} }
} }
@ -185,7 +182,7 @@ final class NewConversationButtonSet : UIView {
self.layoutIfNeeded() self.layoutIfNeeded()
button.frame = frame button.frame = frame
button.layer.cornerRadius = size / 2 button.layer.cornerRadius = size / 2
button.removeGlow() button.setGlow(to: size, with: UIColor.black)
button.backgroundColor = Colors.newConversationButtonCollapsedBackground button.backgroundColor = Colors.newConversationButtonCollapsedBackground
} }
} }
@ -229,9 +226,9 @@ private final class NewConversationButton : UIImageView {
private func setUpViewHierarchy() { private func setUpViewHierarchy() {
backgroundColor = isMainButton ? Colors.accent : Colors.newConversationButtonCollapsedBackground backgroundColor = isMainButton ? Colors.accent : Colors.newConversationButtonCollapsedBackground
let size = isMainButton ? Values.newConversationButtonExpandedSize : Values.newConversationButtonCollapsedSize let size = Values.newConversationButtonCollapsedSize
layer.cornerRadius = size / 2 layer.cornerRadius = size / 2
if isMainButton { addGlow(ofSize: size) } if isMainButton { setGlow(to: size, with: Colors.newConversationButtonShadow) }
layer.masksToBounds = false layer.masksToBounds = false
image = icon image = icon
contentMode = .center contentMode = .center
@ -240,21 +237,13 @@ private final class NewConversationButton : UIImageView {
} }
// General // General
func addGlow(ofSize size: CGFloat) { func setGlow(to size: CGFloat, with color: UIColor) {
layer.shadowPath = UIBezierPath(ovalIn: CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: size, height: size))).cgPath layer.shadowPath = UIBezierPath(ovalIn: CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: size, height: size))).cgPath
layer.shadowColor = Colors.newConversationButtonShadow.cgColor layer.shadowColor = color.cgColor
layer.shadowOffset = CGSize(width: 0, height: 0.8) layer.shadowOffset = CGSize(width: 0, height: 0.8)
layer.shadowOpacity = 1 layer.shadowOpacity = 1
layer.shadowRadius = 6 layer.shadowRadius = 6
} }
func removeGlow() {
layer.shadowPath = nil
layer.shadowColor = nil
layer.shadowOffset = CGSize.zero
layer.shadowOpacity = 0
layer.shadowRadius = 0
}
} }
// MARK: Convenience // MARK: Convenience

@ -30,8 +30,8 @@ final class Values : NSObject {
@objc static let borderThickness = CGFloat(1) @objc static let borderThickness = CGFloat(1)
@objc static let conversationCellStatusIndicatorSize = CGFloat(14) @objc static let conversationCellStatusIndicatorSize = CGFloat(14)
@objc static let searchBarHeight = CGFloat(36) @objc static let searchBarHeight = CGFloat(36)
@objc static let newConversationButtonCollapsedSize = CGFloat(48) @objc static let newConversationButtonCollapsedSize = CGFloat(60)
@objc static let newConversationButtonExpandedSize = CGFloat(60) @objc static let newConversationButtonExpandedSize = CGFloat(72)
@objc static let textFieldHeight = isSmallScreen ? CGFloat(48) : CGFloat(80) @objc static let textFieldHeight = isSmallScreen ? CGFloat(48) : CGFloat(80)
@objc static let textFieldCornerRadius = CGFloat(8) @objc static let textFieldCornerRadius = CGFloat(8)
@objc static let separatorLabelHeight = CGFloat(24) @objc static let separatorLabelHeight = CGFloat(24)

Loading…
Cancel
Save