Skip to content

Instantly share code, notes, and snippets.

View zunda-pixel's full-sized avatar

zunda zunda-pixel

View GitHub Profile
@zunda-pixel
zunda-pixel / List+onScrollTargetVisibilityChange.swift
Created July 21, 2025 13:59
SwiftUI.List has problem with onScrollTargetVisibilityChange.swift
struct ContentView2: View {
var model = Model()
var body: some View {
NavigationStack {
List {
ForEach(model.items.sorted(using: KeyPathComparator(\.createdDate, order: .reverse))) { item in
Cell(item: item)
}
}
@zunda-pixel
zunda-pixel / List+onScrollVisibilityChange.swift
Last active July 21, 2025 13:44
SwiftUI.List has problem with onScrollVisibilityChange
struct Item: Identifiable {
var id: UUID = UUID()
var value: Int
var createdDate: Date
}
@Observable
class Model {
var items: [Item] = (0..<100).map { Item(value: $0, createdDate: .now.addingTimeInterval(Double($0 * 60 * 60 * 24))) }
var itemVisibility: [Item.ID: Bool] = [:]
@zunda-pixel
zunda-pixel / Swift-OptionSet-Macro-Overflow-problem.swift
Last active May 31, 2025 14:05
Swift OptionSet Macro Overflow problem
@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
@attached(extension, conformances: OptionSet)
public macro OptionSet<RawType>() = #externalMacro(module: "SwiftMacros", type: "OptionSetMacro")
@OptionSet<UInt8>
struct Parameters {
enum Options: UInt8 {
case p0 = 0
case p7 = 7
@zunda-pixel
zunda-pixel / DoubleBorderModifier.swift
Created April 8, 2025 18:28
Double Border and Shade in SwiftUI
// https://x.com/usagimaruma/status/1460083928358789123
struct ContenteView: View {
var text = "プレゼンテーション"
var body: some View {
VStack {
Rectangle()
.fill(Color(.secondarySystemGroupedBackground))
.frame(width: 300, height: 100)
@zunda-pixel
zunda-pixel / 等幅画像.swift
Created August 14, 2023 09:20
等幅画像 SwiftUI
struct ContentView: View {
let urls: [URL] = [
.init(string: "https://webcg.ismcdn.jp/mwimgs/0/f/640wm/img_0f0ccf94fbdcfab41992550a42460808110746.jpg")!,
.init(string: "https://upload.wikimedia.org/wikipedia/commons/thumb/8/85/Tour_Eiffel_Wikimedia_Commons_%28cropped%29.jpg/640px-Tour_Eiffel_Wikimedia_Commons_%28cropped%29.jpg")!,
]
var body: some View {
ScrollView {
LazyVStack(spacing: 40) {
ForEach(urls, id: \.self) { url in
@zunda-pixel
zunda-pixel / SampleApp.swift
Last active June 22, 2023 09:32
SwiftData Relationship(cascade, inverse) delete bug
// 1. Add Person
// 2. Add Car
// 3. Delete Person(or Car)
import SwiftUI
import SwiftData
@main
struct Xcode17_SampleApp: App {
var body: some Scene {
@zunda-pixel
zunda-pixel / NavigationSplitView+tint.swift
Last active June 2, 2023 16:08
NavigationSplitView's sidebar doesn't support tint
struct ContentView: View {
@State var selection: Int? = 0
var body: some View {
NavigationSplitView {
List(selection: $selection) {
ForEach(0..<10) { i in
Text("Data \(i)")
.tag(i)
}
@zunda-pixel
zunda-pixel / NavigationSplitView+TabView+toolbar(.hidden).swift
Last active May 17, 2024 17:56
.toolbar(.hidden, for: .tabBar) does not work when multiple tab change
import SwiftUI
enum TabItem: String, CaseIterable, Hashable, Identifiable {
case first
case second
case third
var id: Self { self }
}
struct ContentView: View {
@zunda-pixel
zunda-pixel / Environment-openURL-bug.swift
Created January 15, 2023 09:22
Environment openURL NavigationLink Bug?
// Previewだと動くがシミュレーターだと動かない
// 原因? Environment(\.openURL), NavigationLink
struct ContentView: View {
let urls: [URL] = [
URL(string: "https://github.com")!,
URL(string: "https://github.com")!,
URL(string: "https://github.com")!,
]
@zunda-pixel
zunda-pixel / ContentView.swift
Last active December 15, 2022 10:43
.toolbarBackground(.visible, for: .navigationBar) has no padding
struct ContentView: View {
@State var text = ""
var body: some View {
NavigationStack {
List {
TextField("Text", text: $text)
}
//.padding(.top, 10)
.toolbarBackground(.visible, for: .navigationBar)