Skip to content

Commit 35235b8

Browse files
author
Isaac
committed
Add story pip button
1 parent ac65d7f commit 35235b8

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ public final class StoryItemSetContainerComponent: Component {
450450
var currentSoundButtonState: Bool?
451451
let soundButton = ComponentView<Empty>()
452452
var privacyIcon: ComponentView<Empty>?
453+
var pictureInPictureIcon: ComponentView<Empty>?
453454

454455
var captionItem: CaptionItem?
455456

@@ -2160,6 +2161,9 @@ public final class StoryItemSetContainerComponent: Component {
21602161
if let closeFriendIcon = self.privacyIcon?.view {
21612162
closeFriendIcon.layer.animateAlpha(from: 0.0, to: closeFriendIcon.alpha, duration: 0.25)
21622163
}
2164+
if let pictureInPictureIconView = self.pictureInPictureIcon?.view {
2165+
pictureInPictureIconView.layer.animateAlpha(from: 0.0, to: pictureInPictureIconView.alpha, duration: 0.25)
2166+
}
21632167
self.closeButton.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.25, completion: { _ in
21642168
completion()
21652169
})
@@ -2350,6 +2354,9 @@ public final class StoryItemSetContainerComponent: Component {
23502354
if let closeFriendIconView = self.privacyIcon?.view {
23512355
closeFriendIconView.layer.animateAlpha(from: closeFriendIconView.alpha, to: 0.0, duration: 0.25, removeOnCompletion: false)
23522356
}
2357+
if let pictureInPictureIconView = self.pictureInPictureIcon?.view {
2358+
pictureInPictureIconView.layer.animateAlpha(from: pictureInPictureIconView.alpha, to: 0.0, duration: 0.25, removeOnCompletion: false)
2359+
}
23532360
if let captionView = self.captionItem?.view.view {
23542361
captionView.layer.animateAlpha(from: captionView.alpha, to: 0.0, duration: 0.25, removeOnCompletion: false)
23552362
}
@@ -4262,6 +4269,51 @@ public final class StoryItemSetContainerComponent: Component {
42624269
closeFriendIcon.view?.removeFromSuperview()
42634270
}
42644271

4272+
if case .liveStream = component.slice.item.storyItem.media {
4273+
let pictureInPictureIcon: ComponentView<Empty>
4274+
var pictureInPictureIconTransition: ComponentTransition = itemChanged ? .immediate : .easeInOut(duration: 0.2)
4275+
if let current = self.pictureInPictureIcon {
4276+
pictureInPictureIcon = current
4277+
} else {
4278+
pictureInPictureIconTransition = .immediate
4279+
pictureInPictureIcon = ComponentView()
4280+
self.pictureInPictureIcon = pictureInPictureIcon
4281+
}
4282+
let pictureInPictureIconSize = pictureInPictureIcon.update(
4283+
transition: pictureInPictureIconTransition,
4284+
component: AnyComponent(PlainButtonComponent(
4285+
content: AnyComponent(
4286+
BundleIconComponent(
4287+
name: "Stories/HeaderPictureInPicture",
4288+
tintColor: .white
4289+
)
4290+
),
4291+
effectAlignment: .center,
4292+
action: { [weak self] in
4293+
guard let self else {
4294+
return
4295+
}
4296+
4297+
self.beginPictureInPicture()
4298+
}
4299+
)),
4300+
environment: {},
4301+
containerSize: CGSize(width: 44.0, height: 44.0)
4302+
)
4303+
let pictureInPictureIconFrame = CGRect(origin: CGPoint(x: headerRightOffset - pictureInPictureIconSize.width, y: 20.0), size: pictureInPictureIconSize)
4304+
if let pictureInPictureIconView = pictureInPictureIcon.view {
4305+
if pictureInPictureIconView.superview == nil {
4306+
self.controlsClippingView.addSubview(pictureInPictureIconView)
4307+
}
4308+
4309+
pictureInPictureIconTransition.setFrame(view: pictureInPictureIconView, frame: pictureInPictureIconFrame)
4310+
headerRightOffset -= 44.0
4311+
}
4312+
} else if let pictureInPictureIcon = self.pictureInPictureIcon {
4313+
self.pictureInPictureIcon = nil
4314+
pictureInPictureIcon.view?.removeFromSuperview()
4315+
}
4316+
42654317
let controlsContainerAlpha = (component.hideUI || self.isEditingStory || self.viewListDisplayState != .hidden) ? 0.0 : 1.0
42664318
transition.setAlpha(view: self.controlsContainerView, alpha: controlsContainerAlpha)
42674319
transition.setAlpha(view: self.controlsClippingView, alpha: controlsContainerAlpha)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "pip.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Binary file not shown.

0 commit comments

Comments
 (0)