2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// Theme.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 2/24/22.
|
2023-03-17 15:56:19 +00:00
|
|
|
// Copyright (c) 2023 Davide De Rosa. All rights reserved.
|
2022-04-12 13:09:14 +00:00
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-06-23 21:31:01 +00:00
|
|
|
import PassepartoutLibrary
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
extension View {
|
|
|
|
var themeIdiom: UIUserInterfaceIdiom {
|
|
|
|
UIDevice.current.userInterfaceIdiom
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-19 18:11:08 +00:00
|
|
|
var themeIsiPadPortrait: Bool {
|
2022-05-15 18:50:01 +00:00
|
|
|
#if targetEnvironment(macCatalyst)
|
|
|
|
false
|
|
|
|
#else
|
2022-05-19 18:11:08 +00:00
|
|
|
let device: UIDevice = .current
|
|
|
|
return device.userInterfaceIdiom == .pad && device.orientation.isPortrait
|
2022-05-15 18:50:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-19 18:11:08 +00:00
|
|
|
var themeIsiPadMultitasking: Bool {
|
2022-05-15 18:50:01 +00:00
|
|
|
#if targetEnvironment(macCatalyst)
|
|
|
|
false
|
|
|
|
#else
|
2022-05-19 18:11:08 +00:00
|
|
|
guard #available(iOS 15, *) else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return UIDevice.current.userInterfaceIdiom == .pad
|
2022-05-15 18:50:01 +00:00
|
|
|
#endif
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-27 14:13:01 +00:00
|
|
|
// MARK: Global
|
2022-04-12 13:09:14 +00:00
|
|
|
|
|
|
|
extension View {
|
|
|
|
func themeGlobal() -> some View {
|
2022-05-04 17:38:44 +00:00
|
|
|
themeNavigationViewStyle()
|
|
|
|
.themeTint()
|
2022-05-20 08:52:09 +00:00
|
|
|
.listStyle(themeListStyleValue())
|
|
|
|
.toggleStyle(themeToggleStyleValue())
|
2022-05-04 17:38:44 +00:00
|
|
|
.menuStyle(.borderlessButton)
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2022-05-04 17:38:44 +00:00
|
|
|
|
2022-05-20 08:52:09 +00:00
|
|
|
func themePrimaryView() -> some View {
|
|
|
|
#if targetEnvironment(macCatalyst)
|
|
|
|
navigationBarTitleDisplayMode(.inline)
|
|
|
|
.themeSidebarListStyle()
|
|
|
|
#else
|
|
|
|
navigationBarTitleDisplayMode(.large)
|
|
|
|
.navigationTitle(Unlocalized.appName)
|
|
|
|
.themeSidebarListStyle()
|
|
|
|
#endif
|
2022-05-04 17:38:44 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 08:52:09 +00:00
|
|
|
func themeSecondaryView() -> some View {
|
|
|
|
navigationBarTitleDisplayMode(.inline)
|
2022-05-04 17:38:44 +00:00
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
@ViewBuilder
|
|
|
|
private func themeNavigationViewStyle() -> some View {
|
2022-04-18 10:01:42 +00:00
|
|
|
switch themeIdiom {
|
2022-04-12 13:09:14 +00:00
|
|
|
case .phone:
|
|
|
|
navigationViewStyle(.stack)
|
|
|
|
|
|
|
|
default:
|
|
|
|
navigationViewStyle(.automatic)
|
|
|
|
}
|
|
|
|
}
|
2022-05-01 11:12:12 +00:00
|
|
|
|
2022-05-20 08:52:09 +00:00
|
|
|
@ViewBuilder
|
|
|
|
private func themeSidebarListStyle() -> some View {
|
|
|
|
switch themeIdiom {
|
2022-05-24 07:15:21 +00:00
|
|
|
case .phone:
|
|
|
|
listStyle(.insetGrouped)
|
2022-05-20 08:52:09 +00:00
|
|
|
|
|
|
|
default:
|
2022-05-24 07:15:21 +00:00
|
|
|
listStyle(.sidebar)
|
2022-05-20 08:52:09 +00:00
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-20 08:52:09 +00:00
|
|
|
@ViewBuilder
|
|
|
|
private func themeTint() -> some View {
|
|
|
|
if #available(iOS 15, *) {
|
|
|
|
tint(.accentColor)
|
|
|
|
} else {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func themeListStyleValue() -> some ListStyle {
|
|
|
|
.insetGrouped
|
|
|
|
}
|
|
|
|
|
|
|
|
private func themeToggleStyleValue() -> some ToggleStyle {
|
|
|
|
if #available(iOS 15, *) {
|
|
|
|
return .switch
|
|
|
|
} else {
|
|
|
|
return SwitchToggleStyle(tint: .accentColor)
|
|
|
|
}
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Colors
|
|
|
|
|
|
|
|
extension View {
|
2022-04-23 09:42:26 +00:00
|
|
|
fileprivate var themePrimaryBackgroundColor: Color {
|
2022-04-12 13:09:14 +00:00
|
|
|
Color(Asset.Assets.primaryColor.color)
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
fileprivate var themeSecondaryColor: Color {
|
2022-04-12 13:09:14 +00:00
|
|
|
.secondary
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
fileprivate var themeLightTextColor: Color {
|
2022-04-12 13:09:14 +00:00
|
|
|
Color(Asset.Assets.lightTextColor.color)
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
fileprivate var themeErrorColor: Color {
|
2022-04-12 13:09:14 +00:00
|
|
|
.red
|
|
|
|
}
|
|
|
|
|
|
|
|
private func themeColor(_ string: String?, validator: (String) throws -> Void) -> Color? {
|
|
|
|
guard let string = string else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
try validator(string)
|
|
|
|
return nil
|
|
|
|
} catch {
|
|
|
|
return themeErrorColor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Images
|
|
|
|
|
|
|
|
extension View {
|
|
|
|
var themeAssetsLogoImage: String {
|
2022-05-20 20:46:59 +00:00
|
|
|
"Logo"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
var themeCheckmarkImage: String {
|
|
|
|
"checkmark"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
var themeShareImage: String {
|
|
|
|
"square.and.arrow.up"
|
|
|
|
}
|
2022-08-27 20:16:41 +00:00
|
|
|
|
|
|
|
var themeCopyImage: String {
|
|
|
|
"doc.on.doc"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
var themeCloseImage: String {
|
|
|
|
"xmark"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
var themeConceilImage: String {
|
|
|
|
"eye.slash"
|
|
|
|
}
|
|
|
|
|
|
|
|
var themeRevealImage: String {
|
|
|
|
"eye"
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Organizer
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
func themeAssetsProviderImage(_ providerName: ProviderName) -> String {
|
|
|
|
"providers/\(providerName)"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
func themeAssetsCountryImage(_ countryCode: String) -> String {
|
|
|
|
"flags/\(countryCode.lowercased())"
|
|
|
|
}
|
|
|
|
|
2022-04-12 16:51:24 +00:00
|
|
|
var themeProviderImage: String {
|
2022-04-27 11:40:05 +00:00
|
|
|
"externaldrive.connected.to.line.below"
|
2022-04-12 16:51:24 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 16:51:24 +00:00
|
|
|
var themeHostFilesImage: String {
|
2022-04-27 11:40:05 +00:00
|
|
|
"folder"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 16:51:24 +00:00
|
|
|
var themeHostTextImage: String {
|
|
|
|
"text.justify"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-08-27 20:42:52 +00:00
|
|
|
var themeSettingsImage: String {
|
|
|
|
"gearshape"
|
2022-05-05 07:52:45 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
var themeDonateImage: String {
|
|
|
|
"giftcard"
|
2022-04-18 10:01:42 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
var themeRedditImage: String {
|
|
|
|
"person.3"
|
|
|
|
}
|
|
|
|
|
|
|
|
var themeWriteReviewImage: String {
|
2022-05-05 07:52:45 +00:00
|
|
|
"star"
|
2022-05-05 07:51:17 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-18 10:01:42 +00:00
|
|
|
var themeAddMenuImage: String {
|
2022-04-12 13:09:14 +00:00
|
|
|
"plus"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-02 08:26:51 +00:00
|
|
|
var themeProfileActiveImage: String {
|
2022-05-03 17:24:46 +00:00
|
|
|
"checkmark.circle"
|
2022-05-02 08:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var themeProfileConnectedImage: String {
|
|
|
|
"circle.fill"
|
|
|
|
}
|
|
|
|
|
|
|
|
var themeProfileInactiveImage: String {
|
2022-05-03 17:24:46 +00:00
|
|
|
"circle"
|
2022-05-02 08:26:51 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
// MARK: Profile
|
|
|
|
|
|
|
|
var themeSettingsMenuImage: String {
|
|
|
|
"ellipsis.circle"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-10-17 15:36:32 +00:00
|
|
|
var themeReconnectImage: String {
|
|
|
|
"arrow.clockwise"
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeShortcutsImage: String {
|
2022-04-27 11:40:05 +00:00
|
|
|
"mic"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
var themeRenameProfileImage: String {
|
|
|
|
"highlighter"
|
|
|
|
// "character.cursor.ibeam"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-05 07:51:17 +00:00
|
|
|
var themeDuplicateImage: String {
|
|
|
|
"doc.on.doc"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-26 21:27:03 +00:00
|
|
|
var themeUninstallImage: String {
|
|
|
|
"arrow.uturn.down"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeDeleteImage: String {
|
2022-04-27 11:40:05 +00:00
|
|
|
"trash"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeVPNProtocolImage: String {
|
2022-04-27 11:40:05 +00:00
|
|
|
"bolt"
|
2022-04-12 13:09:14 +00:00
|
|
|
// "waveform.path.ecg"
|
|
|
|
// "message.and.waveform.fill"
|
|
|
|
// "pc"
|
|
|
|
// "captions.bubble.fill"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeEndpointImage: String {
|
|
|
|
"link"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeAccountImage: String {
|
2022-04-27 11:40:05 +00:00
|
|
|
"person"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeProviderLocationImage: String {
|
2022-04-27 11:40:05 +00:00
|
|
|
"location"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeProviderPresetImage: String {
|
|
|
|
"slider.horizontal.3"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeNetworkSettingsImage: String {
|
|
|
|
// "network"
|
|
|
|
"globe"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeOnDemandImage: String {
|
|
|
|
"wifi"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeDiagnosticsImage: String {
|
|
|
|
"bandage.fill"
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
var themeFAQImage: String {
|
2022-04-27 11:40:05 +00:00
|
|
|
"questionmark.diamond"
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func themeFavoritesImage(_ active: Bool) -> String {
|
|
|
|
active ? "bookmark.fill" : "bookmark"
|
|
|
|
}
|
|
|
|
|
|
|
|
func themeFavoriteActionImage(_ doFavorite: Bool) -> String {
|
|
|
|
doFavorite ? "bookmark" : "bookmark.slash.fill"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension String {
|
|
|
|
var asAssetImage: Image {
|
|
|
|
Image(self)
|
|
|
|
}
|
|
|
|
|
|
|
|
var asSystemImage: Image {
|
|
|
|
Image(systemName: self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
// MARK: Styles
|
|
|
|
|
|
|
|
extension View {
|
2022-05-04 17:38:44 +00:00
|
|
|
func themeAccentForegroundStyle() -> some View {
|
|
|
|
foregroundColor(.accentColor)
|
|
|
|
}
|
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
var themePrimaryBackground: some View {
|
|
|
|
themePrimaryBackgroundColor
|
|
|
|
.ignoresSafeArea()
|
|
|
|
}
|
|
|
|
|
|
|
|
func themeSecondaryTextStyle() -> some View {
|
|
|
|
foregroundColor(themeSecondaryColor)
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
func themeLightTextStyle() -> some View {
|
|
|
|
foregroundColor(themeLightTextColor)
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
@available(iOS 15, *)
|
|
|
|
func themePrimaryTintStyle() -> some View {
|
|
|
|
tint(themePrimaryBackgroundColor)
|
|
|
|
}
|
|
|
|
|
2022-04-23 09:27:17 +00:00
|
|
|
func themeTextButtonStyle() -> some View {
|
|
|
|
accentColor(.primary)
|
|
|
|
}
|
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
func themeLongTextStyle() -> some View {
|
|
|
|
lineLimit(1)
|
|
|
|
.truncationMode(.middle)
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-05-24 06:25:10 +00:00
|
|
|
func themeRawTextStyle() -> some View {
|
|
|
|
disableAutocorrection(true)
|
|
|
|
.autocapitalization(.none)
|
|
|
|
}
|
|
|
|
|
2022-04-23 09:42:26 +00:00
|
|
|
func themeInformativeTextStyle() -> some View {
|
|
|
|
multilineTextAlignment(.center)
|
|
|
|
.font(.title)
|
|
|
|
.foregroundColor(themeSecondaryColor)
|
|
|
|
}
|
|
|
|
|
|
|
|
func themeDebugLogStyle() -> some View {
|
|
|
|
font(.system(size: 13, weight: .medium, design: .monospaced))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-19 19:04:31 +00:00
|
|
|
// MARK: Shortcuts
|
|
|
|
|
|
|
|
extension ShortcutType {
|
|
|
|
var themeImageName: String {
|
|
|
|
switch self {
|
|
|
|
case .enableVPN:
|
|
|
|
return "power"
|
|
|
|
|
|
|
|
case .disableVPN:
|
|
|
|
return "xmark"
|
|
|
|
|
|
|
|
case .reconnectVPN:
|
|
|
|
return "arrow.clockwise"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-23 10:08:24 +00:00
|
|
|
// MARK: Animations
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-23 10:08:24 +00:00
|
|
|
extension View {
|
|
|
|
func themeAnimation<V: Equatable>(on value: V) -> some View {
|
|
|
|
animation(.default, value: value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension Binding {
|
|
|
|
func themeAnimation() -> Binding<Value> {
|
|
|
|
animation(.default)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
// MARK: Shortcuts
|
|
|
|
|
|
|
|
extension View {
|
2022-04-19 08:10:06 +00:00
|
|
|
func themeCloseItem(presentationMode: Binding<PresentationMode>) -> some ToolbarContent {
|
2022-04-19 21:11:04 +00:00
|
|
|
ToolbarItem(placement: .cancellationAction) {
|
2022-04-19 08:10:06 +00:00
|
|
|
Button {
|
|
|
|
presentationMode.wrappedValue.dismiss()
|
|
|
|
} label: {
|
|
|
|
themeCloseImage.asSystemImage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func themeCloseItem(isPresented: Binding<Bool>) -> some ToolbarContent {
|
2022-04-19 21:11:04 +00:00
|
|
|
ToolbarItem(placement: .cancellationAction) {
|
2022-04-19 08:10:06 +00:00
|
|
|
Button {
|
|
|
|
isPresented.wrappedValue = false
|
|
|
|
} label: {
|
|
|
|
themeCloseImage.asSystemImage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
func themeSaveButtonLabel() -> some View {
|
|
|
|
Text(L10n.Global.Strings.save)
|
|
|
|
}
|
|
|
|
|
2023-03-20 10:00:01 +00:00
|
|
|
func themeSecureField(_ placeholder: String, text: Binding<String>, contentType: UITextContentType = .password) -> some View {
|
|
|
|
RevealingSecureField(placeholder, text: text) {
|
|
|
|
themeConceilImage.asSystemImage
|
|
|
|
.themeAccentForegroundStyle()
|
|
|
|
} revealImage: {
|
|
|
|
themeRevealImage.asSystemImage
|
|
|
|
.themeAccentForegroundStyle()
|
|
|
|
}.textContentType(contentType)
|
|
|
|
.themeRawTextStyle()
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
func themeTextPicker<T: Hashable>(_ title: String, selection: Binding<T>, values: [T], description: @escaping (T) -> String) -> some View {
|
|
|
|
StyledPicker(title: title, selection: selection, values: values) {
|
|
|
|
Text(description($0))
|
|
|
|
} selectionLabel: {
|
|
|
|
Text(description($0))
|
|
|
|
.foregroundColor(themeSecondaryColor)
|
|
|
|
} listStyle: {
|
2022-05-20 08:52:09 +00:00
|
|
|
themeListStyleValue()
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-13 07:45:58 +00:00
|
|
|
|
|
|
|
func themeLongContentLinkDefault(_ title: String, content: Binding<String>) -> some View {
|
|
|
|
LongContentLink(title, content: content) {
|
|
|
|
Text($0)
|
|
|
|
.foregroundColor(themeSecondaryColor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
func themeLongContentLink(_ title: String, content: Binding<String>, withPreview preview: String? = nil) -> some View {
|
|
|
|
LongContentLink(title, content: content, preview: preview) {
|
|
|
|
Text(preview != nil ? $0 : "")
|
|
|
|
.foregroundColor(themeSecondaryColor)
|
|
|
|
}
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-12 13:09:14 +00:00
|
|
|
@ViewBuilder
|
|
|
|
func themeErrorMessage(_ message: String?) -> some View {
|
|
|
|
if let message = message {
|
|
|
|
if message.last != "." {
|
|
|
|
Text("\(message).")
|
|
|
|
.foregroundColor(themeErrorColor)
|
|
|
|
} else {
|
|
|
|
Text(message)
|
|
|
|
.foregroundColor(themeErrorColor)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
EmptyView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Validation
|
|
|
|
|
|
|
|
extension View {
|
2022-04-25 20:44:24 +00:00
|
|
|
func themeValidProfileName() -> some View {
|
2022-05-24 06:25:10 +00:00
|
|
|
themeRawTextStyle()
|
2022-04-25 13:20:19 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:44:24 +00:00
|
|
|
func themeValidURL(_ urlString: String?) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
themeValidating(urlString, validator: Validators.url)
|
|
|
|
.keyboardType(.asciiCapable)
|
2022-05-24 06:25:10 +00:00
|
|
|
.themeRawTextStyle()
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-25 20:44:24 +00:00
|
|
|
func themeValidIPAddress(_ ipAddress: String?) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
themeValidating(ipAddress, validator: Validators.ipAddress)
|
|
|
|
.keyboardType(.numbersAndPunctuation)
|
2022-05-24 06:25:10 +00:00
|
|
|
.themeRawTextStyle()
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-04-25 20:44:24 +00:00
|
|
|
func themeValidSocketPort() -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
keyboardType(.numberPad)
|
|
|
|
}
|
|
|
|
|
2022-04-25 20:44:24 +00:00
|
|
|
func themeValidDomainName(_ domainName: String?) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
themeValidating(domainName, validator: Validators.domainName)
|
|
|
|
.keyboardType(.asciiCapable)
|
2022-05-24 06:25:10 +00:00
|
|
|
.themeRawTextStyle()
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:44:24 +00:00
|
|
|
func themeValidDNSOverTLSServerName(_ string: String?) -> some View {
|
2022-04-25 20:36:05 +00:00
|
|
|
themeValidating(string, validator: Validators.dnsOverTLSServerName)
|
|
|
|
.keyboardType(.asciiCapable)
|
2022-05-24 06:25:10 +00:00
|
|
|
.themeRawTextStyle()
|
2022-04-25 20:36:05 +00:00
|
|
|
}
|
|
|
|
|
2022-04-25 20:44:24 +00:00
|
|
|
func themeValidSSID(_ text: String?) -> some View {
|
2022-04-12 13:09:14 +00:00
|
|
|
themeValidating(text, validator: Validators.notEmpty)
|
|
|
|
.keyboardType(.asciiCapable)
|
2022-05-24 06:25:10 +00:00
|
|
|
.themeRawTextStyle()
|
2022-04-12 13:09:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private func themeValidating(_ string: String?, validator: (String) throws -> Void) -> some View {
|
|
|
|
foregroundColor(themeColor(string, validator: validator))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Hacks
|
|
|
|
|
|
|
|
extension View {
|
2022-05-23 08:10:02 +00:00
|
|
|
@available(*, deprecated, message: "mitigates multiline text truncation (1.0 does not work though)")
|
2022-04-12 13:09:14 +00:00
|
|
|
func xxxThemeTruncation() -> some View {
|
|
|
|
minimumScaleFactor(0.5)
|
|
|
|
}
|
|
|
|
}
|