Skip to content

Commit

Permalink
Updated account transition (#685)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews authored Oct 4, 2023
1 parent 1d83d19 commit 78351b1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
4 changes: 4 additions & 0 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@
CD2053102AC878B50000AA38 /* UpdatedTimestampView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */; };
CD2053142ACBAF150000AA38 /* AvatarType.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053132ACBAF150000AA38 /* AvatarType.swift */; };
CD2053172ACBBB5A0000AA38 /* DefaultAvatarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053162ACBBB5A0000AA38 /* DefaultAvatarView.swift */; };
CD2053122ACB72190000AA38 /* AccountTransitionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2053112ACB72190000AA38 /* AccountTransitionView.swift */; };
CD2BD6782A79F55800ECFF89 /* ImageSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2BD6772A79F55800ECFF89 /* ImageSize.swift */; };
CD2E182B2A3B708500224F8A /* Settings Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD2E182A2A3B708500224F8A /* Settings Options.swift */; };
CD309C462A93FBD300988F95 /* Logo View.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD309C452A93FBD300988F95 /* Logo View.swift */; };
Expand Down Expand Up @@ -809,6 +810,7 @@
CD20530F2AC878B50000AA38 /* UpdatedTimestampView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdatedTimestampView.swift; sourceTree = "<group>"; };
CD2053132ACBAF150000AA38 /* AvatarType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarType.swift; sourceTree = "<group>"; };
CD2053162ACBBB5A0000AA38 /* DefaultAvatarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultAvatarView.swift; sourceTree = "<group>"; };
CD2053112ACB72190000AA38 /* AccountTransitionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountTransitionView.swift; sourceTree = "<group>"; };
CD2BD6772A79F55800ECFF89 /* ImageSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageSize.swift; sourceTree = "<group>"; };
CD2E182A2A3B708500224F8A /* Settings Options.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Settings Options.swift"; sourceTree = "<group>"; };
CD309C452A93FBD300988F95 /* Logo View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Logo View.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1169,6 +1171,7 @@
504ECBA92AB27C73006C0B96 /* LandingPage.swift */,
CDE3BA862A8C25B000B972E2 /* OnboardingView.swift */,
504ECBAB2AB27CB1006C0B96 /* OnboardingRoute.swift */,
CD2053112ACB72190000AA38 /* AccountTransitionView.swift */,
);
path = Onboarding;
sourceTree = "<group>";
Expand Down Expand Up @@ -2627,6 +2630,7 @@
63D24EDE2A169F2A005CCA81 /* Markdown View.swift in Sources */,
E453A1D02A81C2140004BB8A /* QuickLookPreviewController.swift in Sources */,
B104A6E02A59C19400B3E725 /* OperationQueue - Easy init.swift in Sources */,
CD2053122ACB72190000AA38 /* AccountTransitionView.swift in Sources */,
03B7AAF32ABEF85300068B23 /* UserModel.swift in Sources */,
CDC1C9432A7AC24600072E3D /* ReadCheck.swift in Sources */,
63F0C7A22A0519BA00A18C5D /* PostSortType.swift in Sources */,
Expand Down
34 changes: 34 additions & 0 deletions Mlem/Views/Onboarding/AccountTransitionView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// AccountTransitionView.swift
// Mlem
//
// Created by Eric Andrews on 2023-10-02.
//

import Foundation
import SwiftUI

struct TransitionView: View {
let accountName: String?
@State var accountNameOpacity: CGFloat = .zero

var body: some View {
VStack(spacing: 24) {
if let accountName {
Text("Welcome")
.onAppear {
withAnimation(.easeIn(duration: 0.5)) {
accountNameOpacity = 1.0
}
}
Text(accountName)
.opacity(accountNameOpacity)
} else {
Text("Goodbye!")
}
}
.font(.largeTitle)
.bold()
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
23 changes: 5 additions & 18 deletions Mlem/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,25 @@ struct Window: View {

private func setFlow(_ flow: AppFlow) {
transition(flow)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.flow = flow
}
}

/// This method changes the current application flow and places a _transition_ view across the active window while
/// - Parameter newFlow: The `AppFlow` that the application should transition into
private func transition(_ newFlow: AppFlow) {
struct TransitionView: View {
let text: String

var body: some View {
VStack(spacing: 24) {
ProgressView()
.controlSize(.large)
Text(text)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}

let transitionText: String
let transitionAccountName: String?
switch newFlow {
case .onboarding:
transitionText = "See you soon 👋"
transitionAccountName = nil
case let .account(account):
transitionText = "Welcome \(account.nickname) 🚀"
transitionAccountName = account.nickname
}

Task { @MainActor in

let transition = TransitionView(text: transitionText)
let transition = TransitionView(accountName: transitionAccountName)
guard let transitionView = UIHostingController(rootView: transition).view,
let window = UIApplication.shared.firstKeyWindow else {
return
Expand Down

0 comments on commit 78351b1

Please sign in to comment.