Fixing fullscreen presentation

This commit is contained in:
Ilya Yelagov
2022-11-26 16:10:24 +04:00
parent 2f9f07d860
commit fe2244a413
3 changed files with 44 additions and 18 deletions

View File

@@ -786,7 +786,7 @@ public final class _MediaStreamComponent: CombinedComponent {
}
let background = background.update(
component: Rectangle(color: .black.withAlphaComponent(0.12)),
component: Rectangle(color: .black.withAlphaComponent(0.0)),
availableSize: context.availableSize,
transition: context.transition
)
@@ -809,7 +809,15 @@ public final class _MediaStreamComponent: CombinedComponent {
state.updated(transition: .easeInOut(duration: 3))
deactivatePictureInPicture.invoke(Void())
}
let isFullscreen = state.isFullscreen
var isFullscreen = state.isFullscreen
let isLandscape = context.availableSize.width > context.availableSize.height
if let videoSize = context.state.videoSize {
if videoSize.width > videoSize.height && isLandscape && !isFullscreen {
state.isFullscreen = true
isFullscreen = true
}
}
let video = video.update(
component: MediaStreamVideoComponent(
call: context.component.call,
@@ -1118,7 +1126,6 @@ public final class _MediaStreamComponent: CombinedComponent {
// transition: context.transition
// )
let isLandscape = context.availableSize.width > context.availableSize.height
if context.state.storedIsLandscape != isLandscape {
context.state.storedIsLandscape = isLandscape
if isLandscape {
@@ -1160,7 +1167,7 @@ public final class _MediaStreamComponent: CombinedComponent {
// TODO: disable button instead of hiding
rightItem: state.hasVideo ? AnyComponent(Button(
content: AnyComponent(BundleIconComponent(
name: isLandscape ? "Media Gallery/Minimize" : "Media Gallery/Fullscreen",
name: isFullscreen ? "Media Gallery/Minimize" : "Media Gallery/Fullscreen",
tintColor: .white
)),
action: {
@@ -1220,7 +1227,7 @@ public final class _MediaStreamComponent: CombinedComponent {
})
)
let videoHeight: CGFloat = context.availableSize.width / 16 * 9
let sheetHeight: CGFloat = (50 + 70 + 20 + 80 + videoHeight)
let sheetHeight: CGFloat = isFullscreen ? context.availableSize.height : (50 + 70 + 20 + 80 + videoHeight)
let isFullyDragged = context.availableSize.height - sheetHeight + state.dismissOffset < 30
let sheet = sheet.update(

View File

@@ -68,6 +68,10 @@ final class _MediaStreamVideoComponent: Component {
return false
}
if lhs.isFullscreen != rhs.isFullscreen {
return false
}
return true
}

View File

@@ -50,7 +50,9 @@ final class StreamSheetComponent: CombinedComponent {
if lhs.sheetHeight != rhs.sheetHeight {
return false
}
if !lhs.backgroundColor.isEqual(rhs.backgroundColor) {
return false
}
return true
}
//
@@ -251,7 +253,29 @@ final class ViewerCountComponent: Component {
final class SheetBackgroundComponent: Component {
private let color: UIColor
private let backgroundView = UIView()
class View: UIView {
private let backgroundView = UIView()
func update(availableSize: CGSize, color: UIColor) {
if backgroundView.superview == nil {
self.addSubview(backgroundView)
}
// To fix release animation
let extraBottom: CGFloat = 500
backgroundView.frame = .init(origin: .zero, size: .init(width: availableSize.width, height: availableSize.height + extraBottom))
backgroundView.backgroundColor = color// .withAlphaComponent(0.4)
backgroundView.isUserInteractionEnabled = false
backgroundView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
backgroundView.layer.cornerRadius = 16
backgroundView.clipsToBounds = true
backgroundView.layer.masksToBounds = true
}
}
func makeView() -> View {
View()
}
static func ==(lhs: SheetBackgroundComponent, rhs: SheetBackgroundComponent) -> Bool {
if !lhs.color.isEqual(rhs.color) {
@@ -270,17 +294,8 @@ final class SheetBackgroundComponent: Component {
self.color = color
}
public func update(view: UIView, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
if backgroundView.superview == nil {
view.addSubview(backgroundView)
}
backgroundView.frame = .init(origin: .zero, size: availableSize)
backgroundView.backgroundColor = self.color// .withAlphaComponent(0.4)
backgroundView.isUserInteractionEnabled = false
backgroundView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
backgroundView.layer.cornerRadius = 16
backgroundView.clipsToBounds = true
backgroundView.layer.masksToBounds = true
public func update(view: View, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
view.update(availableSize: availableSize, color: color)
return availableSize
}
}