Home telegram - message bubble
Post
Cancel

telegram - message bubble

class PrincipalThemeEssentialGraphics

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
public let chatMessageBackgroundIncomingMaskImage: UIImage
public let chatMessageBackgroundIncomingImage: UIImage
public let chatMessageBackgroundIncomingHighlightedImage: UIImage
public let chatMessageBackgroundIncomingMergedTopMaskImage: UIImage
public let chatMessageBackgroundIncomingMergedTopImage: UIImage
public let chatMessageBackgroundIncomingMergedTopHighlightedImage: UIImage
public let chatMessageBackgroundIncomingMergedTopSideMaskImage: UIImage
public let chatMessageBackgroundIncomingMergedTopSideImage: UIImage
public let chatMessageBackgroundIncomingMergedTopSideHighlightedImage: UIImage
public let chatMessageBackgroundIncomingMergedBottomMaskImage: UIImage
public let chatMessageBackgroundIncomingMergedBottomImage: UIImage
public let chatMessageBackgroundIncomingMergedBottomHighlightedImage: UIImage
public let chatMessageBackgroundIncomingMergedBothMaskImage: UIImage
public let chatMessageBackgroundIncomingMergedBothImage: UIImage
public let chatMessageBackgroundIncomingMergedBothHighlightedImage: UIImage
public let chatMessageBackgroundIncomingMergedSideMaskImage: UIImage
public let chatMessageBackgroundIncomingMergedSideImage: UIImage
public let chatMessageBackgroundIncomingMergedSideHighlightedImage: UIImage

public let chatMessageBackgroundOutgoingMaskImage: UIImage
public let chatMessageBackgroundOutgoingImage: UIImage
public let chatMessageBackgroundOutgoingHighlightedImage: UIImage
public let chatMessageBackgroundOutgoingMergedTopMaskImage: UIImage
public let chatMessageBackgroundOutgoingMergedTopImage: UIImage
public let chatMessageBackgroundOutgoingMergedTopHighlightedImage: UIImage
public let chatMessageBackgroundOutgoingMergedTopSideMaskImage: UIImage
public let chatMessageBackgroundOutgoingMergedTopSideImage: UIImage
public let chatMessageBackgroundOutgoingMergedTopSideHighlightedImage: UIImage
public let chatMessageBackgroundOutgoingMergedBottomMaskImage: UIImage
public let chatMessageBackgroundOutgoingMergedBottomImage: UIImage
public let chatMessageBackgroundOutgoingMergedBottomHighlightedImage: UIImage
public let chatMessageBackgroundOutgoingMergedBothMaskImage: UIImage
public let chatMessageBackgroundOutgoingMergedBothImage: UIImage
public let chatMessageBackgroundOutgoingMergedBothHighlightedImage: UIImage
public let chatMessageBackgroundOutgoingMergedSideMaskImage: UIImage
public let chatMessageBackgroundOutgoingMergedSideImage: UIImage
public let chatMessageBackgroundOutgoingMergedSideHighlightedImage: UIImage

public let checkBubbleFullImage: UIImage
public let checkBubblePartialImage: UIImage
public let checkMediaFullImage: UIImage
public let checkMediaPartialImage: UIImage
public let checkFreeFullImage: UIImage
public let checkFreePartialImage: UIImage
public let clockBubbleIncomingFrameImage: UIImage
public let clockBubbleIncomingMinImage: UIImage
public let clockBubbleIncomingHourImage: UIImage
public let clockBubbleOutgoingFrameImage: UIImage
public let clockBubbleOutgoingMinImage: UIImage
public let clockBubbleOutgoingHourImage: UIImage
public let clockMediaFrameImage: UIImage
public let clockMediaHourImage: UIImage
public let clockMediaMinImage: UIImage
public let clockFreeFrameImage: UIImage
public let clockFreeHourImage: UIImage
public let clockFreeMinImage: UIImage

public let dateAndStatusMediaBackground: UIImage
public let dateAndStatusFreeBackground: UIImage
public let incomingDateAndStatusImpressionIcon: UIImage
public let outgoingDateAndStatusImpressionIcon: UIImage
public let mediaImpressionIcon: UIImage
public let freeImpressionIcon: UIImage

public let dateStaticBackground: UIImage
public let dateFloatingBackground: UIImage

public let radialIndicatorFileIconIncoming: UIImage
public let radialIndicatorFileIconOutgoing: UIImage

public let incomingBubbleGradientImage: UIImage?
public let outgoingBubbleGradientImage: UIImage?

messageBubbleImage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
public func messageBubbleImage(incoming: Bool, fillColor: UIColor, strokeColor: UIColor, neighbors: MessageBubbleImageNeighbors, theme: PresentationThemeChat, wallpaper: UChatWallpaper, knockout knockoutValue: Bool, mask: Bool = false) -> UIImage{
    let diameter: CGFloat = 36.0
    let corner: CGFloat = 10.0
    let knockout = knockoutValue && !mask
    
    return generateImage(CGSize(width: 42.0, height: diameter), contextGenerator: { size, context in
        var drawWithClearColor = false
        
        if knockout, case let .color(color) = wallpaper {
            drawWithClearColor = !mask
            context.setFillColor(UIColor(rgb: UInt32(color)).cgColor)
            context.fill(CGRect(origin: CGPoint(), size: size))
        } else {
            context.clear(CGRect(origin: CGPoint(), size: size))
        }
        
        let additionalOffset: CGFloat = 0.0
        
        context.translateBy(x: size.width / 2.0, y: size.height / 2.0)
        context.scaleBy(x: incoming ? 1.0 : -1.0, y: -1.0)
        context.translateBy(x: -size.width / 2.0 + 0.5 + additionalOffset, y: -size.height / 2.0 + 0.5)
        
        
        let lineWidth: CGFloat = 1.0
        if drawWithClearColor {
            context.setBlendMode(.copy)
            context.setFillColor(UIColor.clear.cgColor)
        } else {
            context.setFillColor(fillColor.cgColor)
            context.setLineWidth(lineWidth)
            context.setStrokeColor(strokeColor.cgColor)
        }
        
        switch neighbors {
        case .none,.top(_),.bottom,.both:
            let corners:UIRectCorner =  [.topRight, .bottomLeft, .bottomRight]
            let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 40.0, height: diameter), byRoundingCorners: corners, cornerRadii: CGSize(width: corner, height: corner))
            context.addPath(path.cgPath)
            context.fillPath()
        case .all:
            let corners:UIRectCorner =  [.allCorners]
            let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: 40.0, height: diameter), byRoundingCorners: corners, cornerRadii: CGSize(width: corner, height: corner))
            context.addPath(path.cgPath)
            context.fillPath()
        case .side:
            if !drawWithClearColor {
                context.strokeEllipse(in: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: 35.0, height: 35.0)))
                context.strokePath()
            }
            context.fillEllipse(in: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: 35.0, height: 35.0)))
        }
    })!.stretchableImage(withLeftCapWidth: incoming ? Int(corner + diameter / 2.0) : Int(diameter / 2.0), topCapHeight: Int(diameter / 2.0))
}
This post is licensed under CC BY 4.0 by the author.