diff --git a/SwiftUIPlayground.xcodeproj/project.xcworkspace/xcuserdata/tahatesser.xcuserdatad/UserInterfaceState.xcuserstate b/SwiftUIPlayground.xcodeproj/project.xcworkspace/xcuserdata/tahatesser.xcuserdatad/UserInterfaceState.xcuserstate index 6b33119..e61bd98 100644 Binary files a/SwiftUIPlayground.xcodeproj/project.xcworkspace/xcuserdata/tahatesser.xcuserdatad/UserInterfaceState.xcuserstate and b/SwiftUIPlayground.xcodeproj/project.xcworkspace/xcuserdata/tahatesser.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SwiftUIPlayground/Samples.swift b/SwiftUIPlayground/Samples.swift index 6174ff3..a6ebc82 100644 --- a/SwiftUIPlayground/Samples.swift +++ b/SwiftUIPlayground/Samples.swift @@ -168,4 +168,10 @@ public let samples: [String: AnyView] = [ "ViewModifier Protocol": AnyView(ViewModifierProtocolSample()), ] )), + "Shapes": AnyView(SamplesList( + title: "Shapes", samples: + [ + "Progress Indicator Arc": AnyView(ProgressIndicatorArcSample()), + ] + )), ] diff --git a/SwiftUIPlayground/Samples/Animations/MatchedGeometryEffectSample.swift b/SwiftUIPlayground/Samples/Animations/MatchedGeometryEffectSample.swift index dc35a10..407b583 100644 --- a/SwiftUIPlayground/Samples/Animations/MatchedGeometryEffectSample.swift +++ b/SwiftUIPlayground/Samples/Animations/MatchedGeometryEffectSample.swift @@ -10,7 +10,7 @@ import SwiftUI struct MatchedGeometryEffectSample: View { @Namespace private var animation @State private var isExpanded: Bool = false - + var body: some View { ZStack { if isExpanded { @@ -24,7 +24,6 @@ struct MatchedGeometryEffectSample: View { .scaledToFit() .padding() .matchedGeometryEffect(id: "park", in: animation) - } } else { ZStack { @@ -47,7 +46,8 @@ struct MatchedGeometryEffectSample: View { isExpanded.toggle() } } - .ignoresSafeArea() } + .ignoresSafeArea() + } } #Preview { diff --git a/SwiftUIPlayground/Samples/CustomLayout/LayoutProtocolSample.swift b/SwiftUIPlayground/Samples/CustomLayout/LayoutProtocolSample.swift index da64bef..a98a6bc 100644 --- a/SwiftUIPlayground/Samples/CustomLayout/LayoutProtocolSample.swift +++ b/SwiftUIPlayground/Samples/CustomLayout/LayoutProtocolSample.swift @@ -28,46 +28,44 @@ struct LayoutProtocolSample: View { } struct BackslashStack: Layout { - - func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { - + func sizeThatFits(proposal _: ProposedViewSize, subviews: Subviews, cache _: inout ()) -> CGSize { let subviewSizes = subviews.map { proxy in - return proxy.sizeThatFits(.unspecified) + proxy.sizeThatFits(.unspecified) } - + let combinedSize = subviewSizes.reduce(.zero) { currentSize, subviewSize in - - return CGSize( - width: currentSize.width + subviewSize.width, height: currentSize.height + subviewSize.height) + + CGSize( + width: currentSize.width + subviewSize.width, height: currentSize.height + subviewSize.height + ) } - + return combinedSize } - - func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { - - + + func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache _: inout ()) { let subviewSizes = subviews.map { proxy in - return proxy.sizeThatFits(.unspecified) + proxy.sizeThatFits(.unspecified) } - + var x = bounds.minX var y = bounds.minY - + for index in subviews.indices { let subviewSize = subviewSizes[index] let sizeProposal = ProposedViewSize( width: subviewSize.width, - height: subviewSize.height) - + height: subviewSize.height + ) + subviews[index] .place( at: CGPoint(x: x, y: y), - proposal: sizeProposal) - + proposal: sizeProposal + ) + x += subviewSize.width y += subviewSize.height } } - } diff --git a/SwiftUIPlayground/Samples/LayoutAdjustments/AlignmentGuideSample.swift b/SwiftUIPlayground/Samples/LayoutAdjustments/AlignmentGuideSample.swift index 8301e0b..b29b3a3 100644 --- a/SwiftUIPlayground/Samples/LayoutAdjustments/AlignmentGuideSample.swift +++ b/SwiftUIPlayground/Samples/LayoutAdjustments/AlignmentGuideSample.swift @@ -8,7 +8,6 @@ import SwiftUI struct AlignmentGuideSample: View { - var body: some View { VStack(alignment: .leading) { RoundedRectangle(cornerRadius: 20) @@ -33,9 +32,7 @@ struct AlignmentGuideSample: View { .fill(Color.green) .frame(width: 50, height: 50) } - } - } #Preview { diff --git a/SwiftUIPlayground/Samples/LayoutFundamentals/ViewThatFitsSample.swift b/SwiftUIPlayground/Samples/LayoutFundamentals/ViewThatFitsSample.swift index c3fe8c7..59cd31e 100644 --- a/SwiftUIPlayground/Samples/LayoutFundamentals/ViewThatFitsSample.swift +++ b/SwiftUIPlayground/Samples/LayoutFundamentals/ViewThatFitsSample.swift @@ -38,6 +38,5 @@ struct UploadProgressView: View { .frame(width: 100) Text("\(uploadProgress.formatted(.percent))") } - } } diff --git a/SwiftUIPlayground/Samples/Shapes/ProgressIndicatorArcSample.swift b/SwiftUIPlayground/Samples/Shapes/ProgressIndicatorArcSample.swift new file mode 100644 index 0000000..210d512 --- /dev/null +++ b/SwiftUIPlayground/Samples/Shapes/ProgressIndicatorArcSample.swift @@ -0,0 +1,56 @@ +// +// ProgressIndicatorArcSample.swift +// SwiftUIPlayground +// +// Created by Taha Tesser on 11/5/24. +// + +import SwiftUI + +struct ProgressIndicatorArcSample: View { + let sunYellow = Color(UIColor(red: 1.0, green: 0.85, blue: 0.2, alpha: 1.0)) // RGB: (255, 217, 51) + let sunOrange = Color(UIColor(red: 1.0, green: 0.64, blue: 0.0, alpha: 1.0)) // RGB: (255, 165, 0) + var body: some View { + ZStack { + _ProgressView( + startAngle: .degrees(-90), + endAngle: .degrees(90), + clockwise: true + ) + .fill(sunOrange) + + _ProgressView( + startAngle: .degrees(-90), + endAngle: .degrees(90), + clockwise: false + ) + .fill(sunYellow) + } + + .padding() + } +} + +struct _ProgressView: Shape { + var startAngle: Angle + var endAngle: Angle + var clockwise: Bool + + func path(in rect: CGRect) -> Path { + var path = Path() + + path.addArc( + center: CGPoint(x: rect.midX, y: rect.midY), + radius: rect.width / 2, + startAngle: startAngle, + endAngle: endAngle, + clockwise: clockwise + ) + + return path + } +} + +#Preview { + ProgressIndicatorArcSample() +} diff --git a/SwiftUIPlayground/Samples/ViewFundamentals/ViewModifierProtocolSample.swift b/SwiftUIPlayground/Samples/ViewFundamentals/ViewModifierProtocolSample.swift index 389c7ab..df96112 100644 --- a/SwiftUIPlayground/Samples/ViewFundamentals/ViewModifierProtocolSample.swift +++ b/SwiftUIPlayground/Samples/ViewFundamentals/ViewModifierProtocolSample.swift @@ -1,5 +1,5 @@ // -// ViewModifierProtocolSamp,e.swift +// ViewModifierProtocolSample.swift // SwiftUIPlayground // // Created by Taha Tesser on 10/14/24. @@ -10,18 +10,18 @@ import SwiftUI struct ViewModifierProtocolSample: View { @State var text: String = "Hello, World!" - var body: some View { TextField( "", text: $text, - prompt: Text("Placeholder")) + prompt: Text("Placeholder") + ) .clearButton( text: $text, onClearHandler: { print("Text wad cleared!") - - }) + } + ) // .modifier(ClearTextButtonViewModifier(text: $text, onClearHandler: { // print("Text wad cleared!") // })) @@ -34,29 +34,29 @@ struct ViewModifierProtocolSample: View { } extension View { - func clearButton( text: Binding, - onClearHandler: (() -> Void)?) -> some View { - modifier(ClearTextButtonViewModifier(text: text, onClearHandler: onClearHandler)) - } + onClearHandler: (() -> Void)? + ) -> some View { + modifier(ClearTextButtonViewModifier(text: text, onClearHandler: onClearHandler)) + } } private struct ClearTextButtonViewModifier: ViewModifier { @Binding var text: String - + let onClearHandler: (() -> Void)? - + func body(content: Content) -> some View { ZStack { content - + HStack { Spacer() - + Button { text.removeAll() - + onClearHandler?() } label: { Image(systemName: "xmark.circle.fill") @@ -69,4 +69,3 @@ private struct ClearTextButtonViewModifier: ViewModifier { } } } -