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
struct DrawingPath { | |
private var points = [CGPoint]() | |
private var breaks = [Int]() | |
mutating func addPoint(_ point: CGPoint) { | |
points.append(point) | |
} | |
mutating func addBreak() { | |
breaks.append(points.count) |
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
// Full recipe at https://swiftuirecipes.com/blog/weighted-layout-hstack-and-vstack-in-swiftui | |
import SwiftUI | |
class WeightedProxy { | |
let kind: Kind | |
var geo: GeometryProxy? = nil | |
private(set) var totalWeight: CGFloat = 0 | |
init(kind: Kind) { |
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
// Full recipe at https://swiftuirecipes.com/blog/swiftui-list-custom-row-swipe-actions-all-versions | |
import SwiftUI | |
// Button in swipe action, renders text or image and can have background color | |
struct SwipeActionButton: View, Identifiable { | |
static let width: CGFloat = 70 | |
let id = UUID() | |
let text: Text? |
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
// full recipe at https://swiftuirecipes.com/blog/swiftui-text-with-html-via-nsattributedstring | |
extension Text { | |
init(html htmlString: String, | |
raw: Bool = false, | |
size: CGFloat? = nil, | |
fontFamily: String = "-apple-system") { | |
let fullHTML: String | |
if raw { | |
fullHTML = htmlString | |
} else { |
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
// Check out https://swiftuirecipes.com/blog/chart-scan-line-lollipop-in-swiftui-with-charts-framework | |
import SwiftUI | |
import Charts | |
struct FoodIntake: Hashable { | |
let date: Date | |
let calories: Int | |
} |
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
// Full recipe at https://swiftuirecipes.com/blog/play-video-in-swiftui | |
import SwiftUI | |
import AVKit | |
import Foundation | |
struct EnhancedVideoPlayer<VideoOverlay: View>: View { | |
@StateObject private var viewModel: ViewModel | |
@ViewBuilder var videoOverlay: () -> VideoOverlay | |
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
import Foundation | |
public struct Service { | |
public enum LifeCycle { | |
case singleton | |
case factory | |
} | |
/// Holds the lifecycle of the current service | |
public var cycle: LifeCycle |
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
#!/usr/bin/env bash | |
set -e | |
cd node_modules/mqtt | |
cat > webpack.config.js << EOF | |
const webpack = require('webpack') | |
module.exports = { | |
entry: "./lib/connect/index.js", |
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
// full recipe at https://swiftuirecipes.com/blog/hyperlinks-in-swiftui-text | |
import SwiftUI | |
import SwiftUIFlowLayout | |
import MarkdownKit | |
struct HyperlinkTest: View { | |
var body: some View { | |
VStack { | |
HyperlinkText(html: "To <b>learn more</b>, <i>please</i> feel free to visit <a href=\"https://swiftuirecipes.com\">SwiftUIRecipes</a> for details, or check the <code>source code</code> at <a href=\"https://github.com/globulus\">Github page</a>.") | |
HyperlinkText(markdown: "To **learn more**, *please* feel free visit [SwiftUIRecipes](https://swiftuirecipes.com) for details, or check the `source code` at [Github page](https://github.com/globulus).") |