Fix voice chat expanded avatar position

This commit is contained in:
Ilya Laktyushin 2021-03-24 23:01:47 +05:00
parent c863952605
commit 5f3bab6261
3 changed files with 42 additions and 27 deletions

View File

@ -1271,7 +1271,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
var overflowOffset: CGFloat var overflowOffset: CGFloat
var contentContainerFrame: CGRect var contentContainerFrame: CGRect
// if keepInPlace {
overflowOffset = min(0.0, originalActionsFrame.minY - contentTopInset) overflowOffset = min(0.0, originalActionsFrame.minY - contentTopInset)
let contentParentNode = referenceNode let contentParentNode = referenceNode
contentContainerFrame = originalContentFrame contentContainerFrame = originalContentFrame
@ -1282,7 +1282,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
originalActionsFrame.origin.x -= contentParentNode.frame.width + 14.0 originalActionsFrame.origin.x -= contentParentNode.frame.width + 14.0
originalActionsFrame.origin.x = max(actionsSideInset, originalActionsFrame.origin.x) originalActionsFrame.origin.x = max(actionsSideInset, originalActionsFrame.origin.x)
//originalActionsFrame.origin.y += contentParentNode.contentRect.height
if originalActionsFrame.minX < contentContainerFrame.minX { if originalActionsFrame.minX < contentContainerFrame.minX {
contentContainerFrame.origin.x = min(originalActionsFrame.maxX + 14.0, layout.size.width - actionsSideInset) contentContainerFrame.origin.x = min(originalActionsFrame.maxX + 14.0, layout.size.width - actionsSideInset)
} }
@ -1293,10 +1293,6 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
} }
contentHeight -= offsetDelta contentHeight -= offsetDelta
} }
// } else {
// overflowOffset = min(0.0, originalContentFrame.minY - contentTopInset)
// contentContainerFrame = originalContentFrame.offsetBy(dx: -contentParentNode.contentRect.minX, dy: -overflowOffset - contentParentNode.contentRect.minY)
// }
let scrollContentSize = CGSize(width: layout.size.width, height: contentHeight) let scrollContentSize = CGSize(width: layout.size.width, height: contentHeight)
if self.scrollNode.view.contentSize != scrollContentSize { if self.scrollNode.view.contentSize != scrollContentSize {
@ -1388,6 +1384,14 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
contentContainerFrame = originalContentFrame.offsetBy(dx: -contentParentNode.contentRect.minX, dy: -overflowOffset - contentParentNode.contentRect.minY) contentContainerFrame = originalContentFrame.offsetBy(dx: -contentParentNode.contentRect.minX, dy: -overflowOffset - contentParentNode.contentRect.minY)
} }
if case let .extracted(source) = self.source, source.centerVertically {
let totalHeight = contentContainerFrame.height + originalActionsFrame.height
let updatedOrigin = floor((layout.size.height - totalHeight) / 2.0)
let delta = updatedOrigin - contentContainerFrame.origin.y
contentContainerFrame.origin.y = updatedOrigin
originalActionsFrame.origin.y += delta
}
let scrollContentSize = CGSize(width: layout.size.width, height: contentHeight) let scrollContentSize = CGSize(width: layout.size.width, height: contentHeight)
if self.scrollNode.view.contentSize != scrollContentSize { if self.scrollNode.view.contentSize != scrollContentSize {
self.scrollNode.view.contentSize = scrollContentSize self.scrollNode.view.contentSize = scrollContentSize
@ -1697,6 +1701,7 @@ public final class ContextControllerPutBackViewInfo {
} }
public protocol ContextExtractedContentSource: class { public protocol ContextExtractedContentSource: class {
var centerVertically: Bool { get }
var keepInPlace: Bool { get } var keepInPlace: Bool { get }
var ignoreContentTouches: Bool { get } var ignoreContentTouches: Bool { get }
var blurBackground: Bool { get } var blurBackground: Bool { get }
@ -1707,6 +1712,10 @@ public protocol ContextExtractedContentSource: class {
} }
public extension ContextExtractedContentSource { public extension ContextExtractedContentSource {
var centerVertically: Bool {
return false
}
var shouldBeDismissed: Signal<Bool, NoError> { var shouldBeDismissed: Signal<Bool, NoError> {
return .single(false) return .single(false)
} }

View File

@ -1432,7 +1432,7 @@ public final class VoiceChatController: ViewController {
let dismissPromise = ValuePromise<Bool>(false) let dismissPromise = ValuePromise<Bool>(false)
let source = VoiceChatContextExtractedContentSource(controller: controller, sourceNode: sourceNode, keepInPlace: false, blurBackground: true, shouldBeDismissed: dismissPromise.get()) let source = VoiceChatContextExtractedContentSource(controller: controller, sourceNode: sourceNode, keepInPlace: false, blurBackground: true, centerVertically: entry.peer.smallProfileImage != nil, shouldBeDismissed: dismissPromise.get())
sourceNode.requestDismiss = { sourceNode.requestDismiss = {
dismissPromise.set(true) dismissPromise.set(true)
} }
@ -3905,13 +3905,15 @@ private final class VoiceChatContextExtractedContentSource: ContextExtractedCont
private let controller: ViewController private let controller: ViewController
private let sourceNode: ContextExtractedContentContainingNode private let sourceNode: ContextExtractedContentContainingNode
var centerVertically: Bool
var shouldBeDismissed: Signal<Bool, NoError> var shouldBeDismissed: Signal<Bool, NoError>
init(controller: ViewController, sourceNode: ContextExtractedContentContainingNode, keepInPlace: Bool, blurBackground: Bool, shouldBeDismissed: Signal<Bool, NoError>) { init(controller: ViewController, sourceNode: ContextExtractedContentContainingNode, keepInPlace: Bool, blurBackground: Bool, centerVertically: Bool, shouldBeDismissed: Signal<Bool, NoError>) {
self.controller = controller self.controller = controller
self.sourceNode = sourceNode self.sourceNode = sourceNode
self.keepInPlace = keepInPlace self.keepInPlace = keepInPlace
self.blurBackground = blurBackground self.blurBackground = blurBackground
self.centerVertically = centerVertically
self.shouldBeDismissed = shouldBeDismissed self.shouldBeDismissed = shouldBeDismissed
} }

View File

@ -756,6 +756,10 @@ class VoiceChatParticipantItemNode: ItemListRevealOptionsItemNode {
strongSelf.nonExtractedRect = nonExtractedRect strongSelf.nonExtractedRect = nonExtractedRect
if strongSelf.isExtracted { if strongSelf.isExtracted {
var extractedRect = extractedRect
if !extractedVerticalOffset.isZero {
extractedRect = CGRect(x: extractedRect.minX, y: extractedRect.minY + extractedVerticalOffset, width: extractedRect.width, height: extractedRect.height - extractedVerticalOffset)
}
strongSelf.backgroundImageNode.frame = extractedRect strongSelf.backgroundImageNode.frame = extractedRect
} else { } else {
strongSelf.backgroundImageNode.frame = nonExtractedRect strongSelf.backgroundImageNode.frame = nonExtractedRect