mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-08 12:24:39 +00:00
Adjust layout
This commit is contained in:
@@ -121,6 +121,19 @@ private final class ExpandItemView: UIView {
|
||||
}
|
||||
|
||||
public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
private struct ItemLayout {
|
||||
var itemSize: CGFloat
|
||||
var visibleItemCount: Int
|
||||
|
||||
init(
|
||||
itemSize: CGFloat,
|
||||
visibleItemCount: Int
|
||||
) {
|
||||
self.itemSize = itemSize
|
||||
self.visibleItemCount = visibleItemCount
|
||||
}
|
||||
}
|
||||
|
||||
private let context: AccountContext
|
||||
private let presentationData: PresentationData
|
||||
private let animationCache: AnimationCache
|
||||
@@ -157,7 +170,7 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
private var continuousHaptic: Any?
|
||||
private var validLayout: (CGSize, UIEdgeInsets, CGRect)?
|
||||
private var isLeftAligned: Bool = true
|
||||
private var visibleItemCount: Int?
|
||||
private var itemLayout: ItemLayout?
|
||||
|
||||
private var customReactionSource: (view: UIView, rect: CGRect, layer: CALayer, item: ReactionItem)?
|
||||
|
||||
@@ -525,13 +538,13 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
}
|
||||
|
||||
private func updateScrolling(transition: ContainedViewLayoutTransition) {
|
||||
guard let visibleItemCount = self.visibleItemCount else {
|
||||
guard let itemLayout = self.itemLayout else {
|
||||
return
|
||||
}
|
||||
|
||||
let sideInset: CGFloat = 6.0
|
||||
let itemSpacing: CGFloat = 8.0
|
||||
let itemSize: CGFloat = 36.0
|
||||
let itemSize: CGFloat = itemLayout.itemSize
|
||||
|
||||
let containerHeight: CGFloat = 46.0
|
||||
var contentHeight: CGFloat = containerHeight
|
||||
@@ -571,13 +584,13 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
|
||||
var topVisibleItems: Int
|
||||
if self.getEmojiContent != nil {
|
||||
topVisibleItems = min(self.items.count, visibleItemCount)
|
||||
topVisibleItems = min(self.items.count, itemLayout.visibleItemCount)
|
||||
} else {
|
||||
topVisibleItems = self.items.count
|
||||
}
|
||||
|
||||
var loopIdle = false
|
||||
for i in 0 ..< min(self.items.count, visibleItemCount) {
|
||||
for i in 0 ..< min(self.items.count, itemLayout.visibleItemCount) {
|
||||
if let reaction = self.items[i].reaction {
|
||||
switch reaction.rawValue {
|
||||
case .builtin:
|
||||
@@ -710,7 +723,7 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
if self.getEmojiContent != nil && i == visibleItemCount - 1 {
|
||||
if self.getEmojiContent != nil && i == itemLayout.visibleItemCount - 1 {
|
||||
itemFrame.origin.x -= (1.0 - compressionFactor) * selectionItemFrame.width * 0.5
|
||||
selectionItemFrame.origin.x -= (1.0 - compressionFactor) * selectionItemFrame.width * 0.5
|
||||
itemNode.isUserInteractionEnabled = false
|
||||
@@ -749,7 +762,7 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
itemNode.appear(animated: !self.context.sharedContext.currentPresentationData.with({ $0 }).reduceMotion)
|
||||
}
|
||||
|
||||
if self.getEmojiContent != nil && i == visibleItemCount - 1 {
|
||||
if self.getEmojiContent != nil && i == itemLayout.visibleItemCount - 1 {
|
||||
transition.updateSublayerTransformScale(node: itemNode, scale: 0.001 * (1.0 - compressionFactor) + normalItemScale * compressionFactor)
|
||||
|
||||
let alphaFraction = min(compressionFactor, 0.2) / 0.2
|
||||
@@ -816,7 +829,7 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
let externalSideInset: CGFloat = 4.0
|
||||
let sideInset: CGFloat = 6.0
|
||||
let itemSpacing: CGFloat = 8.0
|
||||
let itemSize: CGFloat = 36.0
|
||||
var itemSize: CGFloat = 36.0
|
||||
let verticalInset: CGFloat = 13.0
|
||||
let rowHeight: CGFloat = 30.0
|
||||
|
||||
@@ -828,6 +841,12 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
let totalItemSlotCount = self.items.count + 1
|
||||
|
||||
var maxRowItemCount = Int(floor((size.width - sideInset * 2.0 - externalSideInset * 2.0 - itemSpacing) / (itemSize + itemSpacing)))
|
||||
|
||||
if maxRowItemCount < 8 {
|
||||
itemSize = floor((size.width - sideInset * 2.0 - externalSideInset * 2.0 - itemSpacing - 8 * itemSpacing) / 8.0)
|
||||
maxRowItemCount = Int(floor((size.width - sideInset * 2.0 - externalSideInset * 2.0 - itemSpacing) / (itemSize + itemSpacing)))
|
||||
}
|
||||
|
||||
maxRowItemCount = min(maxRowItemCount, 8)
|
||||
itemCount = min(totalItemSlotCount, maxRowItemCount)
|
||||
if self.isExpanded {
|
||||
@@ -860,7 +879,11 @@ public final class ReactionContextNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
|
||||
let (actualBackgroundFrame, visualBackgroundFrame, isLeftAligned, cloudSourcePoint) = self.calculateBackgroundFrame(containerSize: CGSize(width: size.width, height: size.height), insets: backgroundInsets, anchorRect: anchorRect, contentSize: CGSize(width: visibleContentWidth, height: contentHeight))
|
||||
self.isLeftAligned = isLeftAligned
|
||||
self.visibleItemCount = itemCount
|
||||
|
||||
self.itemLayout = ItemLayout(
|
||||
itemSize: itemSize,
|
||||
visibleItemCount: itemCount
|
||||
)
|
||||
|
||||
var scrollFrame = CGRect(origin: CGPoint(x: 0.0, y: self.isExpanded ? 46.0 : 0.0), size: actualBackgroundFrame.size)
|
||||
scrollFrame.origin.y += floorToScreenPixels(self.extensionDistance / 2.0)
|
||||
|
||||
@@ -620,6 +620,14 @@ public final class EmojiStatusSelectionController: ViewController {
|
||||
transition = Transition(animation: .curve(duration: 0.4, curve: .spring)).withUserData(contentAnimation)
|
||||
}
|
||||
|
||||
var componentWidth = layout.size.width - sideInset * 2.0
|
||||
let nativeItemSize: CGFloat = 40.0
|
||||
let minSpacing: CGFloat = 9.0
|
||||
let itemsPerRow = Int((componentWidth + minSpacing) / (nativeItemSize + minSpacing))
|
||||
if itemsPerRow > 8 {
|
||||
componentWidth = min(componentWidth, 480.0)
|
||||
}
|
||||
|
||||
let componentSize = self.componentHost.update(
|
||||
transition: transition,
|
||||
component: AnyComponent(EmojiStatusSelectionComponent(
|
||||
@@ -631,7 +639,7 @@ public final class EmojiStatusSelectionController: ViewController {
|
||||
separatorColor: separatorColor
|
||||
)),
|
||||
environment: {},
|
||||
containerSize: CGSize(width: layout.size.width - sideInset * 2.0, height: min(308.0, layout.size.height))
|
||||
containerSize: CGSize(width: componentWidth, height: min(308.0, layout.size.height))
|
||||
)
|
||||
if let componentView = self.componentHost.view {
|
||||
var animateIn = false
|
||||
@@ -643,7 +651,7 @@ public final class EmojiStatusSelectionController: ViewController {
|
||||
componentView.layer.cornerRadius = 24.0
|
||||
}
|
||||
|
||||
let sourceOrigin: CGPoint
|
||||
var sourceOrigin: CGPoint
|
||||
if let sourceView = self.sourceView {
|
||||
let sourceRect = sourceView.convert(sourceView.bounds, to: self.view)
|
||||
sourceOrigin = CGPoint(x: sourceRect.midX, y: sourceRect.maxY)
|
||||
@@ -654,7 +662,11 @@ public final class EmojiStatusSelectionController: ViewController {
|
||||
sourceOrigin = CGPoint(x: layout.size.width / 2.0, y: floor(layout.size.height / 2.0 - componentSize.height))
|
||||
}
|
||||
|
||||
let componentFrame = CGRect(origin: CGPoint(x: sideInset, y: sourceOrigin.y + 5.0), size: componentSize)
|
||||
if sourceOrigin.y + 5.0 + componentSize.height > layout.size.height - layout.insets(options: []).bottom {
|
||||
sourceOrigin.y = layout.size.height - layout.insets(options: []).bottom - componentSize.height - 5.0
|
||||
}
|
||||
|
||||
let componentFrame = CGRect(origin: CGPoint(x: floor((layout.size.width - componentSize.width) / 2.0), y: sourceOrigin.y + 5.0), size: componentSize)
|
||||
|
||||
if self.componentShadowLayer.bounds.size != componentFrame.size {
|
||||
let componentShadowPath = UIBezierPath(roundedRect: CGRect(origin: CGPoint(), size: componentFrame.size), cornerRadius: 24.0).cgPath
|
||||
|
||||
@@ -213,7 +213,8 @@ class ChatMessageForwardInfoNode: ASDisplayNode {
|
||||
highlight = false
|
||||
}
|
||||
|
||||
let completeString: NSString = (completeSourceString.string.replacingOccurrences(of: "\n", with: " \n")) as NSString
|
||||
//let completeString: NSString = (completeSourceString.string.replacingOccurrences(of: "\n", with: " \n")) as NSString
|
||||
let completeString: NSString = completeSourceString.string as NSString
|
||||
let string = NSMutableAttributedString(string: completeString as String, attributes: [NSAttributedString.Key.foregroundColor: titleColor, NSAttributedString.Key.font: prefixFont])
|
||||
if highlight, let range = completeSourceString.ranges.first?.range {
|
||||
string.addAttributes([NSAttributedString.Key.font: peerFont], range: range)
|
||||
|
||||
Reference in New Issue
Block a user