-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show transition on account switch (#1086)
- Loading branch information
Showing
17 changed files
with
249 additions
and
73 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// AppState+Transition.swift | ||
// Mlem | ||
// | ||
// Created by Sjmarf on 05/06/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension AppState { | ||
func transition(_ account: any Account) { | ||
Task { @MainActor in | ||
let transition = TransitionView(account: account) | ||
guard let transitionView = UIHostingController(rootView: transition).view, | ||
let window = UIApplication.shared.firstKeyWindow else { | ||
return | ||
} | ||
|
||
transitionView.alpha = 0 | ||
window.addSubview(transitionView) | ||
UIView.animate(withDuration: 0.15) { | ||
transitionView.alpha = 1 | ||
} | ||
|
||
transitionView.translatesAutoresizingMaskIntoConstraints = false | ||
transitionView.heightAnchor.constraint(equalTo: window.heightAnchor).isActive = true | ||
transitionView.widthAnchor.constraint(equalTo: window.widthAnchor).isActive = true | ||
|
||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) { | ||
UIView.animate(withDuration: 0.3) { | ||
transitionView.alpha = 0 | ||
} completion: { _ in | ||
transitionView.removeFromSuperview() | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// AccountTransitionView.swift | ||
// Mlem | ||
// | ||
// Created by Eric Andrews on 2023-10-02. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct TransitionView: View { | ||
let account: any Account | ||
@State var accountNameOpacity: CGFloat = .zero | ||
|
||
var body: some View { | ||
VStack(spacing: 24) { | ||
Text(account is UserAccount ? "Welcome" : "Welcome to") | ||
.onAppear { | ||
withAnimation(.easeIn(duration: 0.5)) { | ||
accountNameOpacity = 1.0 | ||
} | ||
} | ||
Text(account.nickname) | ||
.opacity(accountNameOpacity) | ||
} | ||
.font(.largeTitle) | ||
.bold() | ||
.frame(maxWidth: .infinity, maxHeight: .infinity) | ||
} | ||
} |
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
Oops, something went wrong.