-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from payan-app/scaffold
feat: add scaffold, error view and new buttons design
- Loading branch information
Showing
16 changed files
with
316 additions
and
45 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
32 changes: 32 additions & 0 deletions
32
PuraceDemo/PuraceDemo/Examples/Pages/ScaffoldExample.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,32 @@ | ||
// | ||
// ScaffoldExample.swift | ||
// PuraceDemo | ||
// | ||
// Created by Juan Hurtado on 7/08/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
import Purace | ||
|
||
struct ScaffoldExample: View { | ||
@State var showError = false | ||
@Environment(\.presentationMode) var presentationMode | ||
|
||
var body: some View { | ||
PuraceScaffold(navBar: .init(title: "This is an example", backOnTap: { | ||
presentationMode.wrappedValue.dismiss() | ||
})) { | ||
PuraceScaffoldContent { | ||
VStack { | ||
PuraceButtonView("Toggle error") { | ||
showError.toggle() | ||
} | ||
} | ||
}.genericErrorView(isPresented: $showError) { | ||
print("error retry callback has been called") | ||
} | ||
} | ||
.navigationBarHidden(true) | ||
} | ||
} |
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,67 @@ | ||
// | ||
// PuraceErrorView.swift | ||
// | ||
// | ||
// Created by Juan Hurtado on 15/12/22. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PuraceErrorView: View { | ||
var onRetryTap: (() -> Void)? | ||
|
||
var body: some View { | ||
GeometryReader { _ in | ||
VStack(alignment: .center) { | ||
Spacer(minLength: 0) | ||
Image("error", bundle: .module) | ||
VStack(spacing: 17) { | ||
PuraceTextView("Ups", fontSize: 22, weight: .medium) | ||
PuraceTextView("Parece que ha ocurrido un error. No te preocupes, es nuestra culpa.", fontSize: 14, textColor: PuraceStyle.Color.N2) | ||
.multilineTextAlignment(.center) | ||
HStack(spacing: 3) { | ||
PuraceTextView("Código:", textColor: PuraceStyle.Color.N4) | ||
PuraceTextView("12", weight: .medium) | ||
} | ||
.padding(.horizontal, 20) | ||
.padding(.vertical, 4) | ||
.background(Color.white) | ||
.cornerRadius(20) | ||
} | ||
Spacer(minLength: 0) | ||
if let onRetryTap { | ||
PuraceButtonView("Reintentar") { | ||
onRetryTap() | ||
} | ||
} | ||
Spacer(minLength: 0) | ||
} | ||
.padding(.horizontal, 50) | ||
}.background(PuraceStyle.Color.F1) | ||
} | ||
} | ||
|
||
// MARK: - View modifier | ||
struct PuraceErrorViewModifier: ViewModifier { | ||
@Binding var isPresented: Bool | ||
var retryCallback: (() -> Void)? | ||
|
||
func body(content: Content) -> some View { | ||
Group { | ||
if isPresented { | ||
PuraceErrorView(onRetryTap: retryCallback) | ||
} else { | ||
content | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
// MARK: - Scaffold extension | ||
public extension PuraceScaffoldContent { | ||
func genericErrorView(isPresented: Binding<Bool>, retryCallback: (() -> Void)? = nil) -> some View { | ||
let errorModifier = PuraceErrorViewModifier(isPresented: isPresented, retryCallback: retryCallback) | ||
return modifier(errorModifier) | ||
} | ||
} |
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,41 @@ | ||
// | ||
// PuraceScaffold.swift | ||
// | ||
// | ||
// Created by Juan Hurtado on 7/08/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public struct PuraceScaffold<Content: View>: View { | ||
var navBar: PuraceScaffoldNavBar? | ||
var content: () -> Content | ||
|
||
public init(navBar: PuraceScaffoldNavBar? = nil, content: @escaping () -> Content) { | ||
self.navBar = navBar | ||
self.content = content | ||
} | ||
|
||
public var body: some View { | ||
VStack(spacing: 0) { | ||
if let navBar { | ||
navBar | ||
} | ||
content() | ||
Spacer(minLength: 0) | ||
} | ||
} | ||
} | ||
|
||
public struct PuraceScaffoldContent<Content: View>: View { | ||
public var content: () -> Content | ||
|
||
public init(content: @escaping () -> Content) { | ||
self.content = content | ||
} | ||
|
||
public var body: some View { | ||
content() | ||
} | ||
} |
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,51 @@ | ||
// | ||
// PuraceScaffoldNavBar.swift | ||
// | ||
// | ||
// Created by Juan Hurtado on 7/08/22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public struct PuraceScaffoldNavBar: View { | ||
var title: String | ||
var backOnTap: () -> Void | ||
|
||
public init(title: String, backOnTap: @escaping () -> Void) { | ||
self.title = title | ||
self.backOnTap = backOnTap | ||
} | ||
|
||
public var body: some View { | ||
GeometryReader { _ in | ||
VStack(alignment: .center) { | ||
Spacer(minLength: 0) | ||
HStack(alignment: .center) { | ||
Button { | ||
backOnTap() | ||
} label: { | ||
Image("arrow_left", bundle: .module) | ||
.foregroundColor(PuraceStyle.Color.N1) | ||
}.frame(width: 20) | ||
.buttonStyle(.plain) | ||
|
||
Spacer(minLength: 0) | ||
|
||
PuraceTextView(title, fontSize: 14, weight: .medium) | ||
.multilineTextAlignment(.center) | ||
|
||
Spacer(minLength: 0) | ||
|
||
Color.white | ||
.frame(width: 20, height: 20) | ||
.background(Color.white) | ||
} | ||
Spacer(minLength: 0) | ||
} | ||
} | ||
.frame(height: 50) | ||
.padding(.horizontal, 16) | ||
.background(Color.white) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Sources/Purace/Resources/Media.xcassets/arrow_left.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "arrow_left.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Sources/Purace/Resources/Media.xcassets/arrow_left.imageset/arrow_left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
Sources/Purace/Resources/Media.xcassets/error.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "error.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Sources/Purace/Resources/Media.xcassets/error.imageset/error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
// | ||
// PuraceButtonSize.swift | ||
// | ||
// | ||
// Created by Juan Hurtado on 15/12/22. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum PuraceButtonSize: Int { | ||
case small = 12 | ||
case medium = 14 | ||
case large = 16 | ||
} |
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.