Skip to content

Commit a42f04b

Browse files
committed
Various improvements
1 parent e4d5a06 commit a42f04b

File tree

4 files changed

+53
-20
lines changed

4 files changed

+53
-20
lines changed

submodules/TelegramUI/Components/PeerInfo/PeerInfoCoverComponent/Sources/PeerInfoGiftsCoverComponent.swift

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ public final class PeerInfoGiftsCoverComponent: Component {
1919
public let giftsContext: ProfileGiftsContext
2020
public let hasBackground: Bool
2121
public let avatarCenter: CGPoint
22+
public let defaultHeight: CGFloat
2223
public let avatarTransitionFraction: CGFloat
2324
public let statusBarHeight: CGFloat
2425
public let topLeftButtonsSize: CGSize
2526
public let topRightButtonsSize: CGSize
2627
public let titleWidth: CGFloat
27-
public let hasButtons: Bool
28+
public let bottomHeight: CGFloat
2829
public let action: (ProfileGiftsContext.State.StarGift) -> Void
2930

3031
public init(
@@ -33,25 +34,27 @@ public final class PeerInfoGiftsCoverComponent: Component {
3334
giftsContext: ProfileGiftsContext,
3435
hasBackground: Bool,
3536
avatarCenter: CGPoint,
37+
defaultHeight: CGFloat,
3638
avatarTransitionFraction: CGFloat,
3739
statusBarHeight: CGFloat,
3840
topLeftButtonsSize: CGSize,
3941
topRightButtonsSize: CGSize,
4042
titleWidth: CGFloat,
41-
hasButtons: Bool,
43+
bottomHeight: CGFloat,
4244
action: @escaping (ProfileGiftsContext.State.StarGift) -> Void
4345
) {
4446
self.context = context
4547
self.peerId = peerId
4648
self.giftsContext = giftsContext
4749
self.hasBackground = hasBackground
4850
self.avatarCenter = avatarCenter
51+
self.defaultHeight = defaultHeight
4952
self.avatarTransitionFraction = avatarTransitionFraction
5053
self.statusBarHeight = statusBarHeight
5154
self.topLeftButtonsSize = topLeftButtonsSize
5255
self.topRightButtonsSize = topRightButtonsSize
5356
self.titleWidth = titleWidth
54-
self.hasButtons = hasButtons
57+
self.bottomHeight = bottomHeight
5558
self.action = action
5659
}
5760

@@ -68,6 +71,9 @@ public final class PeerInfoGiftsCoverComponent: Component {
6871
if lhs.avatarCenter != rhs.avatarCenter {
6972
return false
7073
}
74+
if lhs.defaultHeight != rhs.defaultHeight {
75+
return false
76+
}
7177
if lhs.avatarTransitionFraction != rhs.avatarTransitionFraction {
7278
return false
7379
}
@@ -83,7 +89,7 @@ public final class PeerInfoGiftsCoverComponent: Component {
8389
if lhs.titleWidth != rhs.titleWidth {
8490
return false
8591
}
86-
if lhs.hasButtons != rhs.hasButtons {
92+
if lhs.bottomHeight != rhs.bottomHeight {
8793
return false
8894
}
8995
return true
@@ -196,20 +202,25 @@ public final class PeerInfoGiftsCoverComponent: Component {
196202
}
197203

198204
if !giftIds.isEmpty && (self.iconPositions.isEmpty || previousCurrentSize?.width != availableSize.width || (previousComponent != nil && previousComponent?.hasBackground != component.hasBackground) || self.appliedGiftIds != giftIds) {
205+
var avatarCenter = component.avatarCenter
206+
if avatarCenter.y < 0.0 {
207+
avatarCenter.y = component.statusBarHeight + 75.0
208+
}
209+
199210
var excludeRects: [CGRect] = []
200211
if component.statusBarHeight > 0.0 {
201212
excludeRects.append(CGRect(origin: .zero, size: CGSize(width: availableSize.width, height: component.statusBarHeight + 4.0)))
202213
}
203214
excludeRects.append(CGRect(origin: CGPoint(x: 0.0, y: component.statusBarHeight), size: component.topLeftButtonsSize))
204215
excludeRects.append(CGRect(origin: CGPoint(x: availableSize.width - component.topRightButtonsSize.width, y: component.statusBarHeight), size: component.topRightButtonsSize))
205-
excludeRects.append(CGRect(origin: CGPoint(x: floor((availableSize.width - component.titleWidth) / 2.0), y: component.avatarCenter.y + 56.0), size: CGSize(width: component.titleWidth, height: 72.0)))
206-
if component.hasButtons {
207-
excludeRects.append(CGRect(origin: CGPoint(x: 0.0, y: availableSize.height - 81.0), size: CGSize(width: availableSize.width, height: 81.0)))
216+
excludeRects.append(CGRect(origin: CGPoint(x: floor((availableSize.width - component.titleWidth) / 2.0), y: avatarCenter.y + 56.0), size: CGSize(width: component.titleWidth, height: 72.0)))
217+
if component.bottomHeight > 0.0 {
218+
excludeRects.append(CGRect(origin: CGPoint(x: 0.0, y: component.defaultHeight - component.bottomHeight), size: CGSize(width: availableSize.width, height: component.bottomHeight)))
208219
}
209-
220+
210221
let positionGenerator = PositionGenerator(
211-
containerSize: availableSize,
212-
centerFrame: CGSize(width: 100, height: 100).centered(around: component.avatarCenter),
222+
containerSize: CGSize(width: availableSize.width, height: component.defaultHeight),
223+
centerFrame: CGSize(width: 100, height: 100).centered(around: avatarCenter),
213224
exclusionZones: excludeRects,
214225
minimumDistance: 42.0,
215226
edgePadding: 5.0,
@@ -581,7 +592,7 @@ private class GiftIconLayer: SimpleLayer {
581592
let hoverDuration = TimeInterval.random(in: 3.5 ..< 4.5)
582593

583594
let hoverAnimation = CABasicAnimation(keyPath: "transform.translation.y")
584-
hoverAnimation.duration = duration
595+
hoverAnimation.duration = hoverDuration
585596
hoverAnimation.fromValue = -upDistance
586597
hoverAnimation.toValue = downDistance
587598
hoverAnimation.autoreverses = true

submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ func peerInfoScreenSettingsData(context: AccountContext, peerId: EnginePeer.Id,
954954
}
955955
}
956956

957-
func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, isSettings: Bool, isMyProfile: Bool, hintGroupInCommon: PeerId?, existingRequestsContext: PeerInvitationImportersContext?, chatLocation: ChatLocation, chatLocationContextHolder: Atomic<ChatLocationContextHolder?>, privacySettings: Signal<AccountPrivacySettings?, NoError>, forceHasGifts: Bool) -> Signal<PeerInfoScreenData, NoError> {
957+
func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat, isSettings: Bool, isMyProfile: Bool, hintGroupInCommon: PeerId?, existingRequestsContext: PeerInvitationImportersContext?, existingProfileGiftsContext: ProfileGiftsContext?, chatLocation: ChatLocation, chatLocationContextHolder: Atomic<ChatLocationContextHolder?>, privacySettings: Signal<AccountPrivacySettings?, NoError>, forceHasGifts: Bool) -> Signal<PeerInfoScreenData, NoError> {
958958
return peerInfoScreenInputData(context: context, peerId: peerId, isSettings: isSettings)
959959
|> mapToSignal { inputData -> Signal<PeerInfoScreenData, NoError> in
960960
let wasUpgradedGroup = Atomic<Bool?>(value: nil)
@@ -1021,7 +1021,7 @@ func peerInfoScreenData(context: AccountContext, peerId: PeerId, strings: Presen
10211021
let profileGiftsContext: ProfileGiftsContext?
10221022
if case .user = kind {
10231023
if isMyProfile || userPeerId != context.account.peerId {
1024-
profileGiftsContext = ProfileGiftsContext(account: context.account, peerId: userPeerId)
1024+
profileGiftsContext = existingProfileGiftsContext ?? ProfileGiftsContext(account: context.account, peerId: userPeerId)
10251025
} else {
10261026
profileGiftsContext = nil
10271027
}

submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoHeaderNode.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,12 +2351,13 @@ final class PeerInfoHeaderNode: ASDisplayNode {
23512351
giftsContext: profileGiftsContext,
23522352
hasBackground: hasBackground,
23532353
avatarCenter: apparentAvatarFrame.center,
2354+
defaultHeight: backgroundDefaultHeight,
23542355
avatarTransitionFraction: max(0.0, min(1.0, titleCollapseFraction + transitionFraction * 2.0)),
23552356
statusBarHeight: statusBarHeight,
23562357
topLeftButtonsSize: CGSize(width: (self.isSettings ? 57.0 : 47.0), height: 46.0),
23572358
topRightButtonsSize: CGSize(width: 76.0 + (self.isMyProfile ? 38.0 : 0.0), height: 46.0),
2358-
titleWidth: titleFrame.width + 42.0,
2359-
hasButtons: !buttonKeys.isEmpty,
2359+
titleWidth: max(140.0, titleFrame.width) + 42.0,
2360+
bottomHeight: !buttonKeys.isEmpty ? 81.0 : 30.0,
23602361
action: { [weak self] gift in
23612362
guard let self, case let .unique(gift) = gift.gift else {
23622363
return

submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/PeerInfoScreen.swift

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,7 +2903,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
29032903
}
29042904
private var didSetReady = false
29052905

2906-
init(controller: PeerInfoScreenImpl, context: AccountContext, peerId: PeerId, avatarInitiallyExpanded: Bool, isOpenedFromChat: Bool, nearbyPeerDistance: Int32?, reactionSourceMessageId: MessageId?, callMessages: [Message], isSettings: Bool, isMyProfile: Bool, hintGroupInCommon: PeerId?, requestsContext: PeerInvitationImportersContext?, starsContext: StarsContext?, chatLocation: ChatLocation, chatLocationContextHolder: Atomic<ChatLocationContextHolder?>, initialPaneKey: PeerInfoPaneKey?) {
2906+
init(controller: PeerInfoScreenImpl, context: AccountContext, peerId: PeerId, avatarInitiallyExpanded: Bool, isOpenedFromChat: Bool, nearbyPeerDistance: Int32?, reactionSourceMessageId: MessageId?, callMessages: [Message], isSettings: Bool, isMyProfile: Bool, hintGroupInCommon: PeerId?, requestsContext: PeerInvitationImportersContext?, profileGiftsContext: ProfileGiftsContext?, starsContext: StarsContext?, chatLocation: ChatLocation, chatLocationContextHolder: Atomic<ChatLocationContextHolder?>, initialPaneKey: PeerInfoPaneKey?) {
29072907
self.controller = controller
29082908
self.context = context
29092909
self.peerId = peerId
@@ -4649,7 +4649,7 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
46494649
self.privacySettings.set(.single(nil))
46504650
}
46514651

4652-
screenData = peerInfoScreenData(context: context, peerId: peerId, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, isSettings: self.isSettings, isMyProfile: self.isMyProfile, hintGroupInCommon: hintGroupInCommon, existingRequestsContext: requestsContext, chatLocation: self.chatLocation, chatLocationContextHolder: self.chatLocationContextHolder, privacySettings: self.privacySettings.get(), forceHasGifts: initialPaneKey == .gifts)
4652+
screenData = peerInfoScreenData(context: context, peerId: peerId, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, isSettings: self.isSettings, isMyProfile: self.isMyProfile, hintGroupInCommon: hintGroupInCommon, existingRequestsContext: requestsContext, existingProfileGiftsContext: profileGiftsContext, chatLocation: self.chatLocation, chatLocationContextHolder: self.chatLocationContextHolder, privacySettings: self.privacySettings.get(), forceHasGifts: initialPaneKey == .gifts)
46534653

46544654
var previousTimestamp: Double?
46554655
self.headerNode.displayPremiumIntro = { [weak self] sourceView, peerStatus, emojiStatusFileAndPack, white in
@@ -10183,7 +10183,8 @@ final class PeerInfoScreenNode: ViewControllerTracingNode, PeerInfoScreenNodePro
1018310183
nearbyPeerDistance: nil,
1018410184
reactionSourceMessageId: nil,
1018510185
callMessages: [],
10186-
isMyProfile: true
10186+
isMyProfile: true,
10187+
profileGiftsContext: self.data?.profileGiftsContext
1018710188
))
1018810189
case .stories:
1018910190
push(PeerInfoStoryGridScreen(context: self.context, peerId: self.context.account.peerId, scope: .saved))
@@ -12592,6 +12593,7 @@ public final class PeerInfoScreenImpl: ViewController, PeerInfoScreen, KeyShortc
1259212593
let isMyProfile: Bool
1259312594
private let hintGroupInCommon: PeerId?
1259412595
private weak var requestsContext: PeerInvitationImportersContext?
12596+
private weak var profileGiftsContext: ProfileGiftsContext?
1259512597
fileprivate let starsContext: StarsContext?
1259612598
private let switchToRecommendedChannels: Bool
1259712599
private let switchToGifts: Bool
@@ -12652,7 +12654,25 @@ public final class PeerInfoScreenImpl: ViewController, PeerInfoScreen, KeyShortc
1265212654

1265312655
private var validLayout: (layout: ContainerViewLayout, navigationHeight: CGFloat)?
1265412656

12655-
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)?, peerId: PeerId, avatarInitiallyExpanded: Bool, isOpenedFromChat: Bool, nearbyPeerDistance: Int32?, reactionSourceMessageId: MessageId?, callMessages: [Message], isSettings: Bool = false, isMyProfile: Bool = false, hintGroupInCommon: PeerId? = nil, requestsContext: PeerInvitationImportersContext? = nil, forumTopicThread: ChatReplyThreadMessage? = nil, switchToRecommendedChannels: Bool = false, switchToGifts: Bool = false, switchToGroupsInCommon: Bool = false) {
12657+
public init(
12658+
context: AccountContext,
12659+
updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)?,
12660+
peerId: PeerId,
12661+
avatarInitiallyExpanded: Bool,
12662+
isOpenedFromChat: Bool,
12663+
nearbyPeerDistance: Int32?,
12664+
reactionSourceMessageId: MessageId?,
12665+
callMessages: [Message],
12666+
isSettings: Bool = false,
12667+
isMyProfile: Bool = false,
12668+
hintGroupInCommon: PeerId? = nil,
12669+
requestsContext: PeerInvitationImportersContext? = nil,
12670+
profileGiftsContext: ProfileGiftsContext? = nil,
12671+
forumTopicThread: ChatReplyThreadMessage? = nil,
12672+
switchToRecommendedChannels: Bool = false,
12673+
switchToGifts: Bool = false,
12674+
switchToGroupsInCommon: Bool = false
12675+
) {
1265612676
self.context = context
1265712677
self.updatedPresentationData = updatedPresentationData
1265812678
self.peerId = peerId
@@ -12665,6 +12685,7 @@ public final class PeerInfoScreenImpl: ViewController, PeerInfoScreen, KeyShortc
1266512685
self.isMyProfile = isMyProfile
1266612686
self.hintGroupInCommon = hintGroupInCommon
1266712687
self.requestsContext = requestsContext
12688+
self.profileGiftsContext = profileGiftsContext
1266812689
self.switchToRecommendedChannels = switchToRecommendedChannels
1266912690
self.switchToGifts = switchToGifts
1267012691
self.switchToGroupsInCommon = switchToGroupsInCommon
@@ -13016,7 +13037,7 @@ public final class PeerInfoScreenImpl: ViewController, PeerInfoScreen, KeyShortc
1301613037
} else if self.switchToGroupsInCommon {
1301713038
initialPaneKey = .groupsInCommon
1301813039
}
13019-
self.displayNode = PeerInfoScreenNode(controller: self, context: self.context, peerId: self.peerId, avatarInitiallyExpanded: self.avatarInitiallyExpanded, isOpenedFromChat: self.isOpenedFromChat, nearbyPeerDistance: self.nearbyPeerDistance, reactionSourceMessageId: self.reactionSourceMessageId, callMessages: self.callMessages, isSettings: self.isSettings, isMyProfile: self.isMyProfile, hintGroupInCommon: self.hintGroupInCommon, requestsContext: self.requestsContext, starsContext: self.starsContext, chatLocation: self.chatLocation, chatLocationContextHolder: self.chatLocationContextHolder, initialPaneKey: initialPaneKey)
13040+
self.displayNode = PeerInfoScreenNode(controller: self, context: self.context, peerId: self.peerId, avatarInitiallyExpanded: self.avatarInitiallyExpanded, isOpenedFromChat: self.isOpenedFromChat, nearbyPeerDistance: self.nearbyPeerDistance, reactionSourceMessageId: self.reactionSourceMessageId, callMessages: self.callMessages, isSettings: self.isSettings, isMyProfile: self.isMyProfile, hintGroupInCommon: self.hintGroupInCommon, requestsContext: self.requestsContext, profileGiftsContext: self.profileGiftsContext, starsContext: self.starsContext, chatLocation: self.chatLocation, chatLocationContextHolder: self.chatLocationContextHolder, initialPaneKey: initialPaneKey)
1302013041
self.controllerNode.accountsAndPeers.set(self.accountsAndPeers.get() |> map { $0.1 })
1302113042
self.controllerNode.activeSessionsContextAndCount.set(self.activeSessionsContextAndCount.get())
1302213043
self.cachedDataPromise.set(self.controllerNode.cachedDataPromise.get())

0 commit comments

Comments
 (0)