Skip to content

Instantly share code, notes, and snippets.

View cyrilzakka's full-sized avatar
💭
coding...

Cyril Zakka, MD cyrilzakka

💭
coding...
View GitHub Profile
@Koshimizu-Takehito
Koshimizu-Takehito / HPicker.swift
Last active March 1, 2025 07:31
水平方向のピッカー
import SwiftUI
struct HPicker<SelectionValue, Content>: View where SelectionValue: Hashable, Content: View {
private var items: [SelectionValue]
private var numberOfDisplays: Int
private var content: (SelectionValue) -> Content
@Binding private var selection: SelectionValue?
@State private var contentOffset: Double = 0
@State private var itemWidth: Double = 100.0
@jrsaruo
jrsaruo / HorizontalInlinePicker.swift
Last active February 24, 2025 06:31
Horizontal Inline Picker by SwiftUI
import SwiftUI
// https://x.com/jrsaruo_tech/status/1893585977760743750
@available(iOS 18, *)
struct HorizontalInlinePicker<SelectionValue, Content>: View where SelectionValue: Hashable, Content: View {
@Binding var selection: SelectionValue
@State private var centerValue: SelectionValue?
@victorBaro
victorBaro / GlowingWaves.metal
Last active March 4, 2025 23:14
Glowing waves shader using new SwiftUI colorEffect modifier. Used code from here: https://github.com/GrishTad/GlowingWaves - Original shadertoy implementation here: https://www.shadertoy.com/view/tlySzm
#include <metal_stdlib>
using namespace metal;
// MARK: Helper methods
float N2(float2 p) {
p = fmod(p, float2(1456.2346));
float3 p3 = fract(float3(p.xyx) * float3(443.897, 441.423, 437.195));
p3 += dot(p3, p3.yzx + 19.19);
return fract((p3.x + p3.y) * p3.z);
}
@juliensagot
juliensagot / VariableBlurView.swift
Last active April 15, 2025 21:17
SwiftUI variable blur view
import Foundation
import SwiftUI
import UIKit
extension UIBlurEffect {
public static func variableBlurEffect(radius: Double, imageMask: UIImage) -> UIBlurEffect? {
let methodType = (@convention(c) (AnyClass, Selector, Double, UIImage) -> UIBlurEffect).self
let selectorName = ["imageMask:", "effectWithVariableBlurRadius:"].reversed().joined()
let selector = NSSelectorFromString(selectorName)
@realvjy
realvjy / ChoasLinesShader.metal
Last active May 24, 2025 23:38
Choas Lines - Metal Shader
// Lines
float hash( float n ) {
return fract(sin(n)*753.5453123);
}
// Slight modification of iq's noise function.
float noise(vector_float2 x )
{
vector_float2 p = floor(x);
vector_float2 f = fract(x);
@dkun7944
dkun7944 / ContentView.swift
Created July 31, 2023 03:36
AirDrop iOS 17 Swift.Shader Animation
//
// ContentView.swift
// Airdrop Demo
//
// Created by Daniel Kuntz on 7/30/23.
//
import SwiftUI
struct ContentView: View {
@alexwidua
alexwidua / ContentView.swift
Created July 4, 2023 17:07
SwiftUI Grid Animation
import SwiftUI
// 1. Use looped H/VStacks to create a grid
// 2. Conditionally increase spacing to grow/shrink the grid
// 3. Calculate the distance of each dot to the center and use the value to stagger the animation
//4. Add random delay on top of the staggered delay value
struct ContentView: View {
// const & state
@importRyan
importRyan / whenHovered.md
Last active March 2, 2025 12:00
Reliable SwiftUI mouse hover

Reliable mouseEnter/Exit for SwiftUI

Kapture 2021-03-01 at 14 43 39

On Mac, SwiftUI's .onHover closure is not always called on mouse exit, particularly with high cursor velocity. A grid of targets or with finer target shapes will often have multiple targets falsely active after the mouse has moved on.

It is easy to run back to AppKit's safety. Below is a SwiftUI-like modifier for reliable mouse-tracking. You can easily adapt it for other mouse tracking needs.

import SwiftUI
@andreyryabtsev
andreyryabtsev / backmatting.ipynb
Last active June 5, 2024 04:56
BackMatting.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
struct RootView: View {
@State private var isHomeShown = true
@State private var selectedContent = "content1"
var body: some View {
ZStack {
ContentView(content: $selectedContent,
isHomeShown: $isHomeShown)
.blur(radius: isHomeShown ? 10 : 0)
.scaleEffect(isHomeShown ? 0.8 : 1)