Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a.rychkov/contest fixes #24

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions TelegramUI/ChatDocumentGalleryItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private final class ChatDocumentURLProtocol: URLProtocol {
}
}

class ChatDocumentGalleryItemNode: GalleryItemNode, WKNavigationDelegate {
class ChatDocumentGalleryItemNode: ZoomableContentGalleryItemNode, WKNavigationDelegate {
fileprivate let _title = Promise<String>()

private let statusNodeContainer: HighlightableButtonNode
Expand Down Expand Up @@ -127,9 +127,9 @@ class ChatDocumentGalleryItemNode: GalleryItemNode, WKNavigationDelegate {
self.statusNode.isHidden = true

super.init()
self.view.addSubview(self.webView)

self.view.insertSubview(self.webView, belowSubview: self.scrollNode.view)

self.statusNodeContainer.addSubnode(self.statusNode)
self.addSubnode(self.statusNodeContainer)

Expand Down
4 changes: 3 additions & 1 deletion TelegramUI/ChatMessageInteractiveFileNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,9 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
if strongSelf.waveformScrubbingNode == nil {
let waveformScrubbingNode = MediaPlayerScrubbingNode(content: .custom(backgroundNode: strongSelf.waveformNode, foregroundContentNode: strongSelf.waveformForegroundNode))
waveformScrubbingNode.hitTestSlop = UIEdgeInsetsMake(-10.0, 0.0, -10.0, 0.0)
waveformScrubbingNode.seek = { timestamp in
waveformScrubbingNode.seek = { timestamp, isContinuous in
guard !isContinuous else { return }

if let strongSelf = self, let context = strongSelf.context, let message = strongSelf.message, let type = peerMessageMediaPlayerType(message) {
context.sharedContext.mediaManager.playlistControl(.seek(timestamp), type: type)
}
Expand Down
2 changes: 1 addition & 1 deletion TelegramUI/ChatTextInputAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ func convertMarkdownToAttributes(_ text: NSAttributedString) -> NSAttributedStri
while let match = regex.firstMatch(in: string as String, range: NSMakeRange(0, string.length)) {
let matchIndex = stringOffset + match.range.location

result.append(text.attributedSubstring(from: NSMakeRange(0, match.range.location)))
result.append(text.attributedSubstring(from: NSMakeRange(text.length - string.length, match.range.location)))

var pre = match.range(at: 3)
if pre.location != NSNotFound {
Expand Down
15 changes: 12 additions & 3 deletions TelegramUI/ChatVideoGalleryItemScrubberView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class ChatVideoGalleryItemScrubberView: UIView {
}
}

var seek: (Double) -> Void = { _ in }
var seek: (_ timestamp: Double, _ isContinuous: Bool) -> Void = { _, _ in }

override init(frame: CGRect) {
self.scrubberNode = MediaPlayerScrubbingNode(content: .standard(lineHeight: 5.0, lineCap: .round, scrubberHandle: .circle, backgroundColor: UIColor(white: 1.0, alpha: 0.42), foregroundColor: .white))
Expand All @@ -57,8 +57,8 @@ final class ChatVideoGalleryItemScrubberView: UIView {

super.init(frame: frame)

self.scrubberNode.seek = { [weak self] timestamp in
self?.seek(timestamp)
self.scrubberNode.seek = { [weak self] timestamp, isContinuous in
self?.seek(timestamp, isContinuous)
}

self.scrubberNode.playerStatusUpdated = { [weak self] status in
Expand Down Expand Up @@ -163,4 +163,13 @@ final class ChatVideoGalleryItemScrubberView: UIView {

self.scrubberNode.frame = CGRect(origin: CGPoint(x: scrubberInset, y: 6.0), size: CGSize(width: size.width - leftInset - rightInset - scrubberInset * 2.0, height: scrubberHeight))
}

override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
var hitTestRect = self.bounds
let minHeightDiff = 44.0 - hitTestRect.height
if (minHeightDiff > 0) {
hitTestRect = bounds.insetBy(dx: 0, dy: -minHeightDiff / 2.0)
}
return hitTestRect.contains(point)
}
}
13 changes: 7 additions & 6 deletions TelegramUI/InstantPageAudioNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ final class InstantPageAudioNode: ASDisplayNode, InstantPageNode {
}
}

self.scrubbingNode.seek = { [weak self] timestamp in
if let strongSelf = self {
if let _ = strongSelf.playbackState {
strongSelf.context.sharedContext.mediaManager.playlistControl(.seek(timestamp), type: strongSelf.playlistType)
}
}
self.scrubbingNode.seek = { [weak self] timestamp, isContinuous in
guard !isContinuous,
let strongSelf = self,
let _ = strongSelf.playbackState
else { return }

strongSelf.context.sharedContext.mediaManager.playlistControl(.seek(timestamp), type: strongSelf.playlistType)
}

/*if let applicationContext = account.applicationContext as? TelegramApplicationContext, let (playlistId, itemId) = instantPageAudioPlaylistAndItemIds(webpage: webpage, media: self.media) {
Expand Down
40 changes: 28 additions & 12 deletions TelegramUI/ItemListRevealOptionsNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private final class ItemListRevealOptionNode: ASDisplayNode {
self.animationNode?.reset()
}

func updateLayout(isFirst: Bool, isLeft: Bool, baseSize: CGSize, alignment: ItemListRevealOptionAlignment, isExpanded: Bool, extendedWidth: CGFloat, sideInset: CGFloat, transition: ContainedViewLayoutTransition, additive: Bool, revealFactor: CGFloat) {
func updateLayout(isFirst: Bool, isLeft: Bool, baseSize: CGSize, alignment: ItemListRevealOptionAlignment, isExpanded: Bool, extendedWidth: CGFloat, sideInset: CGFloat, transition: ContainedViewLayoutTransition, additive: Bool, revealFactor: CGFloat, animateIconMovement: Bool) {
self.highlightNode.frame = CGRect(origin: CGPoint(), size: baseSize)

var animateAdditive = false
Expand All @@ -163,7 +163,9 @@ private final class ItemListRevealOptionNode: ASDisplayNode {
} else {
deltaX = -(previousFrame.width - backgroundFrame.width)
}
transition.animatePositionAdditive(node: self.backgroundNode, offset: CGPoint(x: deltaX, y: 0.0))
if !animateIconMovement {
transition.animatePositionAdditive(node: self.backgroundNode, offset: CGPoint(x: deltaX, y: 0.0))
}
} else {
deltaX = 0.0
transition.updateFrame(node: self.backgroundNode, frame: backgroundFrame)
Expand All @@ -185,20 +187,22 @@ private final class ItemListRevealOptionNode: ASDisplayNode {
let titleIconSpacing: CGFloat = 11.0
let iconFrame = CGRect(origin: CGPoint(x: contentRect.minX + floor((baseSize.width - imageSize.width + sideInset) / 2.0), y: contentRect.midY - imageSize.height / 2.0 + iconOffset), size: imageSize)
if animateAdditive {
let iconOffsetX = animateIconMovement ? animationNode.frame.minX - iconFrame.minX : deltaX
animationNode.frame = iconFrame
transition.animatePositionAdditive(node: animationNode, offset: CGPoint(x: deltaX, y: 0.0))
transition.animatePositionAdditive(node: animationNode, offset: CGPoint(x: iconOffsetX, y: 0.0))
} else {
transition.updateFrame(node: animationNode, frame: iconFrame)
}

let titleFrame = CGRect(origin: CGPoint(x: contentRect.minX + floor((baseSize.width - titleSize.width + sideInset) / 2.0), y: contentRect.midY + titleIconSpacing), size: titleSize)
if animateAdditive {
let titleOffsetX = animateIconMovement ? self.titleNode.frame.minX - titleFrame.minX : deltaX
self.titleNode.frame = titleFrame
transition.animatePositionAdditive(node: self.titleNode, offset: CGPoint(x: deltaX, y: 0.0))
transition.animatePositionAdditive(node: self.titleNode, offset: CGPoint(x: titleOffsetX, y: 0.0))
} else {
transition.updateFrame(node: self.titleNode, frame: titleFrame)
}

if (abs(revealFactor) >= 0.4) {
animationNode.play()
} else if abs(revealFactor) < CGFloat.ulpOfOne && !transition.isAnimated {
Expand All @@ -209,24 +213,27 @@ private final class ItemListRevealOptionNode: ASDisplayNode {
let titleIconSpacing: CGFloat = 11.0
let iconFrame = CGRect(origin: CGPoint(x: contentRect.minX + floor((baseSize.width - imageSize.width + sideInset) / 2.0), y: contentRect.midY - imageSize.height / 2.0 + iconOffset), size: imageSize)
if animateAdditive {
let iconOffsetX = animateIconMovement ? iconNode.frame.minX - iconFrame.minX : deltaX
iconNode.frame = iconFrame
transition.animatePositionAdditive(node: iconNode, offset: CGPoint(x: deltaX, y: 0.0))
transition.animatePositionAdditive(node: iconNode, offset: CGPoint(x: iconOffsetX, y: 0.0))
} else {
transition.updateFrame(node: iconNode, frame: iconFrame)
}

let titleFrame = CGRect(origin: CGPoint(x: contentRect.minX + floor((baseSize.width - titleSize.width + sideInset) / 2.0), y: contentRect.midY + titleIconSpacing), size: titleSize)
if animateAdditive {
let titleOffsetX = animateIconMovement ? self.titleNode.frame.minX - titleFrame.minX : deltaX
self.titleNode.frame = titleFrame
transition.animatePositionAdditive(node: self.titleNode, offset: CGPoint(x: deltaX, y: 0.0))
transition.animatePositionAdditive(node: self.titleNode, offset: CGPoint(x: titleOffsetX, y: 0.0))
} else {
transition.updateFrame(node: self.titleNode, frame: titleFrame)
}
} else {
let titleFrame = CGRect(origin: CGPoint(x: contentRect.minX + floor((baseSize.width - titleSize.width + sideInset) / 2.0), y: contentRect.minY + floor((baseSize.height - titleSize.height) / 2.0)), size: titleSize)
if animateAdditive {
let titleOffsetX = animateIconMovement ? self.titleNode.frame.minX - titleFrame.minX : deltaX
self.titleNode.frame = titleFrame
transition.animatePositionAdditive(node: self.titleNode, offset: CGPoint(x: deltaX, y: 0.0))
transition.animatePositionAdditive(node: self.titleNode, offset: CGPoint(x: titleOffsetX, y: 0.0))
} else {
transition.updateFrame(node: self.titleNode, frame: titleFrame)
}
Expand Down Expand Up @@ -355,7 +362,6 @@ final class ItemListRevealOptionsNode: ASDisplayNode {
while i >= 0 && i < self.optionNodes.count {
let node = self.optionNodes[i]
let nodeWidth = i == (self.optionNodes.count - 1) ? lastNodeWidth : basicNodeWidth
let defaultAlignment: ItemListRevealOptionAlignment = self.isLeft ? .right : .left
var nodeTransition = transition
var isExpanded = false
if (self.isLeft && i == 0) || (!self.isLeft && i == self.optionNodes.count - 1) {
Expand All @@ -364,7 +370,7 @@ final class ItemListRevealOptionsNode: ASDisplayNode {
}
}
if let _ = node.alignment, node.isExpanded != isExpanded {
nodeTransition = transition.isAnimated ? transition : .animated(duration: 0.2, curve: .spring)
nodeTransition = transition.isAnimated ? transition : .animated(duration: 0.2, curve: .easeInOut)
if !transition.isAnimated {
self.tapticAction()
}
Expand Down Expand Up @@ -393,9 +399,19 @@ final class ItemListRevealOptionsNode: ASDisplayNode {
transition.updateFrame(node: node, frame: CGRect(origin: CGPoint(x: nodeLeftOffset, y: 0.0), size: CGSize(width: extendedWidth, height: size.height)), completion: { _ in
completionCount -= 1
intermediateCompletion()

})
node.updateLayout(isFirst: (self.isLeft && i == 0) || (!self.isLeft && i == self.optionNodes.count - 1), isLeft: self.isLeft, baseSize: CGSize(width: nodeWidth, height: size.height), alignment: defaultAlignment, isExpanded: isExpanded, extendedWidth: extendedWidth, sideInset: sideInset, transition: nodeTransition, additive: !transition.isAnimated, revealFactor: revealFactor)
var nodeAlignment: ItemListRevealOptionAlignment
if (self.optionNodes.count > 1) {
nodeAlignment = self.isLeft ? .right : .left
} else {
if (self.isLeft) {
nodeAlignment = isExpanded ? .right : .left
} else {
nodeAlignment = isExpanded ? .left : .right
}
}
let animateIconMovement = self.optionNodes.count == 1
node.updateLayout(isFirst: (self.isLeft && i == 0) || (!self.isLeft && i == self.optionNodes.count - 1), isLeft: self.isLeft, baseSize: CGSize(width: nodeWidth, height: size.height), alignment: nodeAlignment, isExpanded: isExpanded, extendedWidth: extendedWidth, sideInset: sideInset, transition: nodeTransition, additive: !transition.isAnimated, revealFactor: revealFactor, animateIconMovement: animateIconMovement)

if self.isLeft {
i -= 1
Expand Down
Loading