-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Program Screen Error Handling (#448)
- Loading branch information
1 parent
b2539a6
commit ea6e24e
Showing
11 changed files
with
321 additions
and
142 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
97 changes: 97 additions & 0 deletions
97
Core/Core/View/Base/FullScreenErrorView/FullScreenErrorView.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,97 @@ | ||
// | ||
// FullScreenErrorView.swift | ||
// Course | ||
// | ||
// Created by Shafqat Muneer on 5/14/24. | ||
// | ||
|
||
import SwiftUI | ||
import Theme | ||
|
||
public struct FullScreenErrorView: View { | ||
|
||
public enum ErrorType { | ||
case noInternet | ||
case noInternetWithReload | ||
case generic | ||
} | ||
|
||
private let errorType: ErrorType | ||
private var action: () -> Void = {} | ||
|
||
public init( | ||
type: ErrorType | ||
) { | ||
self.errorType = type | ||
} | ||
|
||
public init( | ||
type: ErrorType, | ||
action: @escaping () -> Void | ||
) { | ||
self.errorType = type | ||
self.action = action | ||
} | ||
|
||
public var body: some View { | ||
GeometryReader { proxy in | ||
VStack(spacing: 28) { | ||
Spacer() | ||
switch errorType { | ||
case .noInternet, .noInternetWithReload: | ||
CoreAssets.noWifi.swiftUIImage | ||
.renderingMode(.template) | ||
.foregroundStyle(Color.primary) | ||
.scaledToFit() | ||
|
||
Text(CoreLocalization.Error.Internet.noInternetTitle) | ||
.font(Theme.Fonts.titleLarge) | ||
.foregroundColor(Theme.Colors.textPrimary) | ||
|
||
Text(CoreLocalization.Error.Internet.noInternetDescription) | ||
.font(Theme.Fonts.bodyLarge) | ||
.foregroundColor(Theme.Colors.textPrimary) | ||
.multilineTextAlignment(.center) | ||
.padding(.horizontal, 50) | ||
case .generic: | ||
CoreAssets.notAvaliable.swiftUIImage | ||
.renderingMode(.template) | ||
.foregroundStyle(Color.primary) | ||
.scaledToFit() | ||
|
||
Text(CoreLocalization.View.Snackbar.tryAgainBtn) | ||
.font(Theme.Fonts.titleLarge) | ||
.foregroundColor(Theme.Colors.textPrimary) | ||
|
||
Text(CoreLocalization.Error.unknownError) | ||
.font(Theme.Fonts.bodyLarge) | ||
.foregroundColor(Theme.Colors.textPrimary) | ||
.multilineTextAlignment(.center) | ||
.padding(.horizontal, 50) | ||
} | ||
|
||
if errorType != .noInternet { | ||
UnitButtonView( | ||
type: .reload, | ||
action: { | ||
self.action() | ||
} | ||
) | ||
} | ||
Spacer() | ||
} | ||
.frame(maxWidth: .infinity, maxHeight: proxy.size.height) | ||
.background( | ||
Theme.Colors.background | ||
) | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct FullScreenErrorView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
FullScreenErrorView(type: .noInternetWithReload) | ||
} | ||
} | ||
#endif |
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
File renamed without changes.
File renamed without changes.
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.