Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
laktyushin committed Feb 15, 2024
1 parent e709318 commit cc4089a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 18 deletions.
24 changes: 20 additions & 4 deletions submodules/AvatarNode/Sources/AvatarNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,16 @@ public final class AvatarNode: ASDisplayNode {
private struct Params: Equatable {
let peerId: EnginePeer.Id?
let resourceId: String?
let clipStyle: AvatarNodeClipStyle

init(
peerId: EnginePeer.Id?,
resourceId: String?
resourceId: String?,
clipStyle: AvatarNodeClipStyle
) {
self.peerId = peerId
self.resourceId = resourceId
self.clipStyle = clipStyle
}
}

Expand Down Expand Up @@ -315,6 +318,15 @@ public final class AvatarNode: ASDisplayNode {
private var params: Params?
private var loadDisposable: Disposable?

var clipStyle: AvatarNodeClipStyle {
if let params = self.params {
return params.clipStyle
} else if case let .peerAvatar(_, _, _, _, clipStyle) = self.state {
return clipStyle
}
return .none
}

public var badgeView: AvatarBadgeView? {
didSet {
if self.badgeView !== oldValue {
Expand Down Expand Up @@ -516,6 +528,7 @@ public final class AvatarNode: ASDisplayNode {
} else if peer?.restrictionText(platform: "ios", contentSettings: contentSettings) == nil {
representation = peer?.smallProfileImage
}

let updatedState: AvatarNodeState = .peerAvatar(peer?.id ?? EnginePeer.Id(0), peer?.nameColor, peer?.displayLetters ?? [], representation, clipStyle)
if updatedState != self.state || overrideImage != self.overrideImage || theme !== self.theme {
self.state = updatedState
Expand Down Expand Up @@ -599,7 +612,8 @@ public final class AvatarNode: ASDisplayNode {
let smallProfileImage = peer?.smallProfileImage
let params = Params(
peerId: peer?.id,
resourceId: smallProfileImage?.resource.id.stringRepresentation
resourceId: smallProfileImage?.resource.id.stringRepresentation,
clipStyle: clipStyle
)
if self.params == params {
return
Expand Down Expand Up @@ -689,6 +703,7 @@ public final class AvatarNode: ASDisplayNode {
} else if peer?.restrictionText(platform: "ios", contentSettings: genericContext.currentContentSettings.with { $0 }) == nil {
representation = peer?.smallProfileImage
}

let updatedState: AvatarNodeState = .peerAvatar(peer?.id ?? EnginePeer.Id(0), peer?.nameColor, peer?.displayLetters ?? [], representation, clipStyle)
if updatedState != self.state || overrideImage != self.overrideImage || theme !== self.theme {
self.state = updatedState
Expand Down Expand Up @@ -1236,7 +1251,7 @@ public final class AvatarNode: ASDisplayNode {
}

let size = self.bounds.size

if let storyStats = self.storyStats {
let activeLineWidth = storyPresentationParams.lineWidth
let inactiveLineWidth = storyPresentationParams.inactiveLineWidth
Expand Down Expand Up @@ -1274,7 +1289,8 @@ public final class AvatarNode: ASDisplayNode {
totalCount: storyStats.totalCount,
unseenCount: storyStats.unseenCount
),
progress: mappedProgress
progress: mappedProgress,
isRoundedRect: self.contentNode.clipStyle == .roundedRect
)),
environment: {},
containerSize: indicatorSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public final class AvatarStoryIndicatorComponent: Component {
public let inactiveLineWidth: CGFloat
public let counters: Counters?
public let progress: Progress?
public let isRoundedRect: Bool

public init(
hasUnseen: Bool,
Expand All @@ -58,7 +59,8 @@ public final class AvatarStoryIndicatorComponent: Component {
activeLineWidth: CGFloat,
inactiveLineWidth: CGFloat,
counters: Counters?,
progress: Progress? = nil
progress: Progress? = nil,
isRoundedRect: Bool = false
) {
self.hasUnseen = hasUnseen
self.hasUnseenCloseFriendsItems = hasUnseenCloseFriendsItems
Expand All @@ -67,6 +69,7 @@ public final class AvatarStoryIndicatorComponent: Component {
self.inactiveLineWidth = inactiveLineWidth
self.counters = counters
self.progress = progress
self.isRoundedRect = isRoundedRect
}

public static func ==(lhs: AvatarStoryIndicatorComponent, rhs: AvatarStoryIndicatorComponent) -> Bool {
Expand All @@ -91,6 +94,9 @@ public final class AvatarStoryIndicatorComponent: Component {
if lhs.progress != rhs.progress {
return false
}
if lhs.isRoundedRect != rhs.isRoundedRect {
return false
}
return true
}

Expand Down Expand Up @@ -211,7 +217,7 @@ public final class AvatarStoryIndicatorComponent: Component {
}
}

func update(size: CGSize, radius: CGFloat, lineWidth: CGFloat, value: Value, transition: Transition) {
func update(size: CGSize, radius: CGFloat, isRoundedRect: Bool, lineWidth: CGFloat, value: Value, transition: Transition) {
let params = Params(
size: size,
lineWidth: lineWidth,
Expand Down Expand Up @@ -295,7 +301,7 @@ public final class AvatarStoryIndicatorComponent: Component {

var locations: [CGFloat] = [0.0, 1.0]

if let counters = component.counters, counters.totalCount > 1 {
if let counters = component.counters, counters.totalCount > 1, !component.isRoundedRect {
let center = CGPoint(x: size.width * 0.5, y: size.height * 0.5)
let spacing: CGFloat = component.activeLineWidth * 2.0
let angularSpacing: CGFloat = spacing / radius
Expand Down Expand Up @@ -347,7 +353,11 @@ public final class AvatarStoryIndicatorComponent: Component {
} else {
let lineWidth: CGFloat = component.hasUnseen ? component.activeLineWidth : component.inactiveLineWidth
context.setLineWidth(lineWidth)
context.addEllipse(in: CGRect(origin: CGPoint(x: size.width * 0.5 - diameter * 0.5, y: size.height * 0.5 - diameter * 0.5), size: size).insetBy(dx: lineWidth * 0.5, dy: lineWidth * 0.5))
if component.isRoundedRect {
context.addPath(UIBezierPath(roundedRect: CGRect(origin: CGPoint(x: size.width * 0.5 - diameter * 0.5, y: size.height * 0.5 - diameter * 0.5), size: size).insetBy(dx: lineWidth * 0.5, dy: lineWidth * 0.5), cornerRadius: floor(diameter * 0.25)).cgPath)
} else {
context.addEllipse(in: CGRect(origin: CGPoint(x: size.width * 0.5 - diameter * 0.5, y: size.height * 0.5 - diameter * 0.5), size: size).insetBy(dx: lineWidth * 0.5, dy: lineWidth * 0.5))
}

context.replacePathWithStrokedPath()
context.clip()
Expand All @@ -369,7 +379,7 @@ public final class AvatarStoryIndicatorComponent: Component {
transition.setFrame(view: self.indicatorView, frame: indicatorFrame)

let progressTransition = Transition(animation: .curve(duration: 0.3, curve: .easeInOut))
if let progress = component.progress {
if let progress = component.progress, !component.isRoundedRect {
let colorLayer: SimpleGradientLayer
if let current = self.colorLayer {
colorLayer = current
Expand Down Expand Up @@ -415,7 +425,7 @@ public final class AvatarStoryIndicatorComponent: Component {
mappedProgress = .progress(value)
}

progressLayer.update(size: indicatorFrame.size, radius: radius, lineWidth: lineWidth, value: mappedProgress, transition: .immediate)
progressLayer.update(size: indicatorFrame.size, radius: radius, isRoundedRect: component.isRoundedRect, lineWidth: lineWidth, value: mappedProgress, transition: .immediate)
} else {
progressTransition.setAlpha(view: self.indicatorView, alpha: 1.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ public class VideoMessageCameraScreen: ViewController {

if let controller = self.controller, let layout = self.validLayout {
let insets = layout.insets(options: .input)
if point.y > layout.size.height - insets.bottom - controller.inputPanelFrame.height {
if point.y > layout.size.height - insets.bottom - controller.inputPanelFrame.0.height {
if layout.metrics.isTablet {
if point.x < layout.size.width * 0.33 {
return result
Expand Down Expand Up @@ -1111,9 +1111,9 @@ public class VideoMessageCameraScreen: ViewController {
self.didAppear()
}

var backgroundFrame = CGRect(origin: .zero, size: CGSize(width: layout.size.width, height: controller.inputPanelFrame.minY))
if backgroundFrame.maxY < layout.size.height - 100.0 && (layout.inputHeight ?? 0.0).isZero {
backgroundFrame = CGRect(origin: .zero, size: CGSize(width: layout.size.width, height: layout.size.height - layout.intrinsicInsets.bottom - controller.inputPanelFrame.height))
var backgroundFrame = CGRect(origin: .zero, size: CGSize(width: layout.size.width, height: controller.inputPanelFrame.0.minY))
if backgroundFrame.maxY < layout.size.height - 100.0 && (layout.inputHeight ?? 0.0).isZero && !controller.inputPanelFrame.1 {
backgroundFrame = CGRect(origin: .zero, size: CGSize(width: layout.size.width, height: layout.size.height - layout.intrinsicInsets.bottom - controller.inputPanelFrame.0.height))
}

transition.setPosition(view: self.backgroundView, position: backgroundFrame.center)
Expand Down Expand Up @@ -1266,7 +1266,7 @@ public class VideoMessageCameraScreen: ViewController {

private let context: AccountContext
private let updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)?
private let inputPanelFrame: CGRect
private let inputPanelFrame: (CGRect, Bool)
fileprivate var allowLiveUpload: Bool
fileprivate var viewOnceAvailable: Bool

Expand Down Expand Up @@ -1417,7 +1417,7 @@ public class VideoMessageCameraScreen: ViewController {
updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)?,
allowLiveUpload: Bool,
viewOnceAvailable: Bool,
inputPanelFrame: CGRect,
inputPanelFrame: (CGRect, Bool),
chatNode: ASDisplayNode?,
completion: @escaping (EnqueueMessage?, Bool?, Int32?) -> Void
) {
Expand Down
2 changes: 1 addition & 1 deletion submodules/TelegramUI/Sources/ChatController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14087,7 +14087,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
updatedPresentationData: self.updatedPresentationData,
allowLiveUpload: peerId.namespace != Namespaces.Peer.SecretChat,
viewOnceAvailable: !isScheduledMessages && peerId.namespace == Namespaces.Peer.CloudUser && peerId != self.context.account.peerId && !isBot,
inputPanelFrame: currentInputPanelFrame,
inputPanelFrame: (currentInputPanelFrame, self.chatDisplayNode.inputNode != nil),
chatNode: self.chatDisplayNode.historyNode,
completion: { [weak self] message, silentPosting, scheduleTime in
guard let self, let videoController = self.videoRecorderValue else {
Expand Down
2 changes: 1 addition & 1 deletion submodules/TelegramUI/Sources/ChatControllerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
private let inputContextOverTextPanelContainer: ChatControllerTitlePanelNodeContainer
private var overlayContextPanelNode: ChatInputContextPanelNode?

private var inputNode: ChatInputNode?
private(set) var inputNode: ChatInputNode?
private var disappearingNode: ChatInputNode?

private(set) var textInputPanelNode: ChatTextInputPanelNode?
Expand Down

0 comments on commit cc4089a

Please sign in to comment.