mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Web app improvements
This commit is contained in:
@@ -596,7 +596,7 @@ public class AttachmentController: ViewController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let isEffecitvelyCollapsedUpdated = (self.selectionCount > 0) != (self.panel.isSelecting)
|
let isEffecitvelyCollapsedUpdated = (self.selectionCount > 0) != (self.panel.isSelecting)
|
||||||
let panelHeight = self.panel.update(layout: containerLayout, buttons: self.controller?.buttons ?? [], isSelecting: self.selectionCount > 0, transition: !hasPanel && hasButton ? .immediate : transition)
|
let panelHeight = self.panel.update(layout: containerLayout, buttons: self.controller?.buttons ?? [], isSelecting: self.selectionCount > 0, transition: transition)
|
||||||
if hasPanel || hasButton {
|
if hasPanel || hasButton {
|
||||||
containerInsets.bottom = panelHeight
|
containerInsets.bottom = panelHeight
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -385,6 +385,10 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
|
|||||||
self.backgroundNode = ASDisplayNode()
|
self.backgroundNode = ASDisplayNode()
|
||||||
self.backgroundNode.allowsGroupOpacity = true
|
self.backgroundNode.allowsGroupOpacity = true
|
||||||
self.backgroundNode.isUserInteractionEnabled = false
|
self.backgroundNode.isUserInteractionEnabled = false
|
||||||
|
self.backgroundNode.cornerRadius = 12.0
|
||||||
|
if #available(iOS 13.0, *) {
|
||||||
|
self.backgroundNode.layer.cornerCurve = .continuous
|
||||||
|
}
|
||||||
|
|
||||||
self.textNode = ImmediateTextNode()
|
self.textNode = ImmediateTextNode()
|
||||||
self.textNode.textAlignment = .center
|
self.textNode.textAlignment = .center
|
||||||
@@ -407,28 +411,22 @@ private final class MainButtonNode: HighlightTrackingButtonNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateLayout(layout: ContainerViewLayout, state: AttachmentMainButtonState, transition: ContainedViewLayoutTransition) -> CGFloat {
|
func updateLayout(size: CGSize, state: AttachmentMainButtonState, transition: ContainedViewLayoutTransition) {
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
self.isUserInteractionEnabled = state.isVisible
|
self.isUserInteractionEnabled = state.isVisible
|
||||||
self.isEnabled = state.isEnabled
|
self.isEnabled = state.isEnabled
|
||||||
transition.updateAlpha(node: self, alpha: state.isEnabled ? 1.0 : 0.4)
|
transition.updateAlpha(node: self, alpha: state.isEnabled ? 1.0 : 0.4)
|
||||||
|
|
||||||
let buttonHeight = 50.0
|
|
||||||
if let text = state.text {
|
if let text = state.text {
|
||||||
self.textNode.attributedText = NSAttributedString(string: text, font: Font.semibold(16.0), textColor: state.textColor)
|
self.textNode.attributedText = NSAttributedString(string: text, font: Font.semibold(17.0), textColor: state.textColor)
|
||||||
|
|
||||||
let textSize = self.textNode.updateLayout(layout.size)
|
let textSize = self.textNode.updateLayout(size)
|
||||||
self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((layout.size.width - textSize.width) / 2.0), y: floorToScreenPixels((buttonHeight - textSize.height) / 2.0)), size: textSize)
|
self.textNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - textSize.width) / 2.0), y: floorToScreenPixels((size.height - textSize.height) / 2.0)), size: textSize)
|
||||||
|
|
||||||
self.backgroundNode.backgroundColor = state.backgroundColor
|
self.backgroundNode.backgroundColor = state.backgroundColor
|
||||||
}
|
}
|
||||||
|
transition.updateFrame(node: self.backgroundNode, frame: CGRect(origin: CGPoint(), size: size))
|
||||||
let totalButtonHeight = buttonHeight + layout.intrinsicInsets.bottom
|
|
||||||
transition.updateFrame(node: self.backgroundNode, frame: CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: totalButtonHeight)))
|
|
||||||
transition.updateSublayerTransformOffset(layer: self.layer, offset: CGPoint(x: 0.0, y: state.isVisible ? 0.0 : totalButtonHeight))
|
|
||||||
|
|
||||||
return totalButtonHeight
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -835,7 +833,7 @@ final class AttachmentPanel: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
}
|
}
|
||||||
self.scrollLayout = (layout.size.width, contentSize)
|
self.scrollLayout = (layout.size.width, contentSize)
|
||||||
|
|
||||||
transition.updateFrame(node: self.scrollNode, frame: CGRect(origin: CGPoint(x: 0.0, y: self.isSelecting || self.isButtonVisible ? -buttonSize.height : 0.0), size: CGSize(width: layout.size.width, height: buttonSize.height)))
|
transition.updateFrameAsPositionAndBounds(node: self.scrollNode, frame: CGRect(origin: CGPoint(x: 0.0, y: self.isSelecting || self.isButtonVisible ? -buttonSize.height : 0.0), size: CGSize(width: layout.size.width, height: buttonSize.height)))
|
||||||
self.scrollNode.view.contentSize = contentSize
|
self.scrollNode.view.contentSize = contentSize
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -935,7 +933,9 @@ final class AttachmentPanel: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
let bounds = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: buttonSize.height + insets.bottom))
|
let bounds = CGRect(origin: CGPoint(), size: CGSize(width: layout.size.width, height: buttonSize.height + insets.bottom))
|
||||||
let containerTransition: ContainedViewLayoutTransition
|
let containerTransition: ContainedViewLayoutTransition
|
||||||
let containerFrame: CGRect
|
let containerFrame: CGRect
|
||||||
if isSelecting {
|
if isButtonVisible {
|
||||||
|
containerFrame = CGRect(origin: CGPoint(), size: CGSize(width: bounds.width, height: bounds.height + 9.0))
|
||||||
|
} else if isSelecting {
|
||||||
containerFrame = CGRect(origin: CGPoint(), size: CGSize(width: bounds.width, height: textPanelHeight + insets.bottom))
|
containerFrame = CGRect(origin: CGPoint(), size: CGSize(width: bounds.width, height: textPanelHeight + insets.bottom))
|
||||||
} else {
|
} else {
|
||||||
containerFrame = bounds
|
containerFrame = bounds
|
||||||
@@ -947,6 +947,7 @@ final class AttachmentPanel: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
containerTransition = transition
|
containerTransition = transition
|
||||||
}
|
}
|
||||||
containerTransition.updateAlpha(node: self.scrollNode, alpha: isSelecting || isButtonVisible ? 0.0 : 1.0)
|
containerTransition.updateAlpha(node: self.scrollNode, alpha: isSelecting || isButtonVisible ? 0.0 : 1.0)
|
||||||
|
containerTransition.updateTransformScale(node: self.scrollNode, scale: isSelecting || isButtonVisible ? 0.8 : 1.0)
|
||||||
|
|
||||||
if isSelectingUpdated {
|
if isSelectingUpdated {
|
||||||
if isSelecting {
|
if isSelecting {
|
||||||
@@ -965,7 +966,6 @@ final class AttachmentPanel: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
containerTransition.updateFrame(node: self.containerNode, frame: containerFrame)
|
containerTransition.updateFrame(node: self.containerNode, frame: containerFrame)
|
||||||
containerTransition.updateFrame(node: self.backgroundNode, frame: containerBounds)
|
containerTransition.updateFrame(node: self.backgroundNode, frame: containerBounds)
|
||||||
self.backgroundNode.update(size: containerBounds.size, transition: transition)
|
self.backgroundNode.update(size: containerBounds.size, transition: transition)
|
||||||
@@ -995,8 +995,10 @@ final class AttachmentPanel: ASDisplayNode, UIScrollViewDelegate {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let mainButtonHeight = self.mainButtonNode.updateLayout(layout: layout, state: self.mainButtonState, transition: transition)
|
let sideInset: CGFloat = 16.0
|
||||||
transition.updateFrame(node: self.mainButtonNode, frame: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: layout.size.width, height: mainButtonHeight)))
|
let buttonSize = CGSize(width: layout.size.width - (sideInset + safeAreaInsets.left) * 2.0, height: 50.0)
|
||||||
|
self.mainButtonNode.updateLayout(size: buttonSize, state: self.mainButtonState, transition: transition)
|
||||||
|
transition.updateFrame(node: self.mainButtonNode, frame: CGRect(origin: CGPoint(x: layout.safeInsets.left + sideInset, y: isButtonVisible ? 8.0 : containerFrame.height), size: buttonSize))
|
||||||
|
|
||||||
return containerFrame.height
|
return containerFrame.height
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,6 +293,10 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
self.mainButtonStatePromise.set(.single(state))
|
self.mainButtonStatePromise.set(.single(state))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "web_app_request_viewport":
|
||||||
|
if let (layout, navigationBarHeight) = self.validLayout {
|
||||||
|
self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate)
|
||||||
|
}
|
||||||
case "web_app_close":
|
case "web_app_close":
|
||||||
self.controller?.dismiss()
|
self.controller?.dismiss()
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user