Skip to content

Instantly share code, notes, and snippets.

@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?
#include <metal_stdlib>
using namespace metal;
float smoothMin(float x1, float x2, float k) {
float h = clamp(0.5 - 0.5 * (x2 - x1) / k, 0.0, 1.0);
return mix(x1, x2, h) - k * h * (1.0 - h);
}
float circleSDF(float2 point, float2 center, float radius) {
return length(point - center) - radius;
import SwiftUI
struct ContentView: View {
var body: some View {
WavingText()
.foregroundStyle(.white)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(hue: 220/360, saturation: 0.3, brightness: 0.9))
}
}
import SwiftUI
struct ContentView: View {
@State var isExpanded = [true] + Array(repeating: false, count: PageItem.samples.count)
var body: some View {
ZStack {
ForEach(1..<isExpanded.count, id: \.self) { offset in
let item = PageItem.samples[(offset-1) % PageItem.samples.count]
PageView(
import SwiftUI
struct ContentView: View {
@State var isExpanded = [true] + Array(repeating: false, count: 10)
var body: some View {
ZStack {
ForEach(1..<isExpanded.count, id: \.self) { offset in
CircleView(
color: .color(offset: offset),
@Koshimizu-Takehito
Koshimizu-Takehito / ShaderView.swift
Created February 11, 2025 04:35
MSLでパーティクル
import SwiftUI
struct ShaderView: View {
let name: String
private let start = Date()
var body: some View {
let shader = ShaderFunction(library: .default, name: name)
TimelineView(.animation) { context in
let seconds = context.date.timeIntervalSince(start)
@Koshimizu-Takehito
Koshimizu-Takehito / TileAnimation2.swift
Created January 18, 2025 09:25
ViewのIdentity を意識してアニメーション素振り
import SwiftUI
// MARK: - Model
@MainActor
@Observable
final class Model {
var angles: [[Angle]]
init(row: Int, column: Int) {
angles = (0..<row).map { _ in
import React, { useState } from 'react';
import { Pressable, View } from 'react-native';
import Animated, { css } from 'react-native-reanimated';
export default function Wave() {
const [clickLocation, setClickLocation] = useState({ x: -1, y: -1 });
const dots = Array.from({ length: 323 });
const size = 19;
const color = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`
import React, { useState } from 'react';
import { Pressable, Text } from 'react-native';
import Animated, { css } from 'react-native-reanimated';
export default function ParticleButton() {
const [pressed, setPressed] = useState(false);
const [showParticles, setShowParticles] = useState(false);
return (
<Pressable