From 0386b856a17feac0d7c16584c8cf05e31af89f8f Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Tue, 14 Apr 2020 16:11:22 +1000 Subject: [PATCH] Fix animation and hook up PN mode screen --- .../Components/NewConversationButtonSet.swift | 28 +++++++++++++++---- .../Loki/View Controllers/DisplayNameVC.swift | 5 ++-- .../src/Loki/View Controllers/PNModeVC.swift | 17 ++++++++--- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Signal/src/Loki/Components/NewConversationButtonSet.swift b/Signal/src/Loki/Components/NewConversationButtonSet.swift index 882100af0..32591f69e 100644 --- a/Signal/src/Loki/Components/NewConversationButtonSet.swift +++ b/Signal/src/Loki/Components/NewConversationButtonSet.swift @@ -158,7 +158,7 @@ final class NewConversationButtonSet : UIView { self.layoutIfNeeded() button.frame = frame button.layer.cornerRadius = size / 2 - button.setGlow(to: size, with: Colors.newConversationButtonShadow) + button.setGlow(to: size, with: Colors.newConversationButtonShadow, animated: true) button.backgroundColor = Colors.accent } } @@ -183,7 +183,7 @@ final class NewConversationButtonSet : UIView { button.frame = frame button.layer.cornerRadius = size / 2 let glowColor = isLightMode ? UIColor.black.withAlphaComponent(0.4) : UIColor.black - button.setGlow(to: size, with: glowColor) + button.setGlow(to: size, with: glowColor, animated: true) button.backgroundColor = Colors.newConversationButtonCollapsedBackground } } @@ -230,7 +230,7 @@ private final class NewConversationButton : UIImageView { let size = Values.newConversationButtonCollapsedSize layer.cornerRadius = size / 2 let glowColor = isMainButton ? Colors.newConversationButtonShadow : (isLightMode ? UIColor.black.withAlphaComponent(0.4) : UIColor.black) - setGlow(to: size, with: glowColor) + setGlow(to: size, with: glowColor, animated: false) layer.masksToBounds = false let iconColor = (isMainButton && isLightMode) ? UIColor.white : Colors.text image = icon.asTintedImage(color: iconColor)! @@ -240,9 +240,25 @@ private final class NewConversationButton : UIImageView { } // General - 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.shadowColor = color.cgColor + func setGlow(to size: CGFloat, with color: UIColor, animated isAnimated: Bool) { + let newPath = UIBezierPath(ovalIn: CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: size, height: size))).cgPath + if isAnimated { + let pathAnimation = CABasicAnimation(keyPath: "shadowPath") + pathAnimation.fromValue = layer.shadowPath + pathAnimation.toValue = newPath + pathAnimation.duration = 0.25 + layer.add(pathAnimation, forKey: pathAnimation.keyPath) + } + layer.shadowPath = newPath + let newColor = color.cgColor + if isAnimated { + let colorAnimation = CABasicAnimation(keyPath: "shadowColor") + colorAnimation.fromValue = layer.shadowColor + colorAnimation.toValue = newColor + colorAnimation.duration = 0.25 + layer.add(colorAnimation, forKey: colorAnimation.keyPath) + } + layer.shadowColor = newColor layer.shadowOffset = CGSize(width: 0, height: 0.8) layer.shadowOpacity = isLightMode ? 0.4 : 1 layer.shadowRadius = isLightMode ? 4 : 6 diff --git a/Signal/src/Loki/View Controllers/DisplayNameVC.swift b/Signal/src/Loki/View Controllers/DisplayNameVC.swift index d603deda7..c65dad94d 100644 --- a/Signal/src/Loki/View Controllers/DisplayNameVC.swift +++ b/Signal/src/Loki/View Controllers/DisplayNameVC.swift @@ -152,9 +152,8 @@ final class DisplayNameVC : BaseVC { guard !OWSProfileManager.shared().isProfileNameTooLong(displayName) else { return showError(title: NSLocalizedString("Please pick a shorter display name", comment: "")) } - TSAccountManager.sharedInstance().didRegister() OWSProfileManager.shared().updateLocalProfileName(displayName, avatarImage: nil, success: { }, failure: { _ in }, requiresSync: false) // Try to save the user name but ignore the result - let homeVC = HomeVC() - navigationController!.setViewControllers([ homeVC ], animated: true) + let pnModeVC = PNModeVC() + navigationController!.pushViewController(pnModeVC, animated: true) } } diff --git a/Signal/src/Loki/View Controllers/PNModeVC.swift b/Signal/src/Loki/View Controllers/PNModeVC.swift index 8d0d1922c..d9330256c 100644 --- a/Signal/src/Loki/View Controllers/PNModeVC.swift +++ b/Signal/src/Loki/View Controllers/PNModeVC.swift @@ -87,7 +87,9 @@ final class PNModeVC : BaseVC, OptionViewDelegate { } @objc private func register() { - // TODO: Implement + TSAccountManager.sharedInstance().didRegister() + let homeVC = HomeVC() + navigationController!.setViewControllers([ homeVC ], animated: true) } } @@ -162,9 +164,15 @@ private extension PNModeVC { private func handleIsSelectedChanged() { let animationDuration: TimeInterval = 0.25 - UIView.animate(withDuration: animationDuration) { - self.backgroundColor = self.isSelected ? Colors.accent : Colors.buttonBackground - } + // Animate border color + let newBorderColor = isSelected ? Colors.accent.cgColor : Colors.pnOptionBorder.cgColor + let borderAnimation = CABasicAnimation(keyPath: "borderColor") + borderAnimation.fromValue = layer.shadowColor + borderAnimation.toValue = newBorderColor + borderAnimation.duration = animationDuration + layer.add(borderAnimation, forKey: borderAnimation.keyPath) + layer.borderColor = newBorderColor + // Animate shadow color let newShadowColor = isSelected ? Colors.newConversationButtonShadow.cgColor : UIColor.black.cgColor let shadowAnimation = CABasicAnimation(keyPath: "shadowColor") shadowAnimation.fromValue = layer.shadowColor @@ -172,6 +180,7 @@ private extension PNModeVC { shadowAnimation.duration = animationDuration layer.add(shadowAnimation, forKey: shadowAnimation.keyPath) layer.shadowColor = newShadowColor + // Notify delegate if isSelected { delegate.optionViewDidActivate(self) } } }