Added selection ring for account avatar in tabbar

Added separate text colors for authorization sequence screens
This commit is contained in:
Ilya Laktyushin 2019-09-20 23:53:46 +03:00
parent 4408dc8f5a
commit 64d2284980
11 changed files with 76 additions and 28 deletions

View File

@ -17,14 +17,16 @@ public func textAlertController(context: AccountContext, title: String?, text: S
return controller
}
public func richTextAlertController(context: AccountContext, title: NSAttributedString?, text: NSAttributedString, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal) -> AlertController {
public func richTextAlertController(context: AccountContext, title: NSAttributedString?, text: NSAttributedString, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal, dismissAutomatically: Bool = true) -> AlertController {
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let theme = AlertControllerTheme(presentationTheme: presentationData.theme)
var dismissImpl: (() -> Void)?
let controller = AlertController(theme: theme, contentNode: TextAlertContentNode(theme: theme, title: title, text: text, actions: actions.map { action in
return TextAlertAction(type: action.type, title: action.title, action: {
dismissImpl?()
if dismissAutomatically {
dismissImpl?()
}
action.action()
})
}, actionLayout: actionLayout))

View File

@ -341,14 +341,14 @@ class TabBarNode: ASDisplayNode {
let previousTextImageSize = node.textImageNode.image?.size ?? CGSize()
if let selectedIndex = self.selectedIndex, selectedIndex == index {
let (textImage, contentWidth) = tabBarItemImage(item.selectedImage, title: item.title ?? "", backgroundColor: .clear, tintColor: self.theme.tabBarSelectedTextColor, horizontal: self.horizontal, imageMode: false)
let (image, imageContentWidth) = tabBarItemImage(item.selectedImage, title: item.title ?? "", backgroundColor: .clear, tintColor: self.theme.tabBarSelectedTextColor, horizontal: self.horizontal, imageMode: true)
let (image, imageContentWidth) = tabBarItemImage(item.selectedImage, title: item.title ?? "", backgroundColor: .clear, tintColor: self.theme.tabBarSelectedIconColor, horizontal: self.horizontal, imageMode: true)
node.textImageNode.image = textImage
node.accessibilityLabel = item.title
node.imageNode.image = image
node.contentWidth = max(contentWidth, imageContentWidth)
} else {
let (textImage, contentWidth) = tabBarItemImage(item.image, title: item.title ?? "", backgroundColor: .clear, tintColor: self.theme.tabBarTextColor, horizontal: self.horizontal, imageMode: false)
let (image, imageContentWidth) = tabBarItemImage(item.image, title: item.title ?? "", backgroundColor: .clear, tintColor: self.theme.tabBarTextColor, horizontal: self.horizontal, imageMode: true)
let (image, imageContentWidth) = tabBarItemImage(item.image, title: item.title ?? "", backgroundColor: .clear, tintColor: self.theme.tabBarIconColor, horizontal: self.horizontal, imageMode: true)
node.textImageNode.image = textImage
node.accessibilityLabel = item.title
node.imageNode.image = image

View File

@ -356,7 +356,7 @@ public func textAlertController(theme: AlertControllerTheme, title: NSAttributed
public func standardTextAlertController(theme: AlertControllerTheme, title: String?, text: String, actions: [TextAlertAction], actionLayout: TextAlertContentActionLayout = .horizontal) -> AlertController {
var dismissImpl: (() -> Void)?
let controller = AlertController(theme: theme, contentNode: TextAlertContentNode(theme: theme, title: title != nil ? NSAttributedString(string: title!, font: Font.medium(17.0), textColor: theme.primaryColor, paragraphAlignment: .center) : nil, text: NSAttributedString(string: text, font: title == nil ? Font.semibold(17.0) : Font.regular(13.0), textColor: theme.primaryColor, paragraphAlignment: .center), actions: actions.map { action in
let controller = AlertController(theme: theme, contentNode: TextAlertContentNode(theme: theme, title: title != nil ? NSAttributedString(string: title!, font: Font.semibold(17.0), textColor: theme.primaryColor, paragraphAlignment: .center) : nil, text: NSAttributedString(string: text, font: title == nil ? Font.semibold(17.0) : Font.regular(13.0), textColor: theme.primaryColor, paragraphAlignment: .center), actions: actions.map { action in
return TextAlertAction(type: action.type, title: action.title, action: {
dismissImpl?()
action.action()

View File

@ -1278,34 +1278,56 @@ public func settingsController(context: AccountContext, accountManager: AccountM
}
|> distinctUntilChanged
let accountTabBarAvatar: Signal<UIImage?, NoError> = accountsAndPeers.get()
|> map { primary, other -> (Account, Peer)? in
if let primary = primary, !other.isEmpty {
return (primary.0, primary.1)
let accountTabBarAvatar: Signal<(UIImage, UIImage)?, NoError> = combineLatest(accountsAndPeers.get(), updatedPresentationData)
|> map { primaryAndOther, presentationData -> (Account, Peer, PresentationTheme)? in
if let primary = primaryAndOther.0, !primaryAndOther.1.isEmpty {
return (primary.0, primary.1, presentationData.theme)
} else {
return nil
}
}
|> distinctUntilChanged(isEqual: { $0?.0 === $1?.0 && arePeersEqual($0?.1, $1?.1) })
|> mapToSignal { primary -> Signal<UIImage?, NoError> in
|> mapToSignal { primary -> Signal<(UIImage, UIImage)?, NoError> in
if let primary = primary {
if let signal = peerAvatarImage(account: primary.0, peer: primary.1, authorOfMessage: nil, representation: primary.1.profileImageRepresentations.first, displayDimensions: CGSize(width: 31.0, height: 31.0), inset: 3.0, emptyColor: nil, synchronousLoad: false) {
let size = CGSize(width: 31.0, height: 31.0)
let inset: CGFloat = 3.0
if let signal = peerAvatarImage(account: primary.0, peer: primary.1, authorOfMessage: nil, representation: primary.1.profileImageRepresentations.first, displayDimensions: size, inset: 3.0, emptyColor: nil, synchronousLoad: false) {
return signal
|> map { image -> UIImage? in
return image.flatMap { image -> UIImage in
return image.withRenderingMode(.alwaysOriginal)
|> map { image -> (UIImage, UIImage)? in
if let image = image, let selectedImage = generateImage(size, rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size))
context.translateBy(x: size.width / 2.0, y: size.height / 2.0)
context.scaleBy(x: 1.0, y: -1.0)
context.translateBy(x: -size.width / 2.0, y: -size.height / 2.0)
context.draw(image.cgImage!, in: CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height))
context.setLineWidth(1.0)
context.setStrokeColor(primary.2.rootController.tabBar.selectedIconColor.cgColor)
context.strokeEllipse(in: CGRect(x: 1.5, y: 1.5, width: 28.0, height: 28.0))
}) {
return (image.withRenderingMode(.alwaysOriginal), selectedImage.withRenderingMode(.alwaysOriginal))
} else {
return nil
}
}
} else {
return Signal { subscriber in
let size = CGSize(width: 31.0, height: 31.0)
let inset: CGFloat = 3.0
let image = generateImage(size, rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size))
context.translateBy(x: inset, y: inset)
drawPeerAvatarLetters(context: context, size: CGSize(width: size.width - inset * 2.0, height: size.height - inset * 2.0), font: avatarFont, letters: primary.1.displayLetters, accountPeerId: primary.1.id, peerId: primary.1.id)
})?.withRenderingMode(.alwaysOriginal)
subscriber.putNext(image)
let selectedImage = generateImage(size, rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size))
context.translateBy(x: inset, y: inset)
drawPeerAvatarLetters(context: context, size: CGSize(width: size.width - inset * 2.0, height: size.height - inset * 2.0), font: avatarFont, letters: primary.1.displayLetters, accountPeerId: primary.1.id, peerId: primary.1.id)
context.translateBy(x: -inset, y: -inset)
context.setLineWidth(1.0)
context.setStrokeColor(primary.2.rootController.tabBar.selectedIconColor.cgColor)
context.strokeEllipse(in: CGRect(x: 1.0, y: 1.0, width: 27.0, height: 27.0))
})?.withRenderingMode(.alwaysOriginal)
subscriber.putNext(image.flatMap { ($0, $0) })
subscriber.putCompletion()
return EmptyDisposable
}
@ -1316,7 +1338,13 @@ public func settingsController(context: AccountContext, accountManager: AccountM
}
}
|> distinctUntilChanged(isEqual: { lhs, rhs in
if lhs !== rhs {
if let lhs = lhs, let rhs = rhs {
if lhs.0 !== rhs.0 || lhs.1 !== rhs.1 {
return false
} else {
return true
}
} else if (lhs == nil) != (rhs == nil) {
return false
}
return true
@ -1329,7 +1357,7 @@ public func settingsController(context: AccountContext, accountManager: AccountM
if accountTabBarAvatarBadge > 0 {
otherAccountsBadge = compactNumericCountString(Int(accountTabBarAvatarBadge), decimalSeparator: presentationData.dateTimeFormat.decimalSeparator)
}
return ItemListControllerTabBarItem(title: presentationData.strings.Settings_Title, image: accountTabBarAvatar ?? icon, selectedImage: accountTabBarAvatar ?? icon, tintImages: accountTabBarAvatar == nil, badgeValue: notificationsWarning ? "!" : otherAccountsBadge)
return ItemListControllerTabBarItem(title: presentationData.strings.Settings_Title, image: accountTabBarAvatar?.0 ?? icon, selectedImage: accountTabBarAvatar?.1 ?? icon, tintImages: accountTabBarAvatar == nil, badgeValue: notificationsWarning ? "!" : otherAccountsBadge)
}
let controller = SettingsControllerImpl(currentContext: context, contextValue: contextValue, state: signal, tabBarItem: tabBarItem, accountsAndPeers: accountsAndPeers.get())

View File

@ -101,6 +101,9 @@ private func makeDarkPresentationTheme(accentColor: UIColor, baseColor: Presenta
let intro = PresentationThemeIntro(
statusBarStyle: .white,
primaryTextColor: .white,
accentTextColor: accentColor,
disabledTextColor: UIColor(rgb: 0x525252),
startButtonColor: accentColor,
dotColor: UIColor(rgb: 0x5e5e5e)
)

View File

@ -53,7 +53,7 @@ private func makeDarkPresentationTheme(accentColor: UIColor, baseColor: Presenta
let rootNavigationBar = PresentationThemeRootNavigationBar(
buttonColor: accentColor,
disabledButtonColor: accentColor.withMultiplied(hue: 1.033, saturation: 0.219, brightness: 0.44),
primaryTextColor: UIColor(rgb: 0xffffff),
primaryTextColor: .white,
secondaryTextColor: mainSecondaryColor,
controlColor: mainSecondaryColor,
accentTextColor: accentColor,
@ -77,6 +77,9 @@ private func makeDarkPresentationTheme(accentColor: UIColor, baseColor: Presenta
let intro = PresentationThemeIntro(
statusBarStyle: .white,
primaryTextColor: .white,
accentTextColor: accentColor,
disabledTextColor: accentColor.withMultiplied(hue: 1.033, saturation: 0.219, brightness: 0.44),
startButtonColor: accentColor,
dotColor: mainSecondaryColor
)

View File

@ -84,6 +84,9 @@ private func makeDefaultDayPresentationTheme(accentColor: UIColor, serviceBackgr
let intro = PresentationThemeIntro(
statusBarStyle: .black,
primaryTextColor: .black,
accentTextColor: accentColor,
disabledTextColor: UIColor(rgb: 0xd0d0d0),
startButtonColor: UIColor(rgb: 0x2ca5e0),
dotColor: UIColor(rgb: 0xd9d9d9)
)

View File

@ -20,11 +20,17 @@ public final class PresentationThemeGradientColors {
public final class PresentationThemeIntro {
public let statusBarStyle: PresentationThemeStatusBarStyle
public let primaryTextColor: UIColor
public let accentTextColor: UIColor
public let disabledTextColor: UIColor
public let startButtonColor: UIColor
public let dotColor: UIColor
public init(statusBarStyle: PresentationThemeStatusBarStyle, startButtonColor: UIColor, dotColor: UIColor) {
public init(statusBarStyle: PresentationThemeStatusBarStyle, primaryTextColor: UIColor, accentTextColor: UIColor, disabledTextColor: UIColor, startButtonColor: UIColor, dotColor: UIColor) {
self.statusBarStyle = statusBarStyle
self.primaryTextColor = primaryTextColor
self.accentTextColor = accentTextColor
self.disabledTextColor = disabledTextColor
self.startButtonColor = startButtonColor
self.dotColor = dotColor
}

View File

@ -238,6 +238,9 @@ extension PresentationThemeGradientColors: Codable {
extension PresentationThemeIntro: Codable {
enum CodingKeys: String, CodingKey {
case statusBar
case primaryText
case accentText
case disabledText
case startButton
case dot
}
@ -245,6 +248,9 @@ extension PresentationThemeIntro: Codable {
public convenience init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
self.init(statusBarStyle: try values.decode(PresentationThemeStatusBarStyle.self, forKey: .statusBar),
primaryTextColor: try decodeColor(values, .primaryText),
accentTextColor: try decodeColor(values, .accentText),
disabledTextColor: try decodeColor(values, .disabledText),
startButtonColor: try decodeColor(values, .startButton),
dotColor: try decodeColor(values, .dot))
}
@ -252,6 +258,9 @@ extension PresentationThemeIntro: Codable {
public func encode(to encoder: Encoder) throws {
var values = encoder.container(keyedBy: CodingKeys.self)
try values.encode(self.statusBarStyle, forKey: .statusBar)
try encodeColor(&values, self.primaryTextColor, .primaryText)
try encodeColor(&values, self.accentTextColor, .accentText)
try encodeColor(&values, self.disabledTextColor, .disabledText)
try encodeColor(&values, self.startButtonColor, .startButton)
try encodeColor(&values, self.dotColor, .dot)
}

View File

@ -25,7 +25,7 @@ private enum InnerState: Equatable {
public final class AuthorizationSequenceController: NavigationController, MFMailComposeViewControllerDelegate {
static func navigationBarTheme(_ theme: PresentationTheme) -> NavigationBarTheme {
return NavigationBarTheme(buttonColor: theme.rootController.navigationBar.buttonColor, disabledButtonColor: theme.rootController.navigationBar.disabledButtonColor, primaryTextColor: theme.rootController.navigationBar.primaryTextColor, backgroundColor: .clear, separatorColor: .clear, badgeBackgroundColor: theme.rootController.navigationBar.badgeBackgroundColor, badgeStrokeColor: theme.rootController.navigationBar.badgeStrokeColor, badgeTextColor: theme.rootController.navigationBar.badgeTextColor)
return NavigationBarTheme(buttonColor: theme.intro.accentTextColor, disabledButtonColor: theme.intro.disabledTextColor, primaryTextColor: theme.intro.primaryTextColor, backgroundColor: .clear, separatorColor: .clear, badgeBackgroundColor: theme.rootController.navigationBar.badgeBackgroundColor, badgeStrokeColor: theme.rootController.navigationBar.badgeStrokeColor, badgeTextColor: theme.rootController.navigationBar.badgeTextColor)
}
private let sharedContext: SharedAccountContext

View File

@ -4718,12 +4718,6 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
completion(.immediate)
}
// if let selectionState = self.presentationInterfaceState.interfaceState.selectionState, !selectionState.selectedIds.isEmpty {
// self.chatTitleView?.titleContent = .custom(self.presentationData.strings.Conversation_SelectedMessages(Int32(selectionState.selectedIds.count)))
// } else {
//
// }
if let button = leftNavigationButtonForChatInterfaceState(updatedChatPresentationInterfaceState, subject: self.subject, strings: updatedChatPresentationInterfaceState.strings, currentButton: self.leftNavigationButton, target: self, selector: #selector(self.leftNavigationButtonAction)) {
if self.leftNavigationButton != button {
var animated = transition.isAnimated