Skip to content

Commit

Permalink
#40: Self review for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Jun 14, 2022
1 parent f3ac347 commit f32e228
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 138 deletions.
184 changes: 88 additions & 96 deletions ElementX.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ElementX/Sources/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class AppCoordinator: AuthenticationCoordinatorDelegate, Coordinator {
}

func start() {
self.window.makeKeyAndVisible()
window.makeKeyAndVisible()
stateMachine.processEvent(userSessionStore.hasSessions ? .startWithExistingSession : .startWithAuthentication)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import SwiftUI

extension String {
/// Returns the string as an `AttributedString` with the specified character tinted in a different color.
/// - Parameters:
/// - character: The character to be tinted.
/// - color: The color to tint the character. Defaults to the accent color.
/// - Returns: An `AttributedString`.
func tinting(_ character: Character, color: Color = .accentColor) -> AttributedString {
var string = AttributedString(self)
let characterView = string.characters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AuthenticationCoordinator: Coordinator {
guard let self = self else { return }
switch action {
case .login:
self.startNewLoginFlow()
self.showLoginScreen()
case .register:
fatalError("Not implemented")
}
Expand All @@ -66,7 +66,7 @@ class AuthenticationCoordinator: Coordinator {
coordinator.start()
}

private func startNewLoginFlow() {
private func showLoginScreen() {
let parameters = LoginScreenCoordinatorParameters()
let coordinator = LoginScreenCoordinator(parameters: parameters)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,12 @@
import SwiftUI

/// Metrics used across the entire onboarding flow.
struct OnboardingMetrics {
struct AuthenticationMetrics {
static let maxContentWidth: CGFloat = 600
static let maxContentHeight: CGFloat = 750

/// The padding used between the top of the main content and the navigation bar.
static let topPaddingToNavigationBar: CGFloat = 16
/// The padding used between the footer and the bottom of the view.
static let actionButtonBottomPadding: CGFloat = 24
/// The width/height used for the main icon shown in most of the screens.
static let iconSize: CGFloat = 90

/// The padding used to the top of the view for breaker screens that don't have a navigation bar.
static let breakerScreenTopPadding: CGFloat = 80
static let breakerScreenIconBottomPadding: CGFloat = 42

/// The height to use for top/bottom spacers to pad the views to fit the `maxContentHeight`.
static func spacerHeight(in geometry: GeometryProxy) -> CGFloat {
max(0, (geometry.size.height - maxContentHeight) / 2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct SplashScreenViewState: BindableState, CustomDebugStringConvertible {
let locale = Locale.current
let page4Title = locale.identifier.hasPrefix("en") ? "Cut the slack from teams." : ElementL10n.ftueAuthCarouselWorkplaceTitle

self.content = [
content = [
SplashScreenPageContent(title: ElementL10n.ftueAuthCarouselSecureTitle.tinting("."),
message: ElementL10n.ftueAuthCarouselSecureBody,
image: Asset.Images.splashScreenPage1,
Expand All @@ -83,7 +83,7 @@ struct SplashScreenViewState: BindableState, CustomDebugStringConvertible {
image: Asset.Images.splashScreenPage4,
gradient: Gradient(colors: [Constants.gradientColors[3], Constants.gradientColors[4]]))
]
self.bindings = SplashScreenBindings()
bindings = SplashScreenBindings()
}
}

Expand Down
40 changes: 21 additions & 19 deletions ElementX/Sources/Screens/SplashScreen/View/SplashScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct SplashScreen: View {

buttons
.padding(.horizontal, 16)
.frame(maxWidth: OnboardingMetrics.maxContentWidth)
.frame(maxWidth: AuthenticationMetrics.maxContentWidth)
Spacer()
}
.background(ViewFrameReader(frame: $overlayFrame))
Expand All @@ -109,33 +109,20 @@ struct SplashScreen: View {

// MARK: - Animation

func nextPage() {
// Wrap back round to the first page index when reaching the end.
viewModel.pageIndex = (viewModel.pageIndex + 1) % viewModel.viewState.content.count
}
func previousPage() {
// Prevent the hidden page at index -1 from being shown.
viewModel.pageIndex = max(0, (viewModel.pageIndex - 1))
}
func hiddenPage() {
// Hidden page for a nicer animation when looping back to the start.
viewModel.pageIndex = -1
}

/// Starts the animation timer for an automatic carousel effect.
private func startTimer() {
guard pageTimer == nil else { return }

pageTimer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in
if viewModel.pageIndex == pageCount - 1 {
hiddenPage()
showHiddenPage()

withAnimation(.easeInOut(duration: 0.7)) {
nextPage()
showNextPage()
}
} else {
withAnimation(.easeInOut(duration: 0.7)) {
nextPage()
showNextPage()
}
}
}
Expand All @@ -149,6 +136,21 @@ struct SplashScreen: View {
pageTimer.invalidate()
}

private func showNextPage() {
// Wrap back round to the first page index when reaching the end.
viewModel.pageIndex = (viewModel.pageIndex + 1) % viewModel.viewState.content.count
}

private func showPreviousPage() {
// Prevent the hidden page at index -1 from being shown.
viewModel.pageIndex = max(0, (viewModel.pageIndex - 1))
}

private func showHiddenPage() {
// Hidden page for a nicer animation when looping back to the start.
viewModel.pageIndex = -1
}

// MARK: - Gestures

/// Whether or not a drag gesture is valid or not.
Expand Down Expand Up @@ -188,9 +190,9 @@ struct SplashScreen: View {

withAnimation(.easeInOut(duration: 0.2)) {
if drag.predictedEndTranslation.width < -viewSize.width / 2 {
nextPage()
showNextPage()
} else if drag.predictedEndTranslation.width > viewSize.width / 2 {
previousPage()
showPreviousPage()
}

dragOffset = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct SplashScreenPage: View {
Spacer().frame(maxHeight: overlayHeight)
}
.padding(.horizontal, 16)
.frame(maxWidth: OnboardingMetrics.maxContentWidth,
maxHeight: OnboardingMetrics.maxContentHeight)
.frame(maxWidth: AuthenticationMetrics.maxContentWidth,
maxHeight: AuthenticationMetrics.maxContentHeight)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(backgroundGradient.ignoresSafeArea())
Expand Down
4 changes: 2 additions & 2 deletions ElementX/Sources/Services/UserSession/UserSessionStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class UserSessionStore {
MXLog.error("Failed restoring login with error: \(error)")

// On any restoration failure reset the token and restart
self.keychainController.removeAllAccessTokens()
keychainController.removeAllAccessTokens()
deleteBaseDirectory(for: usernameTokenTuple.username)

return .failure(error)
Expand Down Expand Up @@ -107,7 +107,7 @@ class UserSessionStore {

let clientProxy = ClientProxy(client: client)

return .success((clientProxy))
return .success(clientProxy)
}

func baseDirectoryPath(for username: String) -> String {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
//

import XCTest
import Combine

@testable import ElementX

class SplashScreenViewModelTests: XCTestCase {

// Nothing to test, the view model has no mutable state.
}
1 change: 1 addition & 0 deletions changelog.d/40.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a UserSessionStore and the splash screen from Element iOS.

0 comments on commit f32e228

Please sign in to comment.