Skip to content

StarRating-Pau #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions SwiftUIBasics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
308440142B2D0A0C00291F2D /* CatsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 308440132B2D0A0C00291F2D /* CatsView.swift */; };
308440182B2DFEB400291F2D /* ButtonNavigation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 308440172B2DFEB400291F2D /* ButtonNavigation.swift */; };
30CA734E2B24AE460025B2EB /* SymbolsAnimations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30CA734D2B24AE460025B2EB /* SymbolsAnimations.swift */; };
557042892B24CB310048C81C /* ProfileListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 557042882B24CB310048C81C /* ProfileListView.swift */; };
5570428B2B24D2F90048C81C /* TabBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5570428A2B24D2F90048C81C /* TabBarView.swift */; };
Expand All @@ -25,6 +27,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
308440132B2D0A0C00291F2D /* CatsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CatsView.swift; sourceTree = "<group>"; };
308440172B2DFEB400291F2D /* ButtonNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonNavigation.swift; sourceTree = "<group>"; };
30CA734D2B24AE460025B2EB /* SymbolsAnimations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SymbolsAnimations.swift; sourceTree = "<group>"; };
557042882B24CB310048C81C /* ProfileListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileListView.swift; sourceTree = "<group>"; };
5570428A2B24D2F90048C81C /* TabBarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabBarView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -73,6 +77,8 @@
5570428C2B24D8050048C81C /* SignUpView.swift */,
5570428E2B24E50E0048C81C /* RatingView.swift */,
557042902B24E5220048C81C /* PlansView.swift */,
308440132B2D0A0C00291F2D /* CatsView.swift */,
308440172B2DFEB400291F2D /* ButtonNavigation.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -197,12 +203,14 @@
5570428B2B24D2F90048C81C /* TabBarView.swift in Sources */,
5598D3162B23DF6D00A6AFD3 /* ContentView.swift in Sources */,
5598D3262B2404FC00A6AFD3 /* ProfileCardVM.swift in Sources */,
308440182B2DFEB400291F2D /* ButtonNavigation.swift in Sources */,
5570428F2B24E50E0048C81C /* RatingView.swift in Sources */,
30CA734E2B24AE460025B2EB /* SymbolsAnimations.swift in Sources */,
5598D3142B23DF6D00A6AFD3 /* SwiftUIBasicsApp.swift in Sources */,
5598D3242B24049B00A6AFD3 /* ProfileCardView.swift in Sources */,
557042952B24F3100048C81C /* RequirementText.swift in Sources */,
557042932B24EFB00048C81C /* FormTextField.swift in Sources */,
308440142B2D0A0C00291F2D /* CatsView.swift in Sources */,
557042892B24CB310048C81C /* ProfileListView.swift in Sources */,
557042912B24E5220048C81C /* PlansView.swift in Sources */,
5570428D2B24D8050048C81C /* SignUpView.swift in Sources */,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "1E94BF2F-5C75-4BF5-ACF2-B4A66A488C79"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "4A216A60-7DB9-4B84-AFB3-532FD5D32B38"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SwiftUIBasics/Views/PlansView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "9"
endingLineNumber = "9"
landmarkName = "unknown"
landmarkType = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SwiftUIBasics.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
36 changes: 36 additions & 0 deletions SwiftUIBasics/Views/ButtonNavigation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// ButtonNavigation.swift
// SwiftUIBasics
//
// Created by Luis Ezcurdia on 16/12/23.
//

import SwiftUI

struct ButtonNavigation: View {
@State var isPresenting = false
var body: some View {
// NavigationView {
// NavigationLink {
// Color.indigo
// } label: {
// Button("Open", systemImage: "bolt") {
// print("hello")
// }.buttonStyle(.borderedProminent)
// }
// }
NavigationStack {
Button("Open", systemImage: "bolt") {
isPresenting = true
}
.buttonStyle(.borderedProminent)
.navigationDestination(isPresented: $isPresenting) {
Color.indigo
}
}
}
}

#Preview {
ButtonNavigation()
}
100 changes: 100 additions & 0 deletions SwiftUIBasics/Views/CatsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// CatsView.swift
// SwiftUIBasics
//
// Created by Luis Ezcurdia on 15/12/23.
//

import SwiftUI

// Hash map cache
private class ImageCache {
static private var cache: [URL: Image] = [:]

static subscript(url: URL) -> Image? {
get {
ImageCache.cache[url]
}
set {
ImageCache.cache[url] = newValue
}
}
}

