mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
7d373c07a3
* remove iOS 16 support * remove iOS 16 support * test updates * added more delay * revert * adding waiting time on the CI
65 lines
2.4 KiB
Swift
65 lines
2.4 KiB
Swift
//
|
|
// Copyright 2023, 2024 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
// Please see LICENSE in the repository root for full details.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct PillView: View {
|
|
let mediaProvider: MediaProviderProtocol?
|
|
@ObservedObject var context: PillContext
|
|
/// callback triggerd by changes in the display text
|
|
let didChangeText: () -> Void
|
|
|
|
var textColor: Color {
|
|
context.viewState.isOwnMention ? .compound._textOwnPill : .compound.textPrimary
|
|
}
|
|
|
|
var backgroundColor: Color {
|
|
context.viewState.isOwnMention ? .compound._bgOwnPill : .compound._bgPill
|
|
}
|
|
|
|
var body: some View {
|
|
Text(context.viewState.displayText)
|
|
.font(.compound.bodyLGSemibold)
|
|
.foregroundColor(textColor)
|
|
.lineLimit(1)
|
|
.padding(.leading, 4)
|
|
.padding(.trailing, 6)
|
|
.padding(.vertical, 1)
|
|
.background { Capsule().foregroundColor(backgroundColor) }
|
|
.onChange(of: context.viewState.displayText) {
|
|
didChangeText()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct PillView_Previews: PreviewProvider, TestablePreview {
|
|
static let mockMediaProvider = MediaProviderMock(configuration: .init())
|
|
|
|
static var previews: some View {
|
|
PillView(mediaProvider: mockMediaProvider,
|
|
context: PillContext.mock(type: .loadUser(isOwn: false))) { }
|
|
.frame(maxWidth: PillConstants.mockMaxWidth)
|
|
.previewDisplayName("Loading")
|
|
PillView(mediaProvider: mockMediaProvider,
|
|
context: PillContext.mock(type: .loadUser(isOwn: true))) { }
|
|
.frame(maxWidth: PillConstants.mockMaxWidth)
|
|
.previewDisplayName("Loading Own")
|
|
PillView(mediaProvider: mockMediaProvider,
|
|
context: PillContext.mock(type: .loadedUser(isOwn: false))) { }
|
|
.frame(maxWidth: PillConstants.mockMaxWidth)
|
|
.previewDisplayName("Loaded Long")
|
|
PillView(mediaProvider: mockMediaProvider,
|
|
context: PillContext.mock(type: .loadedUser(isOwn: true))) { }
|
|
.frame(maxWidth: PillConstants.mockMaxWidth)
|
|
.previewDisplayName("Loaded Long Own")
|
|
PillView(mediaProvider: mockMediaProvider,
|
|
context: PillContext.mock(type: .allUsers)) { }
|
|
.frame(maxWidth: PillConstants.mockMaxWidth)
|
|
.previewDisplayName("All Users")
|
|
}
|
|
}
|