Skip to content

Commit

Permalink
Fixes #296 - Improved bubble timeline item corner radii
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Nov 16, 2022
1 parent 2bce779 commit ce6b004
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
8 changes: 0 additions & 8 deletions ElementX/Sources/Other/SwiftUI/Views/RoundedCornerShape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ struct RoundedCornerShape: Shape {
self.corners = corners
}

init(radius: CGFloat, inGroupState: TimelineItemInGroupState) {
self.init(radius: radius, corners: inGroupState.roundedCorners)
}

func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect,
byRoundingCorners: corners,
Expand All @@ -41,8 +37,4 @@ extension View {
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
clipShape(RoundedCornerShape(radius: radius, corners: corners))
}

func cornerRadius(_ radius: CGFloat, inGroupState: TimelineItemInGroupState) -> some View {
clipShape(RoundedCornerShape(radius: radius, inGroupState: inGroupState))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {

if shouldAvoidBubbling {
content()
.cornerRadius(12, inGroupState: timelineItem.inGroupState)
.cornerRadius(12, corners: timelineItem.roundedCorners)
.padding(.top, topPadding)
} else {
VStack(alignment: .trailing, spacing: 4) {
Expand All @@ -115,7 +115,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
}
.padding(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12))
.background(Color.element.systemGray5)
.cornerRadius(12, inGroupState: timelineItem.inGroupState)
.cornerRadius(12, corners: timelineItem.roundedCorners)
.padding(.top, topPadding)
}
}
Expand All @@ -124,7 +124,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
var styledContentIncoming: some View {
if shouldAvoidBubbling {
content()
.cornerRadius(12, inGroupState: timelineItem.inGroupState)
.cornerRadius(12, corners: timelineItem.roundedCorners)
} else {
VStack(alignment: .trailing, spacing: 4) {
content()
Expand All @@ -136,8 +136,8 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
}
}
.padding(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12))
.background(Color.element.systemGray6) // Demo time!
.cornerRadius(12, inGroupState: timelineItem.inGroupState)
.background(Color.element.systemGray6)
.cornerRadius(12, corners: timelineItem.roundedCorners)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ enum TimelineItemInGroupState {
case middle
case end

var roundedCorners: UIRectCorner {
switch self {
case .single:
return .allCorners
case .beginning:
return [.topLeft, .topRight]
case .middle:
return []
case .end:
return [.bottomLeft, .bottomRight]
}
}

var shouldShowSenderDetails: Bool {
switch self {
case .single, .beginning:
Expand Down Expand Up @@ -65,4 +52,25 @@ extension EventBasedTimelineItemProtocol {
var shouldShowSenderDetails: Bool {
inGroupState.shouldShowSenderDetails
}

var roundedCorners: UIRectCorner {
switch inGroupState {
case .single:
return .allCorners
case .beginning:
if isOutgoing {
return [.topLeft, .topRight, .bottomLeft]
} else {
return [.topLeft, .topRight, .bottomRight]
}
case .middle:
return isOutgoing ? [.topLeft, .bottomLeft] : [.topRight, .bottomRight]
case .end:
if isOutgoing {
return [.topLeft, .bottomLeft, .bottomRight]
} else {
return [.topRight, .bottomLeft, .bottomRight]
}
}
}
}

0 comments on commit ce6b004

Please sign in to comment.