struct CacheAsyncImage<Content>: View where Content: View {
private let url: URL
private let scale: CGFloat
private let transaction: Transaction
private let content: (AsyncImagePhase) -> Content

init(
url: URL,
scale: CGFloat = 1.0,
transaction: Transaction = Transaction(),
@ViewBuilder content: @escaping (AsyncImagePhase) -> Content
) {
self.url = url
self.scale = scale
self.transaction = transaction
self.content = content
}

var body: some View {
if let cached = ImageCache[url] {
content(.success(cached))
} else {
AsyncImage(
url: url,
scale: scale,
transaction: transaction
) { phase in
cacheAndRender(phase: phase)
}
}
}

func cacheAndRender(phase: AsyncImagePhase) -> some View {
if case .success(let image) = phase {
print("Storing into cache")
ImageCache[url] = image
}

return content(phase)
}
}

struct CatsView: View {
var body: some View {
List {
ForEach((1..<10)) { _ in
CacheAsyncImage(url: URL(string: "https://wallpapercave.com/wp/wp3516314.jpg")!) { phase in
switch phase {
case .empty:
ProgressView()
case .success(let image):
image
.resizable()
.scaledToFit()
case .failure(let error):
EmptyView()
@unknown default:
fatalError()
}
}
// AsyncImage(url: URL(string: "https://wallpapercave.com/wp/wp3516314.jpg")) { image in
// image
// .resizable()
// .scaledToFit()
// } placeholder: {
// ProgressView()
// }
// .frame(width: .infinity, height: 120)
}
}
.listStyle(.plain)
}
}

#Preview {
CatsView()
}
90 changes: 87 additions & 3 deletions SwiftUIBasics/Views/PlansView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,93 @@ import SwiftUI

struct PlansView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}

VStack {
VStack (alignment: .leading, spacing: 2) {
Text("Choose")
.font(.system(.largeTitle, design: .rounded))
.fontWeight(.black)
Text("Your Plan")
.font(.system(.largeTitle, design: .rounded))
.fontWeight(.black)
}

HStack {
ZStack {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(.purple)
.frame(height: 200)
VStack {
Text("Basic")
.bold()
.font(.system(.title, design: .rounded))
Text("$9")
.bold()
.font(.system(size: 40, weight: .heavy, design: .rounded))
Text("per month")
.font(.headline)
}
.foregroundColor(Color.white)
}

ZStack {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color(red: 240/255, green: 240/255, blue: 240/255))
.frame(height: 200)
VStack {
Text("Pro")
.bold()
.font(.system(.title, design: .rounded))
Text("$19")
.bold()
.font(.system(size: 40, weight: .heavy, design: .rounded))
Text("per month")
.font(.headline)
}
.foregroundColor(Color.black)

Text("Best for designer")
.font(.system(.caption, design: .rounded))
.fontWeight(.bold)
.foregroundColor(.white)
.padding(5)
.background(Color(red: 255/255, green: 183/255, blue: 37/255))
.offset(x: 0, y: 98)
}
}
.padding()

ZStack {
RoundedRectangle(cornerRadius: 10)
.foregroundColor(Color(red: 62/255, green: 63/255, blue: 70/255))
.frame(width: 360, height: 222)
VStack {
Image(systemName: "wand.and.rays")
.font(.largeTitle)
Text("Team")
.bold()
.font(.system(.title, design: .rounded))

Text("$299")
.bold()
.font(.system(size: 40, weight: .heavy, design: .rounded))
Text("per month")
.font(.headline)
}
.foregroundColor(Color.white)

Text("Perfect for teams with 20 members")
.font(.system(.caption, design: .rounded))
.fontWeight(.bold)
.foregroundColor(.white)
.padding(5)
.background(Color(red: 255/255, green: 183/255, blue: 37/255))
.offset(x: 0, y: 110)
}
}
}
}


#Preview {
PlansView()
Expand Down
4 changes: 2 additions & 2 deletions SwiftUIBasics/Views/ProfileListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct Profile: Codable, Identifiable {
struct ProfileCellView: View {
let profile: Profile
var body: some View {
HStack{
HStack {
Image(systemName: "person.crop.circle")
.resizable()
.aspectRatio(contentMode: .fill)
Expand All @@ -39,7 +39,7 @@ struct ProfileCellView: View {
struct ProfileListView: View {
let profiles: [Profile]
var body: some View {
NavigationView{
NavigationView {
List(profiles) { profile in
NavigationLink {
Text(profile.name)
Expand Down
34 changes: 23 additions & 11 deletions SwiftUIBasics/Views/RatingView.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
//
// RatingView.swift
// SwiftUIBasics
//
// Created by Diplomado on 09/12/23.
//

import SwiftUI
struct StarRatingView: View {
@State private var rating: Int = 0

struct RatingView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
VStack {
Text("Selected Rating: \(rating)")

HStack {
ForEach(1...5, id: \.self) { index in
Image(systemName: index <= self.rating ? "star.fill" : "star")
.resizable()
.frame(width: 40, height: 40)
.foregroundColor(.yellow)
.onTapGesture {
self.rating = index
}
}
}
}
.padding()
}
}

#Preview {
RatingView()
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
StarRatingView()
}
}

Loading