generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#40: Add server selection screen from EI.
- Loading branch information
Showing
30 changed files
with
796 additions
and
13 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
...ources/Assets.xcassets/Images/Authentication/Server Selection Icon.imageset/Contents.json
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,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "authentication_server_selection_icon.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ication/Server Selection Icon.imageset/authentication_server_selection_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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
41 changes: 41 additions & 0 deletions
41
ElementX/Sources/Screens/Authentication/AuthenticationIconImage.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 @@ | ||
// | ||
// Copyright 2022 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
/// An image that is styled for use as the screen icon in the onboarding flow. | ||
struct AuthenticationIconImage: View { | ||
|
||
let image: ImageAsset | ||
|
||
var body: some View { | ||
Image(image.name) | ||
.resizable() | ||
.renderingMode(.template) | ||
.foregroundColor(.element.accent) | ||
.frame(width: 90, height: 90) | ||
.background(.white, in: Circle().inset(by: 2)) | ||
.accessibilityHidden(true) | ||
} | ||
} | ||
|
||
// MARK: - Previews | ||
|
||
struct AuthenticationIconImage_Previews: PreviewProvider { | ||
static var previews: some View { | ||
AuthenticationIconImage(image: Asset.Images.serverSelectionIcon) | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
ElementX/Sources/Screens/Authentication/ServerSelection/MockServerSelectionScreenState.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,47 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
enum MockServerSelectionScreenState: CaseIterable { | ||
case matrix | ||
case emptyAddress | ||
case invalidAddress | ||
case nonModal | ||
|
||
/// Generate the view struct for the screen state. | ||
var viewModel: ServerSelectionViewModel { | ||
// swiftlint:disable:next implicit_getter | ||
@MainActor get { | ||
switch self { | ||
case .matrix: | ||
return ServerSelectionViewModel(homeserverAddress: "https://matrix.org", | ||
hasModalPresentation: true) | ||
case .emptyAddress: | ||
return ServerSelectionViewModel(homeserverAddress: "", | ||
hasModalPresentation: true) | ||
case .invalidAddress: | ||
let viewModel = ServerSelectionViewModel(homeserverAddress: "thisisbad", | ||
hasModalPresentation: true) | ||
viewModel.displayError(.footerMessage(ElementL10n.unknownError)) | ||
return viewModel | ||
case .nonModal: | ||
return ServerSelectionViewModel(homeserverAddress: "https://matrix.org", | ||
hasModalPresentation: false) | ||
} | ||
} | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
ElementX/Sources/Screens/Authentication/ServerSelection/ServerSelectionCoordinator.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,110 @@ | ||
// | ||
// Copyright 2021 New Vector Ltd | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ServerSelectionCoordinatorParameters { | ||
/// The homeserver to be shown initially. | ||
let homeserver: LoginHomeserver | ||
/// Whether the screen is presented modally or within a navigation stack. | ||
let hasModalPresentation: Bool | ||
} | ||
|
||
enum ServerSelectionCoordinatorResult { | ||
case selected(LoginHomeserver) | ||
case dismiss | ||
} | ||
|
||
final class ServerSelectionCoordinator: Coordinator, Presentable { | ||
|
||
// MARK: - Properties | ||
|
||
// MARK: Private | ||
|
||
private let parameters: ServerSelectionCoordinatorParameters | ||
private let serverSelectionHostingController: UIViewController | ||
private var serverSelectionViewModel: ServerSelectionViewModelProtocol | ||
|
||
private var indicatorPresenter: UserIndicatorTypePresenterProtocol | ||
private var loadingIndicator: UserIndicator? | ||
|
||
// MARK: Public | ||
|
||
// Must be used only internally | ||
var childCoordinators: [Coordinator] = [] | ||
var callback: (@MainActor (ServerSelectionCoordinatorResult) -> Void)? | ||
|
||
// MARK: - Setup | ||
|
||
init(parameters: ServerSelectionCoordinatorParameters) { | ||
self.parameters = parameters | ||
|
||
let viewModel = ServerSelectionViewModel(homeserverAddress: parameters.homeserver.address, | ||
hasModalPresentation: parameters.hasModalPresentation) | ||
let view = ServerSelectionScreen(viewModel: viewModel.context) | ||
serverSelectionViewModel = viewModel | ||
serverSelectionHostingController = UIHostingController(rootView: view) | ||
|
||
indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: serverSelectionHostingController) | ||
} | ||
|
||
// MARK: - Public | ||
|
||
func start() { | ||
MXLog.debug("[ServerSelectionCoordinator] did start.") | ||
|
||
serverSelectionViewModel.callback = { [weak self] result in | ||
guard let self = self else { return } | ||
MXLog.debug("[ServerSelectionCoordinator] ServerSelectionViewModel did complete with result: \(result).") | ||
|
||
switch result { | ||
case .confirm(let homeserverAddress): | ||
self.useHomeserver(homeserverAddress) | ||
case .dismiss: | ||
self.callback?(.dismiss) | ||
} | ||
} | ||
} | ||
|
||
func toPresentable() -> UIViewController { | ||
return self.serverSelectionHostingController | ||
} | ||
|
||
// MARK: - Private | ||
|
||
/// Show an activity indicator whilst loading. | ||
/// - Parameters: | ||
/// - label: The label to show on the indicator. | ||
/// - isInteractionBlocking: Whether the indicator should block any user interaction. | ||
private func startLoading(label: String = ElementL10n.loading, isInteractionBlocking: Bool = true) { | ||
loadingIndicator = indicatorPresenter.present(.loading(label: label, isInteractionBlocking: isInteractionBlocking)) | ||
} | ||
|
||
/// Hide the currently displayed activity indicator. | ||
private func stopLoading() { | ||
loadingIndicator = nil | ||
} | ||
|
||
/// Updates the login flow using the supplied homeserver address, or shows an error when this isn't possible. | ||
private func useHomeserver(_ homeserverAddress: String) { | ||
startLoading() | ||
|
||
let homeserverAddress = LoginHomeserver.sanitized(homeserverAddress) | ||
callback?(.selected(LoginHomeserver(address: homeserverAddress))) | ||
|
||
stopLoading() | ||
} | ||
} |
Oops, something went wrong.