Supporting varying aspect ratio

This commit is contained in:
Ilya Yelagov 2022-12-08 08:02:16 +04:00
parent abe0be6d63
commit 073920c5ec
2 changed files with 33 additions and 28 deletions

View File

@ -1013,7 +1013,7 @@ public final class _MediaStreamComponent: CombinedComponent {
if forceFullScreenInLandscape && /*videoSize.width > videoSize.height &&*/ isLandscape && !state.isFullscreen {
state.isFullscreen = true
isFullscreen = true
} else if let videoSize = context.state.videoSize, videoSize.width > videoSize.height && !isLandscape && state.isFullscreen && canEnforceOrientation {
} else if /*let videoSize = context.state.videoSize, videoSize.width > videoSize.height &&*/ !isLandscape && state.isFullscreen && canEnforceOrientation {
state.isFullscreen = false
isFullscreen = false
} else {
@ -1991,36 +1991,36 @@ public final class Throttler<T: Hashable> {
}
public func publish(_ value: T, includingLatest: Bool = false, using completion: ((T) -> Void)?) {
accumulator.insert(value)
queue.async { [self] in
accumulator.insert(value)
if !isThrottling {
isThrottling = true
lastValue = nil
queue.async {
if !isThrottling {
isThrottling = true
lastValue = nil
completion?(value)
self.lastCompletedValue = value
} else {
lastValue = value
}
} else {
lastValue = value
}
if lastValue == nil {
queue.asyncAfter(deadline: .now() + duration) { [self] in
accumulator.removeAll()
// TODO: quick fix, replace with timer
if lastValue == nil {
queue.asyncAfter(deadline: .now() + duration) { [self] in
isThrottling = false
accumulator.removeAll()
// TODO: quick fix, replace with timer
queue.asyncAfter(deadline: .now() + duration) { [self] in
isThrottling = false
}
guard
let lastValue = lastValue,
lastCompletedValue != lastValue || includingLatest
else { return }
accumulator.insert(lastValue)
self.lastValue = nil
completion?(lastValue)
lastCompletedValue = lastValue
}
guard
let lastValue = lastValue,
lastCompletedValue != lastValue || includingLatest
else { return }
accumulator.insert(lastValue)
self.lastValue = nil
completion?(lastValue)
lastCompletedValue = lastValue
}
}
}

View File

@ -595,8 +595,10 @@ final class _MediaStreamVideoComponent: Component {
// aspect == 1 the first run
if component.isFullscreen && self.hadVideo {
if aspect <= 0.01 {
aspect = 16.0 / 9 // 3.0 / 4.0
aspect = 16.0 / 9
}
} else if self.hadVideo {
// aspect = aspect
} else {
aspect = 16.0 / 9
}
@ -604,7 +606,10 @@ final class _MediaStreamVideoComponent: Component {
if component.isFullscreen {
videoSize = CGSize(width: aspect * 100.0, height: 100.0).aspectFitted(.init(width: availableSize.width - videoInset * 2, height: availableSize.height))
} else {
videoSize = CGSize(width: aspect * 100.0, height: 100.0).aspectFitted(.init(width: min(availableSize.width, availableSize.height) - videoInset * 2, height: max(availableSize.height, availableSize.width)))
let availableVideoWidth = availableSize.width - videoInset * 2
let availableVideoHeight = availableVideoWidth * 9.0 / 16
videoSize = CGSize(width: aspect * 100.0, height: 100.0).aspectFitted(.init(width: availableVideoWidth, height: availableVideoHeight))
}
let blurredVideoSize = videoSize.aspectFilled(availableSize)