From 55e2276e43d13dd7d51521bfa4056f37c8f47b14 Mon Sep 17 00:00:00 2001 From: Ilya Yelagov Date: Thu, 8 Dec 2022 10:14:34 +0400 Subject: [PATCH] Refactoring --- .../Components/MediaStreamComponent.swift | 5 +-- .../MediaStreamVideoComponent.swift | 3 +- .../Components/StreamSheetComponent.swift | 33 +++---------------- 3 files changed, 9 insertions(+), 32 deletions(-) diff --git a/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift b/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift index 84a86f86df..0cab10ba04 100644 --- a/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/MediaStreamComponent.swift @@ -1200,8 +1200,9 @@ final class StreamTitleComponent: Component { if !wasLive { wasLive = true let anim = CAKeyframeAnimation(keyPath: "transform.scale") - anim.values = [1.0, 1.4, 1.0] - anim.keyTimes = [0, 0.5, 1] + anim.values = [1.0, 1.4, 0.9, 1.0] + anim.keyTimes = [0, 0.5, 0.8, 1] + anim.duration = 0.4 self.layer.add(anim, forKey: "transform") UIView.animate(withDuration: 0.15, animations: { diff --git a/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift b/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift index f5bb89be04..ca65bb423f 100644 --- a/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/MediaStreamVideoComponent.swift @@ -428,7 +428,7 @@ final class MediaStreamVideoComponent: Component { self.hadVideo, // TODO: remove from here and move to call end (or at least to background) let snapshot = videoView.snapshotView(afterScreenUpdates: false) ?? videoView.snapshotView(afterScreenUpdates: true) { - lastFrame[component.call.peerId.id.description] = snapshot// ()! + lastFrame[component.call.peerId.id.description] = snapshot } var aspect = videoView.getAspect() @@ -500,6 +500,7 @@ final class MediaStreamVideoComponent: Component { placeholderView.frame = loadingBlurView.frame placeholderView.layer.cornerRadius = videoCornerRadius placeholderView.clipsToBounds = true + placeholderView.subviews.forEach { $0.frame = placeholderView.bounds } shimmerBorderLayer.frame = loadingBlurView.bounds diff --git a/submodules/TelegramCallsUI/Sources/Components/StreamSheetComponent.swift b/submodules/TelegramCallsUI/Sources/Components/StreamSheetComponent.swift index 486847bc73..1cff46379c 100644 --- a/submodules/TelegramCallsUI/Sources/Components/StreamSheetComponent.swift +++ b/submodules/TelegramCallsUI/Sources/Components/StreamSheetComponent.swift @@ -119,29 +119,17 @@ final class StreamSheetComponent: CombinedComponent { } private weak var state: State? -// func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment, transition: Transition) -> CGSize { -// view.isUserInteractionEnabled = false -// return availableSize -// } - /*public func update(view: View, availableSize: CGSize, state: State, environment: Environment, transition: Transition) -> CGSize { - return view.update(component: self, availableSize: availableSize, state: state, transition: transition) - }*/ static var body: Body { let background = Child(SheetBackgroundComponent.self) -// let leftItem = Child(environment: Empty.self) let topItem = Child(environment: Empty.self) let viewerCounter = Child(ParticipantsComponent.self) let bottomButtonsRow = Child(environment: Empty.self) -// let bottomButtons = Child(environment: Empty.self) -// let rightItems = ChildMap(environment: Empty.self, keyedBy: AnyHashable.self) -// let centerItem = Child(environment: Empty.self) return { context in let availableWidth = context.availableSize.width -// let sideInset: CGFloat = 16.0 + context.component.sideInset let contentHeight: CGFloat = 44.0 - let size = context.availableSize// CGSize(width: context.availableSize.width, height:44)// context.component.topInset + contentHeight) + let size = context.availableSize let topOffset = context.component.topOffset let backgroundExtraOffset = context.component.isFullyExtended ? -context.view.safeAreaInsets.top : 0 @@ -180,7 +168,6 @@ final class StreamSheetComponent: CombinedComponent { context.add(background .position(CGPoint(x: size.width / 2.0, y: topOffset + context.component.sheetHeight / 2)) - // .position(CGPoint(x: size.width / 2.0, y: context.component.topOffset + context.component.sheetHeight / 2 + backgroundExtraOffset)) ) (context.view as? StreamSheetComponent.View)?.overlayComponentsFrames = [] @@ -192,7 +179,7 @@ final class StreamSheetComponent: CombinedComponent { ) (context.view as? StreamSheetComponent.View)?.overlayComponentsFrames.append(.init(x: 0, y: topOffset, width: topItem.size.width, height: topItem.size.height)) } - let videoHeight = context.component.videoHeight // ?? (min(availableWidth, context.availableSize.height) - 32) / 16 * 9 + let videoHeight = context.component.videoHeight let sheetHeight = context.component.sheetHeight let animatedParticipantsVisible = context.component.participantsCount != -1 if true { @@ -239,12 +226,9 @@ final class SheetBackgroundComponent: Component { let extraBottom: CGFloat = 500 if backgroundView.backgroundColor != color && backgroundView.backgroundColor != nil { -// let initialVelocity: CGFloat = 0 -// let xtransition = ComponentFlow.Transition(animation: .curve(duration: 0.45, curve: .spring))// .animated(duration: 0.45, curve: .customSpring(damping: 124.0, initialVelocity: initialVelocity)) - UIView.animate(withDuration: 0.4) { [self] in backgroundView.backgroundColor = color - // TODO: determine if animation is needed (with facts and logic, not color) + // TODO: determine if animation is needed (with logic, not color) backgroundView.frame = .init(origin: .init(x: 0, y: offset), size: .init(width: availableSize.width, height: availableSize.height + extraBottom)) } @@ -261,9 +245,6 @@ final class SheetBackgroundComponent: Component { } backgroundView.isUserInteractionEnabled = false backgroundView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] -// let currentRadius = backgroundView.layer.cornerRadius -// backgroundView.layer.cornerRadius = cornerRadius -// transition.animateCornerRadius(layer: backgroundView.layer, from: currentRadius, to: cornerRadius) backgroundView.clipsToBounds = true backgroundView.layer.masksToBounds = true } @@ -283,12 +264,6 @@ final class SheetBackgroundComponent: Component { if lhs.offset != rhs.offset { return false } -// if lhs.width != rhs.width { -// return false -// } -// if lhs.height != rhs.height { -// return false -// } return true } @@ -328,7 +303,7 @@ final class ParticipantsComponent: Component { } final class View: UIView { - let counter = AnimatedCountView()// VoiceChatTimerNode.init(strings: .init(), dateTimeFormat: .init()) + let counter = AnimatedCountView() override init(frame: CGRect) { super.init(frame: frame)