generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,361 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
ElementX/Resources/Assets.xcassets/Images/Authentication/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,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ssets.xcassets/Images/Authentication/authentication_sso_icon_apple.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_sso_apple.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...hentication/authentication_sso_icon_apple.imageset/authentication_sso_apple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
...ts.xcassets/Images/Authentication/authentication_sso_icon_facebook.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_sso_facebook.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ation/authentication_sso_icon_facebook.imageset/authentication_sso_facebook.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
...sets.xcassets/Images/Authentication/authentication_sso_icon_github.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_sso_github.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ntication/authentication_sso_icon_github.imageset/authentication_sso_github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
...sets.xcassets/Images/Authentication/authentication_sso_icon_gitlab.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_sso_gitlab.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ntication/authentication_sso_icon_gitlab.imageset/authentication_sso_gitlab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
...sets.xcassets/Images/Authentication/authentication_sso_icon_google.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_sso_google.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ntication/authentication_sso_icon_google.imageset/authentication_sso_google.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions
15
...ets.xcassets/Images/Authentication/authentication_sso_icon_twitter.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_sso_twitter.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"preserves-vector-representation" : true | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ication/authentication_sso_icon_twitter.imageset/authentication_sso_twitter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
87 changes: 87 additions & 0 deletions
87
ElementX/Sources/Other/SwiftUI/ErrorHandling/AlertInfo.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,87 @@ | ||
// | ||
// 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 | ||
|
||
/// A type that describes an alert to be shown to the user. | ||
/// | ||
/// The alert info can be added to the view state bindings and used as an alert's `item`: | ||
/// ``` | ||
/// MyView | ||
/// .alert(item: $viewModel.alertInfo) { $0.alert } | ||
/// ``` | ||
struct AlertInfo<T: Hashable>: Identifiable { | ||
/// An identifier that can be used to distinguish one error from another. | ||
let id: T | ||
/// The alert's title. | ||
let title: String | ||
/// The alert's message (optional). | ||
var message: String? = nil | ||
/// The alert's primary button title and action. Defaults to an Ok button with no action. | ||
var primaryButton: (title: String, action: (() -> Void)?) = (VectorL10n.ok, nil) | ||
/// The alert's secondary button title and action. | ||
var secondaryButton: (title: String, action: (() -> Void)?)? = nil | ||
} | ||
|
||
extension AlertInfo { | ||
/// Initialises the type with the title and message from an `NSError` along with the default Ok button. | ||
init?(error: NSError? = nil) where T == Int { | ||
self.init(id: error?.code ?? -1, error: error) | ||
} | ||
|
||
/// Initialises the type with the title and message from an `NSError` along with the default Ok button. | ||
/// - Parameters: | ||
/// - id: An ID that identifies the error. | ||
/// - error: The Error that occurred. | ||
init?(id: T, error: NSError? = nil) { | ||
guard error?.domain != NSURLErrorDomain && error?.code != NSURLErrorCancelled else { return nil } | ||
|
||
self.id = id | ||
title = error?.userInfo[NSLocalizedFailureReasonErrorKey] as? String ?? VectorL10n.error | ||
message = error?.userInfo[NSLocalizedDescriptionKey] as? String ?? VectorL10n.errorCommonMessage | ||
} | ||
} | ||
|
||
@available(iOS 13.0, *) | ||
extension AlertInfo { | ||
private var messageText: Text? { | ||
guard let message = message else { return nil } | ||
return Text(message) | ||
} | ||
|
||
/// Returns a SwiftUI `Alert` created from this alert info, using default button | ||
/// styles for both primary and (if set) secondary buttons. | ||
var alert: Alert { | ||
if let secondaryButton = secondaryButton { | ||
return Alert(title: Text(title), | ||
message: messageText, | ||
primaryButton: alertButton(for: primaryButton), | ||
secondaryButton: alertButton(for: secondaryButton)) | ||
} else { | ||
return Alert(title: Text(title), | ||
message: messageText, | ||
dismissButton: alertButton(for: primaryButton)) | ||
} | ||
} | ||
|
||
private func alertButton(for buttonParameters: (title: String, action: (() -> Void)?)) -> Alert.Button { | ||
guard let action = buttonParameters.action else { | ||
return .default(Text(buttonParameters.title)) | ||
} | ||
|
||
return .default(Text(buttonParameters.title), action: action) | ||
} | ||
} |
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
ElementX/Sources/Other/SwiftUI/Layout/ReadableFrameModifier.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,37 @@ | ||
// | ||
// 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 | ||
|
||
/// Positions this view within an invisible frame that fills the width of its parent view, | ||
/// whilst limiting the width of the content to a readable size (which is customizable). | ||
fileprivate struct ReadableFrameModifier: ViewModifier { | ||
var maxWidth: CGFloat | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.frame(maxWidth: maxWidth) | ||
.frame(maxWidth: .infinity) | ||
} | ||
} | ||
|
||
extension View { | ||
/// Positions this view within an invisible frame that fills the width of its parent view, | ||
/// whilst limiting the width of the content to a readable size (which is customizable). | ||
func readableFrame(maxWidth: CGFloat = 600) -> some View { | ||
modifier(ReadableFrameModifier(maxWidth: maxWidth)) | ||
} | ||
} |
File renamed without changes.
78 changes: 78 additions & 0 deletions
78
ElementX/Sources/Screens/Authentication/AuthenticationHomeserverViewData.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,78 @@ | ||
// | ||
// 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 Foundation | ||
|
||
/// Information about a homeserver that is ready for display in the authentication flow. | ||
struct AuthenticationHomeserverViewData: Equatable { | ||
/// The homeserver string to be shown to the user. | ||
let address: String | ||
/// Whether or not the homeserver is matrix.org. | ||
let isMatrixDotOrg: Bool | ||
/// Whether or not to display the username and password text fields during login. | ||
let showLoginForm: Bool | ||
/// Whether or not to display the username and password text fields during registration. | ||
let showRegistrationForm: Bool | ||
/// The supported SSO login options. | ||
let ssoIdentityProviders: [SSOIdentityProvider] | ||
} | ||
|
||
// MARK: - Mocks | ||
|
||
extension AuthenticationHomeserverViewData { | ||
/// A mock homeserver that is configured just like matrix.org. | ||
static var mockMatrixDotOrg: AuthenticationHomeserverViewData { | ||
AuthenticationHomeserverViewData(address: "matrix.org", | ||
isMatrixDotOrg: true, | ||
showLoginForm: true, | ||
showRegistrationForm: true, | ||
ssoIdentityProviders: [ | ||
SSOIdentityProvider(id: "1", name: "Apple", brand: "apple", iconURL: nil), | ||
SSOIdentityProvider(id: "2", name: "Facebook", brand: "facebook", iconURL: nil), | ||
SSOIdentityProvider(id: "3", name: "GitHub", brand: "github", iconURL: nil), | ||
SSOIdentityProvider(id: "4", name: "GitLab", brand: "gitlab", iconURL: nil), | ||
SSOIdentityProvider(id: "5", name: "Google", brand: "google", iconURL: nil) | ||
]) | ||
} | ||
|
||
/// A mock homeserver that supports login and registration via a password but has no SSO providers. | ||
static var mockBasicServer: AuthenticationHomeserverViewData { | ||
AuthenticationHomeserverViewData(address: "example.com", | ||
isMatrixDotOrg: false, | ||
showLoginForm: true, | ||
showRegistrationForm: true, | ||
ssoIdentityProviders: []) | ||
} | ||
|
||
/// A mock homeserver that supports only supports authentication via a single SSO provider. | ||
static var mockEnterpriseSSO: AuthenticationHomeserverViewData { | ||
AuthenticationHomeserverViewData(address: "company.com", | ||
isMatrixDotOrg: false, | ||
showLoginForm: false, | ||
showRegistrationForm: false, | ||
ssoIdentityProviders: [SSOIdentityProvider(id: "test", name: "SAML", brand: nil, iconURL: nil)]) | ||
} | ||
|
||
/// A mock homeserver that supports only supports authentication via fallback. | ||
static var mockFallback: AuthenticationHomeserverViewData { | ||
AuthenticationHomeserverViewData(address: "company.com", | ||
isMatrixDotOrg: false, | ||
showLoginForm: false, | ||
showRegistrationForm: false, | ||
ssoIdentityProviders: []) | ||
} | ||
|
||
} |
Oops, something went wrong.