* refactored the static location screen to the location sharing screen # Conflicts: # UnitTests/Sources/LocationSharingScreenViewModelTests.swift # Conflicts: # ElementX.xcodeproj/project.pbxproj * implemented a custom pin with an overlayable view * implemented the render of the user when the location is sender instead of the pin type * removed description and body they are not used at all. * reimplemented single button for sharing this or user location + implemented an experimental way to update annotations * removed unnecessary @Suite description * implemented a way to display the alert on top of the sheet and added a spinner to the center user location button * fixed alerts strings * fixed a failing test * improved preview tests
92 lines
2.7 KiB
Swift
92 lines
2.7 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Compound
|
|
import SwiftUI
|
|
|
|
struct ToolbarButton: View {
|
|
@MainActor
|
|
enum Role {
|
|
static let cancel = Role.cancel(title: L10n.actionCancel)
|
|
static let done = Role.confirm(title: L10n.actionDone)
|
|
static let save = Role.confirm(title: L10n.actionSave)
|
|
static let close = Role.cancel(title: L10n.actionClose)
|
|
|
|
case cancel(title: String)
|
|
case confirm(title: String)
|
|
case destructive(title: String)
|
|
|
|
var title: String {
|
|
switch self {
|
|
case .cancel(let title), .confirm(let title), .destructive(let title):
|
|
title
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
var icon: some View {
|
|
switch self {
|
|
case .cancel:
|
|
CompoundIcon(\.close)
|
|
.foregroundStyle(.compound.iconPrimary)
|
|
case .confirm:
|
|
CompoundIcon(\.check)
|
|
.foregroundStyle(.compound.iconOnSolidPrimary)
|
|
case .destructive:
|
|
CompoundIcon(\.delete)
|
|
.foregroundStyle(.compound.iconOnSolidPrimary)
|
|
}
|
|
}
|
|
|
|
var tint: Color {
|
|
switch self {
|
|
case .cancel:
|
|
.compound.bgCanvasDefault
|
|
case .confirm:
|
|
.compound.bgAccentRest
|
|
case .destructive:
|
|
.compound.bgCriticalPrimary
|
|
}
|
|
}
|
|
}
|
|
|
|
let role: Role
|
|
let action: () -> Void
|
|
|
|
var body: some View {
|
|
if #available(iOS 26, *) {
|
|
Button(action: action) {
|
|
role.icon
|
|
.accessibilityLabel(role.title)
|
|
}
|
|
.tint(role.tint)
|
|
.backportButtonStyleGlassProminent()
|
|
} else {
|
|
Button(role.title, action: action)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ToolbarButton_Previews: PreviewProvider, TestablePreview {
|
|
static var previews: some View {
|
|
ElementNavigationStack {
|
|
Color.clear
|
|
.toolbar {
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
ToolbarButton(role: .done) { }
|
|
}
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
ToolbarButton(role: .cancel) { }
|
|
}
|
|
ToolbarItem(placement: .primaryAction) {
|
|
ToolbarButton(role: .destructive(title: L10n.actionRemove)) { }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|