Skip to content
Merged
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
4 changes: 4 additions & 0 deletions Examples/Basic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
D961846D220FDD1200C59D9B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D961846C220FDD1200C59D9B /* Assets.xcassets */; };
D9618470220FDD1200C59D9B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D961846E220FDD1200C59D9B /* LaunchScreen.storyboard */; };
D9742E1E27D4877300E02FFD /* SwiftDraw in Frameworks */ = {isa = PBXBuildFile; productRef = D9742E1D27D4877300E02FFD /* SwiftDraw */; };
D9AC57BF2D65E86A005ACBFF /* GalleryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9AC57BE2D65E86A005ACBFF /* GalleryView.swift */; };
D9EE86AF2A4EC94E00C7CAE1 /* Samples.bundle in Resources */ = {isa = PBXBuildFile; fileRef = D94D5BE22A4EC906001DCD83 /* Samples.bundle */; };
/* End PBXBuildFile section */

Expand All @@ -37,6 +38,7 @@
D961846F220FDD1200C59D9B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
D9618471220FDD1200C59D9B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
D9742E1C27D4875100E02FFD /* SwiftDraw */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = SwiftDraw; path = ..; sourceTree = "<group>"; };
D9AC57BE2D65E86A005ACBFF /* GalleryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GalleryView.swift; sourceTree = "<group>"; };
D9ACD7A0220FDE04009717CF /* SwiftDraw.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftDraw.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -75,6 +77,7 @@
D9618464220FDD1100C59D9B /* Sources */ = {
isa = PBXGroup;
children = (
D9AC57BE2D65E86A005ACBFF /* GalleryView.swift */,
D9618465220FDD1100C59D9B /* AppDelegate.swift */,
D9618467220FDD1100C59D9B /* ViewController.swift */,
D961846C220FDD1200C59D9B /* Assets.xcassets */,
Expand Down Expand Up @@ -169,6 +172,7 @@
files = (
D9618468220FDD1100C59D9B /* ViewController.swift in Sources */,
D9618466220FDD1100C59D9B /* AppDelegate.swift in Sources */,
D9AC57BF2D65E86A005ACBFF /* GalleryView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion Examples/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
//

import UIKit
import SwiftUI

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -40,7 +41,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

let window = UIWindow()
window.rootViewController = UINavigationController(rootViewController: ViewController())
window.rootViewController = UINavigationController(rootViewController: UIHostingController(rootView: GalleryView()))
window.makeKeyAndVisible()
self.window = window

Expand Down
69 changes: 69 additions & 0 deletions Examples/Sources/GalleryView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// GalleryView.swift
// SwiftDraw
//
// Created by Simon Whitty on 19/2/25.
// Copyright 2019 Simon Whitty
//
// Distributed under the permissive zlib license
// Get the latest version from here:
//
// https://github.com/swhitty/SwiftDraw
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//

import SwiftDraw
import SwiftUI

struct GalleryView: View {

var imageNames: [String] = [
"avocado.svg",
"angry.svg",
"dish.svg",
"mouth-open.svg",
"sleepy.svg",
"smile.svg",
"snake.svg",
"spider.svg",
"star-struck.svg",
"worried.svg",
"yawning.svg",
"thats-no-moon.svg",
"alert.svg"
]

var body: some View {
if #available(iOS 15.0, *) {
ScrollView {
LazyVStack(spacing: 20) {
ForEach(imageNames, id: \.self) { name in
SVGView(name, bundle: .samples)
.aspectRatio(contentMode: .fit)
.padding([.leading, .trailing], 10)
// .frame(maxWidth: 320)
}
}
.background(Color.white)
}

}
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions SwiftDraw/Image.swift → SwiftDraw/SVG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public final class SVG: NSObject {
}
}

@available(*, deprecated, renamed: "SVG")
public typealias Image = SVG
@available(*, unavailable, renamed: "SVG")
public enum Image { }

#else

Expand Down
71 changes: 71 additions & 0 deletions SwiftDraw/SVGView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// SVGView.swift
// SwiftDraw
//
// Created by Simon Whitty on 19/2/25.
// Copyright 2019 Simon Whitty
//
// Distributed under the permissive zlib license
// Get the latest version from here:
//
// https://github.com/swhitty/SwiftDraw
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//

#if canImport(SwiftUI)
import SwiftUI

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public struct SVGView: View {

public init(_ name: String, bundle: Bundle = .main) {
self.svg = SVG(named: name, in: bundle)
}

Check warning on line 40 in SwiftDraw/SVGView.swift

View check run for this annotation

Codecov / codecov/patch

SwiftDraw/SVGView.swift#L38-L40

Added lines #L38 - L40 were not covered by tests

public init(svg: SVG) {
self.svg = svg
}

Check warning on line 44 in SwiftDraw/SVGView.swift

View check run for this annotation

Codecov / codecov/patch

SwiftDraw/SVGView.swift#L42-L44

Added lines #L42 - L44 were not covered by tests

private let svg: SVG?

public var body: some View {
if let svg {
Canvas(
opaque: false,
colorMode: .linear,
rendersAsynchronously: false
) { ctx, size in
ctx.draw(svg, in: CGRect(origin: .zero, size: size))
}
.frame(idealWidth: svg.size.width, idealHeight: svg.size.height)
}
}

Check warning on line 59 in SwiftDraw/SVGView.swift

View check run for this annotation

Codecov / codecov/patch

SwiftDraw/SVGView.swift#L48-L59

Added lines #L48 - L59 were not covered by tests
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
public extension GraphicsContext {

func draw(_ image: SVG, in rect: CGRect? = nil) {
withCGContext {
$0.draw(image, in: rect)
}
}

Check warning on line 69 in SwiftDraw/SVGView.swift

View check run for this annotation

Codecov / codecov/patch

SwiftDraw/SVGView.swift#L65-L69

Added lines #L65 - L69 were not covered by tests
}
#endif