Refactoring

This commit is contained in:
Ilya Yelagov
2022-12-08 10:14:34 +04:00
parent 81f69b801d
commit 55e2276e43
3 changed files with 9 additions and 32 deletions

View File

@@ -1200,8 +1200,9 @@ final class StreamTitleComponent: Component {
if !wasLive { if !wasLive {
wasLive = true wasLive = true
let anim = CAKeyframeAnimation(keyPath: "transform.scale") let anim = CAKeyframeAnimation(keyPath: "transform.scale")
anim.values = [1.0, 1.4, 1.0] anim.values = [1.0, 1.4, 0.9, 1.0]
anim.keyTimes = [0, 0.5, 1] anim.keyTimes = [0, 0.5, 0.8, 1]
anim.duration = 0.4
self.layer.add(anim, forKey: "transform") self.layer.add(anim, forKey: "transform")
UIView.animate(withDuration: 0.15, animations: { UIView.animate(withDuration: 0.15, animations: {

View File

@@ -428,7 +428,7 @@ final class MediaStreamVideoComponent: Component {
self.hadVideo, self.hadVideo,
// TODO: remove from here and move to call end (or at least to background) // TODO: remove from here and move to call end (or at least to background)
let snapshot = videoView.snapshotView(afterScreenUpdates: false) ?? videoView.snapshotView(afterScreenUpdates: true) { 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() var aspect = videoView.getAspect()
@@ -500,6 +500,7 @@ final class MediaStreamVideoComponent: Component {
placeholderView.frame = loadingBlurView.frame placeholderView.frame = loadingBlurView.frame
placeholderView.layer.cornerRadius = videoCornerRadius placeholderView.layer.cornerRadius = videoCornerRadius
placeholderView.clipsToBounds = true placeholderView.clipsToBounds = true
placeholderView.subviews.forEach { $0.frame = placeholderView.bounds }
shimmerBorderLayer.frame = loadingBlurView.bounds shimmerBorderLayer.frame = loadingBlurView.bounds

View File

@@ -119,29 +119,17 @@ final class StreamSheetComponent: CombinedComponent {
} }
private weak var state: State? private weak var state: State?
// func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
// view.isUserInteractionEnabled = false
// return availableSize
// }
/*public func update(view: View, availableSize: CGSize, state: State, environment: Environment<Empty>, transition: Transition) -> CGSize {
return view.update(component: self, availableSize: availableSize, state: state, transition: transition)
}*/
static var body: Body { static var body: Body {
let background = Child(SheetBackgroundComponent.self) let background = Child(SheetBackgroundComponent.self)
// let leftItem = Child(environment: Empty.self)
let topItem = Child(environment: Empty.self) let topItem = Child(environment: Empty.self)
let viewerCounter = Child(ParticipantsComponent.self) let viewerCounter = Child(ParticipantsComponent.self)
let bottomButtonsRow = Child(environment: Empty.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 return { context in
let availableWidth = context.availableSize.width let availableWidth = context.availableSize.width
// let sideInset: CGFloat = 16.0 + context.component.sideInset
let contentHeight: CGFloat = 44.0 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 topOffset = context.component.topOffset
let backgroundExtraOffset = context.component.isFullyExtended ? -context.view.safeAreaInsets.top : 0 let backgroundExtraOffset = context.component.isFullyExtended ? -context.view.safeAreaInsets.top : 0
@@ -180,7 +168,6 @@ final class StreamSheetComponent: CombinedComponent {
context.add(background context.add(background
.position(CGPoint(x: size.width / 2.0, y: topOffset + context.component.sheetHeight / 2)) .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 = [] (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)) (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 sheetHeight = context.component.sheetHeight
let animatedParticipantsVisible = context.component.participantsCount != -1 let animatedParticipantsVisible = context.component.participantsCount != -1
if true { if true {
@@ -239,12 +226,9 @@ final class SheetBackgroundComponent: Component {
let extraBottom: CGFloat = 500 let extraBottom: CGFloat = 500
if backgroundView.backgroundColor != color && backgroundView.backgroundColor != nil { 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 UIView.animate(withDuration: 0.4) { [self] in
backgroundView.backgroundColor = color 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)) 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.isUserInteractionEnabled = false
backgroundView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] 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.clipsToBounds = true
backgroundView.layer.masksToBounds = true backgroundView.layer.masksToBounds = true
} }
@@ -283,12 +264,6 @@ final class SheetBackgroundComponent: Component {
if lhs.offset != rhs.offset { if lhs.offset != rhs.offset {
return false return false
} }
// if lhs.width != rhs.width {
// return false
// }
// if lhs.height != rhs.height {
// return false
// }
return true return true
} }
@@ -328,7 +303,7 @@ final class ParticipantsComponent: Component {
} }
final class View: UIView { final class View: UIView {
let counter = AnimatedCountView()// VoiceChatTimerNode.init(strings: .init(), dateTimeFormat: .init()) let counter = AnimatedCountView()
override init(frame: CGRect) { override init(frame: CGRect) {
super.init(frame: frame) super.init(frame: frame)