Skip to content

Commit

Permalink
#40: Add login screen from EI.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jun 16, 2022
1 parent 8653f1d commit c0f5d7b
Show file tree
Hide file tree
Showing 40 changed files with 1,511 additions and 329 deletions.
156 changes: 92 additions & 64 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"untranslated" = "Untranslated";
"screenshot_detected_title" = "You took a screenshot";
"screenshot_detected_message" = "Would you like to submit a bug report?";

// MARK: - Authentication

"authentication_login_title" = "Welcome back!";
"authentication_login_forgot_password" = "Forgot password";

"authentication_server_info_title" = "Choose your server to store your data";
"authentication_server_info_matrix_description" = "Join millions for free on the largest public server";
6 changes: 6 additions & 0 deletions ElementX/Sources/Generated/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ internal typealias AssetImageTypeAlias = ImageAsset.Image
// swiftlint:disable identifier_name line_length nesting type_body_length type_name
internal enum Asset {
internal enum Images {
internal static let authenticationSsoIconApple = ImageAsset(name: "Images/authentication_sso_icon_apple")
internal static let authenticationSsoIconFacebook = ImageAsset(name: "Images/authentication_sso_icon_facebook")
internal static let authenticationSsoIconGithub = ImageAsset(name: "Images/authentication_sso_icon_github")
internal static let authenticationSsoIconGitlab = ImageAsset(name: "Images/authentication_sso_icon_gitlab")
internal static let authenticationSsoIconGoogle = ImageAsset(name: "Images/authentication_sso_icon_google")
internal static let authenticationSsoIconTwitter = ImageAsset(name: "Images/authentication_sso_icon_twitter")
internal static let splashScreenPage1 = ImageAsset(name: "Images/Splash Screen Page 1")
internal static let splashScreenPage2 = ImageAsset(name: "Images/Splash Screen Page 2")
internal static let splashScreenPage3 = ImageAsset(name: "Images/Splash Screen Page 3")
Expand Down
8 changes: 8 additions & 0 deletions ElementX/Sources/Generated/Strings+Untranslated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import Foundation
// swiftlint:disable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:disable nesting type_body_length type_name vertical_whitespace_opening_braces
extension ElementL10n {
/// Forgot password
public static let authenticationLoginForgotPassword = ElementL10n.tr("Untranslated", "authentication_login_forgot_password")
/// Welcome back!
public static let authenticationLoginTitle = ElementL10n.tr("Untranslated", "authentication_login_title")
/// Join millions for free on the largest public server
public static let authenticationServerInfoMatrixDescription = ElementL10n.tr("Untranslated", "authentication_server_info_matrix_description")
/// Choose your server to store your data
public static let authenticationServerInfoTitle = ElementL10n.tr("Untranslated", "authentication_server_info_title")
/// Would you like to submit a bug report?
public static let screenshotDetectedMessage = ElementL10n.tr("Untranslated", "screenshot_detected_message")
/// You took a screenshot
Expand Down
19 changes: 19 additions & 0 deletions ElementX/Sources/Other/Logging/MXLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ private var logger: SwiftyBeaver.Type = {
logger.error(message, file, function, line: line)
}

public static func failure(_ message: @autoclosure () -> Any, _
file: String = #file,
_ function: String = #function,
line: Int = #line,
context: Any? = nil) {
logger.error(message(), file, function, line: line, context: context)
#if DEBUG
assertionFailure("\(message())")
#endif
}

@available(swift, obsoleted: 5.4)
@objc public static func logFailure(_ message: String, file: String, function: String, line: Int) {
logger.error(message, file, function, line: line)
#if DEBUG
assertionFailure(message)
#endif
}

// MARK: - Private

fileprivate static func configureLogger(_ logger: SwiftyBeaver.Type, withConfiguration configuration: MXLogConfiguration) {
Expand Down
88 changes: 88 additions & 0 deletions ElementX/Sources/Other/SwiftUI/ErrorHandling/AlertInfo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//
// 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)?) = (ElementL10n.ok, nil)
/// The alert's secondary button title and action.
var secondaryButton: (title: String, action: (() -> Void)?)? = nil
}

#warning("Remove the NSError extensions?")
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 ?? ElementL10n.dialogTitleError
message = error?.userInfo[NSLocalizedDescriptionKey] as? String ?? ElementL10n.unknownError
}
}

@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)
}
}
37 changes: 37 additions & 0 deletions ElementX/Sources/Other/SwiftUI/Layout/ReadableFrameModifier.swift
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))
}
}
Loading

0 comments on commit c0f5d7b

Please sign in to comment.