mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix tooltip
This commit is contained in:
parent
717e91aa9e
commit
0533ec4a43
@ -2153,35 +2153,18 @@ public final class StoryItemSetContainerComponent: Component {
|
||||
return
|
||||
}
|
||||
|
||||
//TODO:localize
|
||||
|
||||
/*let rect = likeButtonView.convert(likeButtonView.bounds, to: nil)
|
||||
let presentationData = component.context.sharedContext.currentPresentationData.with { $0 }
|
||||
let text = "Long tap for more reactions"
|
||||
let controller = TooltipController(content: .text(text), baseFontSize: presentationData.listsFontSize.baseDisplaySize, padding: 2.0)
|
||||
controller.dismissed = { [weak self] _ in
|
||||
if let self {
|
||||
self.voiceMessagesRestrictedTooltipController = nil
|
||||
self.updateIsProgressPaused()
|
||||
}
|
||||
}
|
||||
component.presentController(controller, TooltipControllerPresentationArguments(sourceViewAndRect: { [weak self] in
|
||||
if let self {
|
||||
return (self, rect)
|
||||
}
|
||||
return nil
|
||||
}))
|
||||
self.voiceMessagesRestrictedTooltipController = controller
|
||||
self.updateIsProgressPaused()*/
|
||||
|
||||
//TODO:localize
|
||||
let tooltipScreen = TooltipScreen(
|
||||
account: component.context.account,
|
||||
sharedContext: component.context.sharedContext,
|
||||
text: .markdown(text: "Long tap for more reactions"),
|
||||
balancedTextLayout: true,
|
||||
style: .default,
|
||||
location: TooltipScreen.Location.point(likeButtonView.convert(likeButtonView.bounds, to: nil).offsetBy(dx: 0.0, dy: 0.0), .bottom), displayDuration: .infinite, shouldDismissOnTouch: { _, _ in
|
||||
style: .customBlur(component.theme.rootController.navigationBar.blurredBackgroundColor, 0.0),
|
||||
arrowStyle: .small,
|
||||
location: TooltipScreen.Location.point(likeButtonView.convert(likeButtonView.bounds, to: nil).offsetBy(dx: 0.0, dy: 0.0), .bottom),
|
||||
displayDuration: .infinite,
|
||||
inset: 5.0,
|
||||
shouldDismissOnTouch: { _, _ in
|
||||
return .dismiss(consume: true)
|
||||
}
|
||||
)
|
||||
|
@ -112,6 +112,7 @@ private final class TooltipScreenNode: ViewControllerTracingNode {
|
||||
private let textAlignment: TooltipScreen.Alignment
|
||||
private let balancedTextLayout: Bool
|
||||
private let tooltipStyle: TooltipScreen.Style
|
||||
private let arrowStyle: TooltipScreen.ArrowStyle
|
||||
private let icon: TooltipScreen.Icon?
|
||||
private let action: TooltipScreen.Action?
|
||||
var location: TooltipScreen.Location {
|
||||
@ -159,6 +160,7 @@ private final class TooltipScreenNode: ViewControllerTracingNode {
|
||||
textAlignment: TooltipScreen.Alignment,
|
||||
balancedTextLayout: Bool,
|
||||
style: TooltipScreen.Style,
|
||||
arrowStyle: TooltipScreen.ArrowStyle,
|
||||
icon: TooltipScreen.Icon? = nil,
|
||||
action: TooltipScreen.Action? = nil,
|
||||
location: TooltipScreen.Location,
|
||||
@ -168,6 +170,7 @@ private final class TooltipScreenNode: ViewControllerTracingNode {
|
||||
shouldDismissOnTouch: @escaping (CGPoint, CGRect) -> TooltipScreen.DismissOnTouch, requestDismiss: @escaping () -> Void, openActiveTextItem: ((TooltipActiveTextItem, TooltipActiveTextAction) -> Void)?)
|
||||
{
|
||||
self.tooltipStyle = style
|
||||
self.arrowStyle = arrowStyle
|
||||
self.icon = icon
|
||||
self.action = action
|
||||
self.location = location
|
||||
@ -223,15 +226,30 @@ private final class TooltipScreenNode: ViewControllerTracingNode {
|
||||
return path
|
||||
}
|
||||
|
||||
let arrowSize = CGSize(width: 29.0, height: 10.0)
|
||||
self.arrowNode = ASImageNode()
|
||||
self.arrowNode.image = generateImage(arrowSize, rotatedContext: { size, context in
|
||||
context.clear(CGRect(origin: CGPoint(), size: size))
|
||||
context.setFillColor(fillColor.cgColor)
|
||||
context.scaleBy(x: 0.333, y: 0.333)
|
||||
let _ = try? drawSvgPath(context, path: "M85.882251,0 C79.5170552,0 73.4125613,2.52817247 68.9116882,7.02834833 L51.4264069,24.5109211 C46.7401154,29.1964866 39.1421356,29.1964866 34.4558441,24.5109211 L16.9705627,7.02834833 C12.4696897,2.52817247 6.36519576,0 0,0 L85.882251,0 ")
|
||||
context.fillPath()
|
||||
})
|
||||
let arrowSize: CGSize
|
||||
switch self.arrowStyle {
|
||||
case .default:
|
||||
arrowSize = CGSize(width: 29.0, height: 10.0)
|
||||
self.arrowNode = ASImageNode()
|
||||
self.arrowNode.image = generateImage(arrowSize, rotatedContext: { size, context in
|
||||
context.clear(CGRect(origin: CGPoint(), size: size))
|
||||
context.setFillColor(fillColor.cgColor)
|
||||
context.scaleBy(x: 0.333, y: 0.333)
|
||||
let _ = try? drawSvgPath(context, path: "M85.882251,0 C79.5170552,0 73.4125613,2.52817247 68.9116882,7.02834833 L51.4264069,24.5109211 C46.7401154,29.1964866 39.1421356,29.1964866 34.4558441,24.5109211 L16.9705627,7.02834833 C12.4696897,2.52817247 6.36519576,0 0,0 L85.882251,0 ")
|
||||
context.fillPath()
|
||||
})
|
||||
case .small:
|
||||
arrowSize = CGSize(width: 18.0, height: 7.0)
|
||||
self.arrowNode = ASImageNode()
|
||||
self.arrowNode.image = generateImage(arrowSize, rotatedContext: { size, context in
|
||||
context.clear(CGRect(origin: CGPoint(), size: size))
|
||||
context.setFillColor(fillColor.cgColor)
|
||||
context.scaleBy(x: 0.333, y: 0.333)
|
||||
context.scaleBy(x: 0.62, y: 0.62)
|
||||
let _ = try? drawSvgPath(context, path: "M85.882251,0 C79.5170552,0 73.4125613,2.52817247 68.9116882,7.02834833 L51.4264069,24.5109211 C46.7401154,29.1964866 39.1421356,29.1964866 34.4558441,24.5109211 L16.9705627,7.02834833 C12.4696897,2.52817247 6.36519576,0 0,0 L85.882251,0 ")
|
||||
context.fillPath()
|
||||
})
|
||||
}
|
||||
|
||||
self.arrowContainer = ASDisplayNode()
|
||||
|
||||
@ -295,7 +313,14 @@ private final class TooltipScreenNode: ViewControllerTracingNode {
|
||||
self.arrowContainer.addSubnode(self.arrowGradientNode!)
|
||||
|
||||
let maskLayer = CAShapeLayer()
|
||||
if let path = try? svgPath("M85.882251,0 C79.5170552,0 73.4125613,2.52817247 68.9116882,7.02834833 L51.4264069,24.5109211 C46.7401154,29.1964866 39.1421356,29.1964866 34.4558441,24.5109211 L16.9705627,7.02834833 C12.4696897,2.52817247 6.36519576,0 0,0 L85.882251,0 ", scale: CGPoint(x: 0.333333, y: 0.333333), offset: CGPoint()) {
|
||||
let arrowScale: CGFloat
|
||||
switch self.arrowStyle {
|
||||
case .default:
|
||||
arrowScale = 1.0
|
||||
case .small:
|
||||
arrowScale = 0.62
|
||||
}
|
||||
if let path = try? svgPath("M85.882251,0 C79.5170552,0 73.4125613,2.52817247 68.9116882,7.02834833 L51.4264069,24.5109211 C46.7401154,29.1964866 39.1421356,29.1964866 34.4558441,24.5109211 L16.9705627,7.02834833 C12.4696897,2.52817247 6.36519576,0 0,0 L85.882251,0 ", scale: CGPoint(x: 0.333333 * arrowScale, y: 0.333333 * arrowScale), offset: CGPoint()) {
|
||||
maskLayer.path = path.cgPath
|
||||
}
|
||||
maskLayer.frame = CGRect(origin: CGPoint(), size: arrowSize)
|
||||
@ -332,7 +357,14 @@ private final class TooltipScreenNode: ViewControllerTracingNode {
|
||||
fontSize = 14.0
|
||||
|
||||
let maskLayer = CAShapeLayer()
|
||||
if let path = try? svgPath("M85.882251,0 C79.5170552,0 73.4125613,2.52817247 68.9116882,7.02834833 L51.4264069,24.5109211 C46.7401154,29.1964866 39.1421356,29.1964866 34.4558441,24.5109211 L16.9705627,7.02834833 C12.4696897,2.52817247 6.36519576,0 0,0 L85.882251,0 ", scale: CGPoint(x: 0.333333, y: 0.333333), offset: CGPoint()) {
|
||||
let arrowScale: CGFloat
|
||||
switch self.arrowStyle {
|
||||
case .default:
|
||||
arrowScale = 1.0
|
||||
case .small:
|
||||
arrowScale = 0.62
|
||||
}
|
||||
if let path = try? svgPath("M85.882251,0 C79.5170552,0 73.4125613,2.52817247 68.9116882,7.02834833 L51.4264069,24.5109211 C46.7401154,29.1964866 39.1421356,29.1964866 34.4558441,24.5109211 L16.9705627,7.02834833 C12.4696897,2.52817247 6.36519576,0 0,0 L85.882251,0 ", scale: CGPoint(x: 0.333333 * arrowScale, y: 0.333333 * arrowScale), offset: CGPoint()) {
|
||||
maskLayer.path = path.cgPath
|
||||
}
|
||||
maskLayer.frame = CGRect(origin: CGPoint(), size: arrowSize)
|
||||
@ -665,7 +697,7 @@ private final class TooltipScreenNode: ViewControllerTracingNode {
|
||||
|
||||
let arrowBounds = CGRect(origin: CGPoint(), size: arrowSize)
|
||||
self.arrowNode.frame = arrowBounds
|
||||
self.arrowGradientNode?.frame = CGRect(origin: CGPoint(x: -arrowFrame.minX + backgroundFrame.minX, y: 0.0), size: backgroundFrame.size)
|
||||
self.arrowGradientNode?.frame = CGRect(origin: CGPoint(x: -arrowFrame.minX + backgroundFrame.minX, y: 0.0), size: backgroundFrame.size)
|
||||
case .right:
|
||||
let arrowCenterY = floorToScreenPixels(rect.midY - arrowSize.height / 2.0)
|
||||
arrowFrame = CGRect(origin: CGPoint(x: backgroundFrame.width + arrowSize.height, y: self.view.convert(CGPoint(x: 0.0, y: arrowCenterY), to: self.arrowContainer.supernode?.view).y), size: CGSize(width: arrowSize.height, height: arrowSize.width))
|
||||
@ -932,6 +964,11 @@ public final class TooltipScreen: ViewController {
|
||||
case bottom
|
||||
}
|
||||
|
||||
public enum ArrowStyle {
|
||||
case `default`
|
||||
case small
|
||||
}
|
||||
|
||||
public enum Location {
|
||||
case point(CGRect, ArrowPosition)
|
||||
case top
|
||||
@ -965,6 +1002,7 @@ public final class TooltipScreen: ViewController {
|
||||
public let textAlignment: TooltipScreen.Alignment
|
||||
private let balancedTextLayout: Bool
|
||||
private let style: TooltipScreen.Style
|
||||
private let arrowStyle: TooltipScreen.ArrowStyle
|
||||
private let icon: TooltipScreen.Icon?
|
||||
private let action: TooltipScreen.Action?
|
||||
public var location: TooltipScreen.Location {
|
||||
@ -1002,6 +1040,7 @@ public final class TooltipScreen: ViewController {
|
||||
textAlignment: TooltipScreen.Alignment = .natural,
|
||||
balancedTextLayout: Bool = false,
|
||||
style: TooltipScreen.Style = .default,
|
||||
arrowStyle: TooltipScreen.ArrowStyle = .default,
|
||||
icon: TooltipScreen.Icon? = nil,
|
||||
action: TooltipScreen.Action? = nil,
|
||||
location: TooltipScreen.Location,
|
||||
@ -1018,6 +1057,7 @@ public final class TooltipScreen: ViewController {
|
||||
self.textAlignment = textAlignment
|
||||
self.balancedTextLayout = balancedTextLayout
|
||||
self.style = style
|
||||
self.arrowStyle = arrowStyle
|
||||
self.icon = icon
|
||||
self.action = action
|
||||
self.location = location
|
||||
@ -1083,7 +1123,7 @@ public final class TooltipScreen: ViewController {
|
||||
}
|
||||
|
||||
override public func loadDisplayNode() {
|
||||
self.displayNode = TooltipScreenNode(context: self.context, account: self.account, sharedContext: self.sharedContext, text: self.text, textAlignment: self.textAlignment, balancedTextLayout: self.balancedTextLayout, style: self.style, icon: self.icon, action: self.action, location: self.location, displayDuration: self.displayDuration, inset: self.inset, cornerRadius: self.cornerRadius, shouldDismissOnTouch: self.shouldDismissOnTouch, requestDismiss: { [weak self] in
|
||||
self.displayNode = TooltipScreenNode(context: self.context, account: self.account, sharedContext: self.sharedContext, text: self.text, textAlignment: self.textAlignment, balancedTextLayout: self.balancedTextLayout, style: self.style, arrowStyle: self.arrowStyle, icon: self.icon, action: self.action, location: self.location, displayDuration: self.displayDuration, inset: self.inset, cornerRadius: self.cornerRadius, shouldDismissOnTouch: self.shouldDismissOnTouch, requestDismiss: { [weak self] in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user