mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Simplify how we build bubbles for previewing purposes, make use of the new bubbleBackground modifier.
This commit is contained in:
committed by
Stefan Ceriu
parent
681daf50ea
commit
c97dcc18f2
@@ -95,9 +95,7 @@ struct LongPressWithFeedback_Previews: PreviewProvider, TestablePreview {
|
||||
|
||||
func mockBubble(_ body: String) -> some View {
|
||||
Text(body)
|
||||
.padding(.horizontal, 12)
|
||||
.padding(.vertical, 4)
|
||||
.background(Color.compound._bgBubbleOutgoing, in: RoundedRectangle(cornerRadius: 12))
|
||||
.bubbleBackground()
|
||||
.contentShape(.contextMenuPreview, RoundedRectangle(cornerRadius: 12))
|
||||
.onTapGesture { /* Fix long press gesture blocking the scroll view */ }
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
extension View {
|
||||
func bubbleBackground(isOutgoing: Bool,
|
||||
insets: EdgeInsets,
|
||||
color: Color? = nil) -> some View {
|
||||
func bubbleBackground(isOutgoing: Bool = true,
|
||||
insets: EdgeInsets = .init(top: 8, leading: 12, bottom: 8, trailing: 12),
|
||||
color: Color? = .compound.bgSubtleSecondary) -> some View {
|
||||
modifier(TimelineItemBubbleBackgroundModifier(isOutgoing: isOutgoing,
|
||||
insets: insets,
|
||||
color: color))
|
||||
|
||||
@@ -189,18 +189,18 @@ struct FormattedBodyText_Previews: PreviewProvider, TestablePreview {
|
||||
ForEach(htmlStrings, id: \.self) { htmlString in
|
||||
if let attributedString = attributedStringBuilder.fromHTML(htmlString) {
|
||||
FormattedBodyText(attributedString: attributedString)
|
||||
.previewBubble()
|
||||
.bubbleBackground()
|
||||
}
|
||||
}
|
||||
FormattedBodyText(attributedString: AttributedString("Some plain text wrapped in an AttributedString."))
|
||||
.previewBubble()
|
||||
.bubbleBackground()
|
||||
FormattedBodyText(text: "Some plain text that's not an attributed component.")
|
||||
.previewBubble()
|
||||
.bubbleBackground()
|
||||
FormattedBodyText(text: "Some plain text that's not an attributed component. This one is really long.")
|
||||
.previewBubble()
|
||||
.bubbleBackground()
|
||||
|
||||
FormattedBodyText(text: "❤️", boostEmojiSize: true)
|
||||
.previewBubble()
|
||||
.bubbleBackground()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
@@ -208,19 +208,3 @@ struct FormattedBodyText_Previews: PreviewProvider, TestablePreview {
|
||||
.snapshotPreferences(delay: 0.25)
|
||||
}
|
||||
}
|
||||
|
||||
private struct PreviewBubbleModifier: ViewModifier {
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.padding(8)
|
||||
.background(Color.compound._bgBubbleOutgoing)
|
||||
.cornerRadius(12)
|
||||
.environmentObject(TimelineViewModel.mock.context)
|
||||
}
|
||||
}
|
||||
|
||||
private extension View {
|
||||
func previewBubble() -> some View {
|
||||
modifier(PreviewBubbleModifier())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user