Skip to content

Commit

Permalink
feat: add scaffold, error view and new buttons design
Browse files Browse the repository at this point in the history
  • Loading branch information
juandahurt committed Dec 16, 2022
1 parent 06e03a9 commit cfc3d38
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 45 deletions.
12 changes: 12 additions & 0 deletions PuraceDemo/PuraceDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
2F9321B7282EE49E003DA929 /* MenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F9321B6282EE49E003DA929 /* MenuView.swift */; };
2F9321BC282EE49E003DA929 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2F9321BB282EE49E003DA929 /* Assets.xcassets */; };
2F9321BF282EE49E003DA929 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2F9321BD282EE49E003DA929 /* LaunchScreen.storyboard */; };
2FA5850C28A01F7700A8393E /* ScaffoldExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA5850B28A01F7700A8393E /* ScaffoldExample.swift */; };
2FA986792837351B000DB409 /* GridExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA986782837351B000DB409 /* GridExample.swift */; };
2FA9867B28373DD3000DB409 /* SnackbarExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FA9867A28373DD3000DB409 /* SnackbarExample.swift */; };
2FC004092831AC250037EF10 /* StoryExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FC004082831AC250037EF10 /* StoryExample.swift */; };
Expand Down Expand Up @@ -52,6 +53,7 @@
2F9321BB282EE49E003DA929 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2F9321BE282EE49E003DA929 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2F9321C0282EE49E003DA929 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2FA5850B28A01F7700A8393E /* ScaffoldExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScaffoldExample.swift; sourceTree = "<group>"; };
2FA986782837351B000DB409 /* GridExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GridExample.swift; sourceTree = "<group>"; };
2FA9867A28373DD3000DB409 /* SnackbarExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnackbarExample.swift; sourceTree = "<group>"; };
2FC004082831AC250037EF10 /* StoryExample.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryExample.swift; sourceTree = "<group>"; };
Expand All @@ -74,6 +76,7 @@
2F1F7D6F28317DE200AA30DB /* Examples */ = {
isa = PBXGroup;
children = (
2FA5850A28A01F4800A8393E /* Pages */,
2F27BC9B284814A700B5AC8D /* Complex */,
2F27BC9A2848149900B5AC8D /* Basic */,
);
Expand Down Expand Up @@ -149,6 +152,14 @@
name = Frameworks;
sourceTree = "<group>";
};
2FA5850A28A01F4800A8393E /* Pages */ = {
isa = PBXGroup;
children = (
2FA5850B28A01F7700A8393E /* ScaffoldExample.swift */,
);
path = Pages;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -234,6 +245,7 @@
2F9321B3282EE49E003DA929 /* AppDelegate.swift in Sources */,
2F6267AE2857B6960063A630 /* AccordionExample.swift in Sources */,
2F569939285FB93500F2D4D3 /* ModalExample.swift in Sources */,
2FA5850C28A01F7700A8393E /* ScaffoldExample.swift in Sources */,
2F77A234283C4AC700F143FB /* ImageExample.swift in Sources */,
2F5EFD3C284D23E3005D130A /* HorizontalGridExample.swift in Sources */,
2FA9867B28373DD3000DB409 /* SnackbarExample.swift in Sources */,
Expand Down
28 changes: 14 additions & 14 deletions PuraceDemo/PuraceDemo/Examples/Basic/ButtonExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ struct ButtonExample: View {
VStack(spacing: 0) {
VStack {
Text("`PuraceButtonView('title', type: .loud)`")
PuraceButtonView("Font size: 12", fontSize: 12)
PuraceButtonView("Font size: 14", fontSize: 14)
PuraceButtonView("Font size: 16", fontSize: 16)
PuraceButtonView("small", size: .small)
PuraceButtonView("medium")
PuraceButtonView("large", size: .large)
.padding(.bottom)
}

VStack {
Text("`PuraceButtonView('title', type: .quiet)`")
PuraceButtonView("Font size: 12", fontSize: 12, type: .quiet)
PuraceButtonView("Font size: 14", fontSize: 14, type: .quiet)
PuraceButtonView("Font size: 16", fontSize: 16, type: .quiet)
PuraceButtonView("small", size: .small, type: .quiet)
PuraceButtonView("medium", type: .quiet)
PuraceButtonView("large", size: .large, type: .quiet)
.padding(.bottom)
}
VStack {
Text("`PuraceButtonView('title', type: .transparent)`")
PuraceButtonView("Font size: 12", fontSize: 12, type: .transparent)
PuraceButtonView("Font size: 14", fontSize: 14, type: .transparent)
PuraceButtonView("Font size: 16", fontSize: 16, type: .transparent)
Spacer()
}
//
// VStack {
// Text("`PuraceButtonView('title', type: .transparent)`")
// PuraceButtonView("Font size: 12", fontSize: 12, type: .transparent)
// PuraceButtonView("Font size: 14", fontSize: 14, type: .transparent)
// PuraceButtonView("Font size: 16", fontSize: 16, type: .transparent)
// Spacer()
// }
}
}
}
2 changes: 1 addition & 1 deletion PuraceDemo/PuraceDemo/Examples/Basic/SnackbarExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct SnackBarExample: View {
Spacer()
}

PuraceButtonView("Mostrar snackbar", fontSize: 14) {
PuraceButtonView("Mostrar snackbar") {
PuraceSnackbarBuilder()
.withTitle("Hubo un error")
.withType(getType())
Expand Down
32 changes: 32 additions & 0 deletions PuraceDemo/PuraceDemo/Examples/Pages/ScaffoldExample.swift
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)
}
}
5 changes: 5 additions & 0 deletions PuraceDemo/PuraceDemo/MenuView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ struct MenuView: View {
AdjustableHStackExample()
}
}
Section {
NavigationLink("Scaffold") {
ScaffoldExample()
}
}
}
.navigationTitle("Purace")
}
Expand Down
67 changes: 67 additions & 0 deletions Sources/Purace/Pages/Scaffold/PuraceErrorView.swift
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)
}
}
41 changes: 41 additions & 0 deletions Sources/Purace/Pages/Scaffold/PuraceScaffold.swift
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()
}
}
51 changes: 51 additions & 0 deletions Sources/Purace/Pages/Scaffold/PuraceScaffoldNavBar.swift
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)
}
}
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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.
14 changes: 14 additions & 0 deletions Sources/Purace/Views/Basic/Button/PuraceButtonSize.swift
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
}
3 changes: 1 addition & 2 deletions Sources/Purace/Views/Basic/Button/PuraceButtonType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ import Foundation
import SwiftUI

public enum PuraceButtonType {
case loud, quiet, transparent
case custom(Color, Color, Color) // 0: background, 1: on pressed, 2: text color
case loud, quiet
}
Loading

0 comments on commit cfc3d38

Please sign in to comment.