mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-06 04:18:31 +00:00
Fixes #296 - Improved bubble timeline item corner radii
This commit is contained in:
committed by
Stefan Ceriu
parent
2bce779206
commit
ce6b0041d2
@@ -25,10 +25,6 @@ struct RoundedCornerShape: Shape {
|
|||||||
self.corners = corners
|
self.corners = corners
|
||||||
}
|
}
|
||||||
|
|
||||||
init(radius: CGFloat, inGroupState: TimelineItemInGroupState) {
|
|
||||||
self.init(radius: radius, corners: inGroupState.roundedCorners)
|
|
||||||
}
|
|
||||||
|
|
||||||
func path(in rect: CGRect) -> Path {
|
func path(in rect: CGRect) -> Path {
|
||||||
let path = UIBezierPath(roundedRect: rect,
|
let path = UIBezierPath(roundedRect: rect,
|
||||||
byRoundingCorners: corners,
|
byRoundingCorners: corners,
|
||||||
@@ -41,8 +37,4 @@ extension View {
|
|||||||
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
|
func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View {
|
||||||
clipShape(RoundedCornerShape(radius: radius, corners: corners))
|
clipShape(RoundedCornerShape(radius: radius, corners: corners))
|
||||||
}
|
}
|
||||||
|
|
||||||
func cornerRadius(_ radius: CGFloat, inGroupState: TimelineItemInGroupState) -> some View {
|
|
||||||
clipShape(RoundedCornerShape(radius: radius, inGroupState: inGroupState))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
|||||||
|
|
||||||
if shouldAvoidBubbling {
|
if shouldAvoidBubbling {
|
||||||
content()
|
content()
|
||||||
.cornerRadius(12, inGroupState: timelineItem.inGroupState)
|
.cornerRadius(12, corners: timelineItem.roundedCorners)
|
||||||
.padding(.top, topPadding)
|
.padding(.top, topPadding)
|
||||||
} else {
|
} else {
|
||||||
VStack(alignment: .trailing, spacing: 4) {
|
VStack(alignment: .trailing, spacing: 4) {
|
||||||
@@ -115,7 +115,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
.padding(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12))
|
.padding(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12))
|
||||||
.background(Color.element.systemGray5)
|
.background(Color.element.systemGray5)
|
||||||
.cornerRadius(12, inGroupState: timelineItem.inGroupState)
|
.cornerRadius(12, corners: timelineItem.roundedCorners)
|
||||||
.padding(.top, topPadding)
|
.padding(.top, topPadding)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
|||||||
var styledContentIncoming: some View {
|
var styledContentIncoming: some View {
|
||||||
if shouldAvoidBubbling {
|
if shouldAvoidBubbling {
|
||||||
content()
|
content()
|
||||||
.cornerRadius(12, inGroupState: timelineItem.inGroupState)
|
.cornerRadius(12, corners: timelineItem.roundedCorners)
|
||||||
} else {
|
} else {
|
||||||
VStack(alignment: .trailing, spacing: 4) {
|
VStack(alignment: .trailing, spacing: 4) {
|
||||||
content()
|
content()
|
||||||
@@ -136,8 +136,8 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12))
|
.padding(EdgeInsets(top: 6, leading: 12, bottom: 6, trailing: 12))
|
||||||
.background(Color.element.systemGray6) // Demo time!
|
.background(Color.element.systemGray6)
|
||||||
.cornerRadius(12, inGroupState: timelineItem.inGroupState)
|
.cornerRadius(12, corners: timelineItem.roundedCorners)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+21
-13
@@ -23,19 +23,6 @@ enum TimelineItemInGroupState {
|
|||||||
case middle
|
case middle
|
||||||
case end
|
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 {
|
var shouldShowSenderDetails: Bool {
|
||||||
switch self {
|
switch self {
|
||||||
case .single, .beginning:
|
case .single, .beginning:
|
||||||
@@ -65,4 +52,25 @@ extension EventBasedTimelineItemProtocol {
|
|||||||
var shouldShowSenderDetails: Bool {
|
var shouldShowSenderDetails: Bool {
|
||||||
inGroupState.shouldShowSenderDetails
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user