-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Backend redirect UI - WPB-15224 (#2404)
Co-authored-by: El-Fitz <[email protected]>
- Loading branch information
1 parent
868841c
commit b4d966a
Showing
22 changed files
with
515 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
WireUI/Sources/WireAuthenticationUI/Models/BackendEnvironmentInfo.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program 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. | ||
// | ||
// This program 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 this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import Foundation | ||
|
||
struct BackendEnvironmentInfo: Sendable { | ||
|
||
let title: String | ||
let backendURL: URL | ||
let backendWSURL: URL | ||
let blacklistURL: URL | ||
let teamsURL: URL | ||
let accountsURL: URL | ||
let websiteURL: URL | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
WireUI/Sources/WireAuthenticationUI/ViewModels/SwitchBackendConfirmationViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program 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. | ||
// | ||
// This program 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 this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import Foundation | ||
|
||
package class SwitchBackendConfirmationViewModel { | ||
|
||
private typealias Strings = L10n.SwitchBackendConfirmation | ||
|
||
// MARK: - State | ||
|
||
let items: [ItemUIModel] | ||
|
||
private let action: (Event) -> Void | ||
|
||
// MARK: - Life cycle | ||
|
||
convenience init( | ||
environment: BackendEnvironmentInfo, | ||
action: @escaping (Event) -> Void | ||
) { | ||
self.init( | ||
backendName: environment.title, | ||
backendURL: environment.backendURL.absoluteString, | ||
backendWSURL: environment.backendWSURL.absoluteString, | ||
blacklistURL: environment.blacklistURL.absoluteString, | ||
teamsURL: environment.teamsURL.absoluteString, | ||
accountsURL: environment.accountsURL.absoluteString, | ||
websiteURL: environment.websiteURL.absoluteString, | ||
action: action | ||
) | ||
} | ||
|
||
package init( | ||
backendName: String, | ||
backendURL: String, | ||
backendWSURL: String, | ||
blacklistURL: String, | ||
teamsURL: String, | ||
accountsURL: String, | ||
websiteURL: String, | ||
action: @escaping (Event) -> Void | ||
) { | ||
self.action = action | ||
self.items = [ | ||
ItemUIModel(title: Strings.backendName, value: backendName, isURL: false), | ||
ItemUIModel(title: Strings.backendUrl, value: backendURL, isURL: true), | ||
ItemUIModel(title: Strings.backendWsurl, value: backendWSURL, isURL: true), | ||
ItemUIModel(title: Strings.blacklistUrl, value: blacklistURL, isURL: true), | ||
ItemUIModel(title: Strings.teamsUrl, value: teamsURL, isURL: true), | ||
ItemUIModel(title: Strings.accountsUrl, value: accountsURL, isURL: true), | ||
ItemUIModel(title: Strings.websiteUrl, value: websiteURL, isURL: true) | ||
] | ||
} | ||
|
||
// MARK: - Events | ||
|
||
package enum Event { | ||
|
||
case didCancel | ||
case didConfirm | ||
|
||
} | ||
|
||
func handleEvent(_ event: Event) { | ||
action(event) | ||
} | ||
|
||
// MARK: - Model | ||
|
||
package struct ItemUIModel { | ||
let title: String | ||
let value: String | ||
let isURL: Bool | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
WireUI/Sources/WireAuthenticationUI/Views/Preview/SwitchBackendConfirmationViewPreview.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program 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. | ||
// | ||
// This program 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 this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import SwiftUI | ||
|
||
package struct SwitchBackendConfirmationViewPreview: View { | ||
package init() {} | ||
|
||
package var body: some View { | ||
VStack { | ||
SwitchBackendConfirmationView( | ||
viewModel: SwitchBackendConfirmationViewModel( | ||
backendName: "Staging", | ||
backendURL: "www.staging.com", | ||
backendWSURL: "www.ws.staging.com", | ||
blacklistURL: "www.blacklist.staging.com", | ||
teamsURL: "www.teams.staging.com", | ||
accountsURL: "www.accounts.staging.com", | ||
websiteURL: "www.wire.com", | ||
action: { _ in } | ||
) | ||
) | ||
} | ||
} | ||
|
||
} |
202 changes: 202 additions & 0 deletions
202
WireUI/Sources/WireAuthenticationUI/Views/SwitchBackendConfirmationView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
// | ||
// Wire | ||
// Copyright (C) 2025 Wire Swiss GmbH | ||
// | ||
// This program 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. | ||
// | ||
// This program 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 this program. If not, see http://www.gnu.org/licenses/. | ||
// | ||
|
||
import SwiftUI | ||
import WireDesign | ||
|
||
package struct SwitchBackendConfirmationView: View { | ||
|
||
// MARK: - Properties | ||
|
||
@Environment(\.dismiss) var dismiss | ||
@State private var showFullDetails: Bool = false | ||
|
||
private typealias Strings = L10n.SwitchBackendConfirmation | ||
|
||
private let viewModel: SwitchBackendConfirmationViewModel | ||
|
||
package init( | ||
viewModel: SwitchBackendConfirmationViewModel | ||
) { | ||
self.viewModel = viewModel | ||
} | ||
|
||
package var body: some View { | ||
VStack(spacing: 20) { | ||
title | ||
backendDetails | ||
buttons | ||
} | ||
.padding() | ||
.interactiveDismissDisabled() | ||
.background(ColorTheme.Backgrounds.surface.color) | ||
.cornerRadius(16) | ||
.overlay( | ||
RoundedRectangle(cornerRadius: 16) | ||
.stroke(ColorTheme.Backgrounds.surface.color, lineWidth: 1) | ||
) | ||
.fixedSize(horizontal: false, vertical: true) | ||
} | ||
|
||
private var title: some View { | ||
Text(Strings.title) | ||
.font(.textStyle(.h2)) | ||
.foregroundStyle(Color.primaryText) | ||
.multilineTextAlignment(.center) | ||
.lineLimit(nil) | ||
.minimumScaleFactor(0.8) | ||
} | ||
|
||
private var backendDetails: some View { | ||
Group { | ||
if showFullDetails { | ||
fullDetails | ||
.transition(.asymmetric(insertion: .opacity, removal: .opacity)) | ||
} else { | ||
shortDetails | ||
.transition(.asymmetric(insertion: .opacity, removal: .opacity)) | ||
} | ||
} | ||
.animation(.default, value: showFullDetails) | ||
} | ||
|
||
private var contentHeight: CGFloat { | ||
UIScreen.main.bounds.height * 0.4 | ||
} | ||
|
||
private var fullDetails: some View { | ||
ScrollView { | ||
VStack(spacing: 16) { | ||
Text(Strings.message) | ||
.foregroundStyle(Color.primaryText) | ||
.multilineTextAlignment(.center) | ||
.lineLimit(nil) | ||
.fixedSize(horizontal: false, vertical: true) | ||
|
||
ForEach(viewModel.items, id: \.title) { model in | ||
itemView( | ||
title: model.title, | ||
value: model.value, | ||
isURL: model.isURL | ||
) | ||
} | ||
} | ||
} | ||
.frame(maxHeight: contentHeight) | ||
} | ||
|
||
private var shortDetails: some View { | ||
ScrollView { | ||
VStack(spacing: 16) { | ||
Text(Strings.message) | ||
.foregroundStyle(Color.primaryText) | ||
.multilineTextAlignment(.center) | ||
.lineLimit(nil) | ||
.fixedSize(horizontal: false, vertical: true) | ||
ForEach(viewModel.items.prefix(2), id: \.title) { model in | ||
itemView( | ||
title: model.title, | ||
value: model.value, | ||
isURL: model.isURL | ||
) | ||
} | ||
Button { | ||
withAnimation { | ||
showFullDetails.toggle() | ||
} | ||
} label: { | ||
Text(Strings.showDetails) | ||
.font(.textStyle(.body1)) | ||
} | ||
.wireButtonStyle(.link) | ||
} | ||
} | ||
.frame(maxHeight: contentHeight) | ||
} | ||
|
||
private func itemView( | ||
title: String, | ||
value: String, | ||
isURL: Bool = false | ||
) -> some View { | ||
VStack { | ||
Text(title) | ||
.foregroundStyle(Color.secondaryText) | ||
.lineLimit(nil) | ||
.fixedSize(horizontal: false, vertical: true) | ||
Text(value) | ||
.foregroundStyle(Color.primaryText) | ||
.accessibilityTextContentType(isURL ? .fileSystem : .plain) | ||
} | ||
} | ||
|
||
private var buttons: some View { | ||
VStack(spacing: 6) { | ||
cancelButton | ||
proceedButton | ||
} | ||
} | ||
|
||
private var cancelButton: some View { | ||
Button { | ||
viewModel.handleEvent(.didCancel) | ||
dismiss() | ||
} label: { | ||
Text(Strings.cancel) | ||
.font(.textStyle(.buttonBig)) | ||
} | ||
.wireButtonStyle(.secondary) | ||
} | ||
|
||
private var proceedButton: some View { | ||
Button { | ||
viewModel.handleEvent(.didConfirm) | ||
dismiss() | ||
} label: { | ||
Text(Strings.proceed) | ||
.font(.textStyle(.buttonBig)) | ||
} | ||
.wireButtonStyle(.primary) | ||
} | ||
|
||
} | ||
|
||
// MARK: - Previews | ||
|
||
#Preview("Regular fonts") { | ||
BackgroundView() | ||
.overlay( | ||
ZStack { | ||
SwitchBackendConfirmationViewPreview() | ||
.padding() | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
) | ||
} | ||
|
||
#Preview("Large fonts") { | ||
BackgroundView() | ||
.overlay( | ||
ZStack { | ||
SwitchBackendConfirmationViewPreview() | ||
.padding() | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
.environment(\.sizeCategory, .accessibilityExtraExtraExtraLarge) | ||
) | ||
} |
Oops, something went wrong.