Skip to content

Instantly share code, notes, and snippets.

View colinfwren's full-sized avatar

Colin Wren colinfwren

View GitHub Profile
.bag {
/* hoist the item list scroll progress scope to the parent so can be shared */
timeline-scope: --item-list-scroll-timeline;
}
.item-list {
/* make the item lists y-axis scroll progress available as a variable */
scroll-timeline: --item-list-scroll-timeline y;
}
.bag {
/* hoist the item list scroll progress scope to the parent so can be shared */
timeline-scope: --item-list-scroll-timeline;
}
.item-list {
/* make the item lists y-axis scroll progress available as a variable */
scroll-timeline: --item-list-scroll-timeline y;
}
.item-list {
/* make the item lists y-axis scroll progress available as a variable */
scroll-timeline: --item-list-scroll-timeline y;
}
.bag-section-image {
/* The animation(s) to drive using the scroll progress */
animation: item-bag-image linear;
/* Hook up the item lists scroll progress to drive the animation */
animation-timeline: --item-list-scroll-timeline;
<div class="item-screen">
<div class="bag">
<div class="bag-details">
<div class="bag-section-title"></div>
<div class="bag-section-image">
<img src="img/item-shadow.png" />
</div>
</div>
<div class="item-list">
<ul>
@colinfwren
colinfwren / ApproachModel.swift
Created November 19, 2023 21:32
Date Test Approach 3 Data Model
import Foundation
import SwiftData
@Model
final class ApproachModel {
var title: String
var date: Date
var granularity: DateGranularity
var year: Int {
@colinfwren
colinfwren / fetchMonthData.swift
Created November 19, 2023 21:29
Date Test Approach 2 fetchMonthData and fetchYearData
func fetchMonthData() {
do {
let calendar = Calendar.init(identifier: .iso8601)
let date = calendar.date(from: DateComponents(year: year, month: month: day: 1))!
let weekOfMonth = calendar.component(.weekOfMonth, from: date)
var predicate: Predicate<ApproachModel>
if (weekOfMonth == 0) {
let weekOfYear = calendar.component(.weekOfYear, from: date)
predicate = #Predicate { todo in
((todo.year == year && todo.month == month) || (todo.week == weekOfYear)) && todo.shownInMonth == true
@colinfwren
colinfwren / fetchDayData.swift
Created November 19, 2023 21:26
Date Test Approach 2 fetchDayData
func fetchDayData() {
do {
let descriptor = FetchDescriptor<ApproachModel>(predicate: #Predicate { todo in
todo.year == year && todo.month == month && todo.day == day && todo.shownInDay == true
})
todos = try modelContext.fetch(descriptor)
} catch {
print("Failed to fetch day data")
}
}
@colinfwren
colinfwren / ApproachTodoListViewModel.swift
Created November 19, 2023 21:25
Date Test Approach 2 View Model
class ApproachTodoListViewModel: Identifiable {
var modelContext: ModelContext
var title: String
var todos = [ApproachModel]()
var granularity: DateGranularity
var year: Int
var month: Int?
var week: Int?
var day: Int?
@colinfwren
colinfwren / ApproachModel.swift
Created November 19, 2023 21:24
Date Test Approach 2 Data Model
import Foundation
import SwiftData
@Model
final class ApproachModel {
var title: String
var year: Int
var month: Int? = nil
var week: Int? = nil
var day: Int? = nil
@colinfwren
colinfwren / fetchMonthData.swift
Created November 19, 2023 21:21
Date Test Approach 1 fetchMonthData
func fetchMonthData() {
do {
let descriptor = FetchDescriptor<ApproachModel>(predicate: #Predicate { todo in
((todo.startDate >= startDate && todo.startDate <= endDate) || (todo.endDate >= startDate && todo.endDate <= endDate)) && todo.shownInWeek == true
}, sortBy: [SortDescriptor(\.endDate)])
todos = try modelContext.fetch(descriptor)
} catch {
print("Failed to fetch month data")
}
}