Skip to content

Commit

Permalink
Merge pull request #16 from shortcut/feature/multiple-corner-rounding…
Browse files Browse the repository at this point in the history
…-support

Added simple corner rounding support for text messages
  • Loading branch information
EnesKaraosman authored Oct 11, 2021
2 parents 46fbb00 + 8f066ba commit 80dd800
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
19 changes: 19 additions & 0 deletions Sources/SwiftyChat/Common/Other/RoundedCornerShape.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// RoundedCornerShape.swift
//
//
// Created by Karl Söderberg on 2021-10-11.
//

import SwiftUI

struct RoundedCornerShape: Shape {

var radius: CGFloat = .infinity
var corners: UIRectCorner = .allCorners

func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
return Path(path.cgPath)
}
}
10 changes: 6 additions & 4 deletions Sources/SwiftyChat/MessageCells/TextCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ internal struct TextCell<Message: ChatMessage>: View {
.foregroundColor(cellStyle.textStyle.textColor)
.padding(cellStyle.textPadding)
.background(cellStyle.cellBackgroundColor)
.clipShape(RoundedRectangle(cornerRadius: cellStyle.cellCornerRadius))
.clipShape(RoundedCornerShape(radius: cellStyle.cellCornerRadius, corners: cellStyle.cellRoundedCorners)
)
.overlay(
RoundedRectangle(cornerRadius: cellStyle.cellCornerRadius)

RoundedCornerShape(radius: cellStyle.cellCornerRadius, corners: cellStyle.cellRoundedCorners)
.stroke(
cellStyle.cellBorderColor,
lineWidth: cellStyle.cellBorderWidth
Expand Down Expand Up @@ -91,9 +93,9 @@ internal struct TextCell<Message: ChatMessage>: View {
.frame(width: textWidth, height: textHeight)
.padding(cellStyle.textPadding)
.background(cellStyle.cellBackgroundColor)
.clipShape(RoundedRectangle(cornerRadius: cellStyle.cellCornerRadius))
.clipShape(RoundedCornerShape(radius: cellStyle.cellCornerRadius, corners: cellStyle.cellRoundedCorners))
.overlay(
RoundedRectangle(cornerRadius: cellStyle.cellCornerRadius)
RoundedCornerShape(radius: cellStyle.cellCornerRadius, corners: cellStyle.cellRoundedCorners)
.stroke(
cellStyle.cellBorderColor,
lineWidth: cellStyle.cellBorderWidth
Expand Down
6 changes: 5 additions & 1 deletion Sources/SwiftyChat/Styles/TextCellStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import SwiftUI
import UIKit

public struct TextCellStyle: CommonViewStyle {

Expand All @@ -21,6 +22,7 @@ public struct TextCellStyle: CommonViewStyle {
public let cellBorderWidth: CGFloat
public let cellShadowRadius: CGFloat
public let cellShadowColor: Color
public let cellRoundedCorners: UIRectCorner

public init(
textStyle: CommonTextStyle = CommonTextStyle(
Expand All @@ -35,7 +37,8 @@ public struct TextCellStyle: CommonViewStyle {
cellBorderColor: Color = .clear,
cellBorderWidth: CGFloat = 1,
cellShadowRadius: CGFloat = 3,
cellShadowColor: Color = .secondary
cellShadowColor: Color = .secondary,
cellRoundedCorners: UIRectCorner = .allCorners
) {
self.textStyle = textStyle
self.textPadding = textPadding
Expand All @@ -46,6 +49,7 @@ public struct TextCellStyle: CommonViewStyle {
self.cellBorderWidth = cellBorderWidth
self.cellShadowRadius = cellShadowRadius
self.cellShadowColor = cellShadowColor
self.cellRoundedCorners = cellRoundedCorners
}

}
6 changes: 4 additions & 2 deletions SwiftyChatExample/SwiftyChatExample/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ internal extension ChatMessageCellStyle {
attributedTextStyle: .init(textColor: .black),
cellBackgroundColor: Color.chatGray,
cellBorderWidth: 0,
cellShadowRadius: 0
cellShadowRadius: 0,
cellRoundedCorners: [.topRight, .bottomRight, .bottomLeft]
),
outgoingTextStyle: .init(
textStyle: .init(textColor: .white, font: futuraFont),
textPadding: 16,
cellBackgroundColor: Color.chatBlue,
cellBorderWidth: 0,
cellShadowRadius: 0
cellShadowRadius: 0,
cellRoundedCorners: [.topLeft, .bottomRight, .bottomLeft]
),
incomingAvatarStyle: .init(imageStyle: .init(imageSize: .zero))
)
Expand Down

0 comments on commit 80dd800

Please sign in to comment.