Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios

This commit is contained in:
Ilya Laktyushin
2023-06-24 15:49:13 +02:00
17 changed files with 213 additions and 64 deletions

View File

@@ -30,7 +30,7 @@ public final class ChatAvatarNavigationNode: ASDisplayNode {
private var avatarVideoNode: AvatarVideoNode?
public private(set) var avatarStoryView: ComponentView<Empty>?
public var hasUnseenStories: Bool?
public var storyData: (hasUnseen: Bool, hasUnseenCloseFriends: Bool)?
public let statusView: ComponentView<Empty>
@@ -78,7 +78,7 @@ public final class ChatAvatarNavigationNode: ASDisplayNode {
self.avatarNode.frame = self.containerNode.bounds
#if DEBUG
self.hasUnseenStories = true
//self.hasUnseenStories = true
#endif
}
@@ -200,7 +200,7 @@ public final class ChatAvatarNavigationNode: ASDisplayNode {
}
public func updateStoryView(transition: ContainedViewLayoutTransition, theme: PresentationTheme) {
if let hasUnseenStories = self.hasUnseenStories {
if let storyData = self.storyData {
let avatarStoryView: ComponentView<Empty>
if let current = self.avatarStoryView {
avatarStoryView = current
@@ -212,7 +212,8 @@ public final class ChatAvatarNavigationNode: ASDisplayNode {
let _ = avatarStoryView.update(
transition: Transition(transition),
component: AnyComponent(AvatarStoryIndicatorComponent(
hasUnseen: hasUnseenStories,
hasUnseen: storyData.hasUnseen,
hasUnseenCloseFriendsItems: storyData.hasUnseenCloseFriends,
isDarkTheme: theme.overallDarkAppearance,
activeLineWidth: 1.0,
inactiveLineWidth: 1.0,

View File

@@ -16,6 +16,7 @@ public final class AvatarStoryIndicatorComponent: Component {
}
public let hasUnseen: Bool
public let hasUnseenCloseFriendsItems: Bool
public let isDarkTheme: Bool
public let activeLineWidth: CGFloat
public let inactiveLineWidth: CGFloat
@@ -23,12 +24,14 @@ public final class AvatarStoryIndicatorComponent: Component {
public init(
hasUnseen: Bool,
hasUnseenCloseFriendsItems: Bool,
isDarkTheme: Bool,
activeLineWidth: CGFloat,
inactiveLineWidth: CGFloat,
counters: Counters?
) {
self.hasUnseen = hasUnseen
self.hasUnseenCloseFriendsItems = hasUnseenCloseFriendsItems
self.isDarkTheme = isDarkTheme
self.activeLineWidth = activeLineWidth
self.inactiveLineWidth = inactiveLineWidth
@@ -39,6 +42,9 @@ public final class AvatarStoryIndicatorComponent: Component {
if lhs.hasUnseen != rhs.hasUnseen {
return false
}
if lhs.hasUnseenCloseFriendsItems != rhs.hasUnseenCloseFriendsItems {
return false
}
if lhs.isDarkTheme != rhs.isDarkTheme {
return false
}
@@ -91,6 +97,29 @@ public final class AvatarStoryIndicatorComponent: Component {
self.indicatorView.image = generateImage(CGSize(width: imageDiameter, height: imageDiameter), rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size))
let activeColors: [CGColor]
let inactiveColors: [CGColor]
if component.hasUnseenCloseFriendsItems {
activeColors = [
UIColor(rgb: 0x7CD636).cgColor,
UIColor(rgb: 0x26B470).cgColor
]
} else {
activeColors = [
UIColor(rgb: 0x34C76F).cgColor,
UIColor(rgb: 0x3DA1FD).cgColor
]
}
if component.isDarkTheme {
inactiveColors = [UIColor(rgb: 0x48484A).cgColor, UIColor(rgb: 0x48484A).cgColor]
} else {
inactiveColors = [UIColor(rgb: 0xD8D8E1).cgColor, UIColor(rgb: 0xD8D8E1).cgColor]
}
var locations: [CGFloat] = [0.0, 1.0]
context.setLineWidth(lineWidth)
if let counters = component.counters, counters.totalCount > 1 {
@@ -124,16 +153,11 @@ public final class AvatarStoryIndicatorComponent: Component {
context.replacePathWithStrokedPath()
context.clip()
var locations: [CGFloat] = [1.0, 0.0]
let colors: [CGColor]
if pass == 1 {
colors = [UIColor(rgb: 0x34C76F).cgColor, UIColor(rgb: 0x3DA1FD).cgColor]
colors = activeColors
} else {
if component.isDarkTheme {
colors = [UIColor(rgb: 0x48484A).cgColor, UIColor(rgb: 0x48484A).cgColor]
} else {
colors = [UIColor(rgb: 0xD8D8E1).cgColor, UIColor(rgb: 0xD8D8E1).cgColor]
}
colors = inactiveColors
}
let colorSpace = CGColorSpaceCreateDeviceRGB()
@@ -148,16 +172,11 @@ public final class AvatarStoryIndicatorComponent: Component {
context.replacePathWithStrokedPath()
context.clip()
var locations: [CGFloat] = [1.0, 0.0]
let colors: [CGColor]
if component.hasUnseen {
colors = [UIColor(rgb: 0x34C76F).cgColor, UIColor(rgb: 0x3DA1FD).cgColor]
colors = activeColors
} else {
if component.isDarkTheme {
colors = [UIColor(rgb: 0x48484A).cgColor, UIColor(rgb: 0x48484A).cgColor]
} else {
colors = [UIColor(rgb: 0xD8D8E1).cgColor, UIColor(rgb: 0xD8D8E1).cgColor]
}
colors = inactiveColors
}
let colorSpace = CGColorSpaceCreateDeviceRGB()

View File

@@ -138,7 +138,8 @@ public final class StoryContentContextImpl: StoryContentContext {
isPinned: item.isPinned,
isExpired: item.isExpired,
isPublic: item.isPublic,
isPending: false
isPending: false,
isCloseFriends: item.isCloseFriends
)
}
if peerId == context.account.peerId, let stateView = views.views[PostboxViewKey.storiesState(key: .local)] as? StoryStatesView, let localState = stateView.value?.get(Stories.LocalState.self) {
@@ -155,7 +156,8 @@ public final class StoryContentContextImpl: StoryContentContext {
isPinned: item.pin,
isExpired: false,
isPublic: false,
isPending: true
isPending: true,
isCloseFriends: false
))
}
}
@@ -434,6 +436,7 @@ public final class StoryContentContextImpl: StoryContentContext {
items: [EngineStorySubscriptions.Item(
peer: peer,
hasUnseen: state.hasUnseen,
hasUnseenCloseFriends: state.hasUnseenCloseFriends,
storyCount: state.items.count,
unseenCount: 0,
lastTimestamp: state.items.last?.timestamp ?? 0
@@ -953,7 +956,8 @@ public final class SingleStoryContentContextImpl: StoryContentContext {
isPinned: itemValue.isPinned,
isExpired: itemValue.isExpired,
isPublic: itemValue.isPublic,
isPending: false
isPending: false,
isCloseFriends: itemValue.isCloseFriends
)
let stateValue = StoryContentContextState(

View File

@@ -603,6 +603,8 @@ public final class StoryPeerListComponent: Component {
var hasUnseen = false
hasUnseen = itemSet.hasUnseen
var hasUnseenCloseFriendsItems = itemSet.hasUnseenCloseFriends
var hasItems = true
var itemRingAnimation: StoryPeerListItemComponent.RingAnimation?
if peer.id == component.context.account.peerId {
@@ -614,6 +616,8 @@ public final class StoryPeerListComponent: Component {
if let uploadProgress = component.uploadProgress {
itemRingAnimation = .progress(uploadProgress)
}
hasUnseenCloseFriendsItems = false
}
let measuredItem = calculateItem(i)
@@ -655,6 +659,7 @@ public final class StoryPeerListComponent: Component {
strings: component.strings,
peer: peer,
hasUnseen: hasUnseen,
hasUnseenCloseFriendsItems: hasUnseenCloseFriendsItems,
hasItems: hasItems,
ringAnimation: itemRingAnimation,
collapseFraction: isReallyVisible ? (1.0 - collapsedState.maxFraction) : 0.0,

View File

@@ -266,6 +266,7 @@ public final class StoryPeerListItemComponent: Component {
public let strings: PresentationStrings
public let peer: EnginePeer
public let hasUnseen: Bool
public let hasUnseenCloseFriendsItems: Bool
public let hasItems: Bool
public let ringAnimation: RingAnimation?
public let collapseFraction: CGFloat
@@ -283,6 +284,7 @@ public final class StoryPeerListItemComponent: Component {
strings: PresentationStrings,
peer: EnginePeer,
hasUnseen: Bool,
hasUnseenCloseFriendsItems: Bool,
hasItems: Bool,
ringAnimation: RingAnimation?,
collapseFraction: CGFloat,
@@ -299,6 +301,7 @@ public final class StoryPeerListItemComponent: Component {
self.strings = strings
self.peer = peer
self.hasUnseen = hasUnseen
self.hasUnseenCloseFriendsItems = hasUnseenCloseFriendsItems
self.hasItems = hasItems
self.ringAnimation = ringAnimation
self.collapseFraction = collapseFraction
@@ -327,6 +330,9 @@ public final class StoryPeerListItemComponent: Component {
if lhs.hasUnseen != rhs.hasUnseen {
return false
}
if lhs.hasUnseenCloseFriendsItems != rhs.hasUnseenCloseFriendsItems {
return false
}
if lhs.hasItems != rhs.hasItems {
return false
}
@@ -646,7 +652,17 @@ public final class StoryPeerListItemComponent: Component {
let colors: [CGColor]
if component.hasUnseen || component.ringAnimation != nil {
colors = [UIColor(rgb: 0x34C76F).cgColor, UIColor(rgb: 0x3DA1FD).cgColor]
if component.hasUnseenCloseFriendsItems {
colors = [
UIColor(rgb: 0x7CD636).cgColor,
UIColor(rgb: 0x26B470).cgColor
]
} else {
colors = [
UIColor(rgb: 0x34C76F).cgColor,
UIColor(rgb: 0x3DA1FD).cgColor
]
}
} else {
if component.theme.overallDarkAppearance {
colors = [UIColor(rgb: 0x48484A).cgColor, UIColor(rgb: 0x48484A).cgColor]

View File

@@ -71,13 +71,13 @@ private final class ShapeImageView: UIView {
if let image = item.image {
context.translateBy(x: imageRect.midX, y: imageRect.midY)
context.scaleBy(x: 1.0, y: -1.0)
context.scaleBy(x: 1.0, y: 1.0)
context.translateBy(x: -imageRect.midX, y: -imageRect.midY)
image.draw(in: imageRect, blendMode: .normal, alpha: 1.0)
context.translateBy(x: imageRect.midX, y: imageRect.midY)
context.scaleBy(x: 1.0, y: -1.0)
context.scaleBy(x: 1.0, y: 1.0)
context.translateBy(x: -imageRect.midX, y: -imageRect.midY)
} else {
context.setFillColor(UIColor.black.cgColor)