Skip to content

Instantly share code, notes, and snippets.

View juliensagot's full-sized avatar

Julien Sagot juliensagot

View GitHub Profile
@juliensagot
juliensagot / Interface.swift
Created June 13, 2024 07:49
SwiftUI Interface (from Xcode 16.0 Beta, module names removed)
This file has been truncated, but you can view the full file.
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 6.0 effective-5.10 (swiftlang-6.0.0.3.38 clang-1600.0.20.6)
// swift-module-flags: -target arm64e-apple-ios18.0 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -Osize -library-level api -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -enable-experimental-feature IsolatedAny -enable-bare-slash-regex -user-module-version 6.0.70.5.103 -module-name SwiftUI -package-name SwiftUI
import Accessibility
import Combine
import CoreData
import CoreFoundation
@_exported import CoreGraphics
@_exported import CoreTransferable
import Darwin
@juliensagot
juliensagot / HostingView.swift
Created June 21, 2024 14:22
The missing UIHostingView
import SwiftUI
import UIKit
public final class HostingView: UIView {
public init(@ViewBuilder content: () -> some View) {
super.init(frame: .zero)
let contentView = UIHostingConfiguration(content: content)
.margins(.all, 0)
.makeContentView()
@juliensagot
juliensagot / ResponsiveButtonStyle.swift
Last active November 22, 2024 13:04
Custom ButtonStyle boilerplate that doesn't take ages to update its `isPressed` state when using spring animations
struct ResponsiveButtonStyle: PrimitiveButtonStyle {
// Use this instead of `Configuration.isPressed`.
@State private var isPressed = false
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(isPressed ? 0.9 : 1)
.animation(.spring, value: isPressed)
._onButtonGesture { isPressed in
self.isPressed = isPressed
@juliensagot
juliensagot / CustomButtonStyle.swift
Created October 10, 2024 17:37
SwiftUI custom ButtonStyle example
import SwiftUI
struct CapsuleButtonStyle: ButtonStyle {
enum Appearance {
case plain
case outlined
}
let appearance: Appearance
@juliensagot
juliensagot / ConditionalEnvironmentOverlay.swift
Created November 8, 2024 10:40
ConditionalEnvironmentOverlay
private struct ConditionalEnvironmentOverlay<Value: Equatable, OverlayContent: View>: ViewModifier {
@Environment(\.self) private var environmentValues
private let keyPath: KeyPath<EnvironmentValues, Value>
private let value: Value
private let overlayContent: OverlayContent
init(
condition: KeyPath<EnvironmentValues, Value>,
equals value: Value,
@juliensagot
juliensagot / AquaScrollBar.swift
Created February 16, 2025 14:17
Aqua scroll bar in SwiftUI
import SwiftUI
struct AquaScrollBar: View {
@ScaledMetric private var height = 35.0
var body: some View {
Track()
.frame(height: height)
.overlay(alignment: .leading) {
Thumb()