Skip to content

Instantly share code, notes, and snippets.

View literalpie's full-sized avatar

Benjamin Kindle literalpie

View GitHub Profile
import {
Component,
component$,
useStore,
PublicProps,
useTask$,
noSerialize,
NoSerialize,
} from "@builder.io/qwik";
import { Meta, StoryObj } from "storybook-framework-qwik/*";
struct ListTransitionView: View {
@State var pickedNumber: Int?
@Namespace var namespace
var body: some View {
VStack {
if pickedNumber == nil {
VStack(spacing: 15) {
ForEach(0..<3) { number in
Button("Hello world \(number)") {
@literalpie
literalpie / scenekit-better-pan-gesture-recognizer.swift
Last active January 28, 2021 21:35
a better approach to handling the pan gesture in scenekit. For use in part 3 of medium post
@objc func handlePan(panGesture: UIPanGestureRecognizer) {
guard let view = view as? SCNView else { return }
let location = panGesture.location(in: self.view)
switch panGesture.state {
case .began:
// existing logic from previous approach. Keep this.
guard let hitNodeResult = view.hitTest(location, options: nil).first else { return }
panStartZ = CGFloat(view.projectPoint(lastPanLocation!).z)
// lastPanLocation is new
lastPanLocation = hitNodeResult.worldCoordinates
@literalpie
literalpie / scenekit-better-pan-gesture-recognizer.swift
Created May 19, 2019 16:33
a better approach to handling the pan gesture in scenekit. For use in part 3 of medium post
@objc func handlePan(panGesture: UIPanGestureRecognizer) {
guard let view = view as? SCNView else { return }
switch panGesture.state {
case .began:
let location = panGesture.location(in: self.view)
guard let hitNodeResult = view.hitTest(location, options: nil).first else { return }
panStartZ = CGFloat(view.projectPoint(lastPanLocation!).z)
lastPanLocation = hitNodeResult.worldCoordinates
draggingNode = hitNodeResult.node
case .changed:
@literalpie
literalpie / SceneKit-simple-pan-gesture-handler.swift
Last active May 16, 2020 14:15
shows a simple pan gesture handler for use in part 2 of a literalpie medium post
@objc func handlePan(panGesture: UIPanGestureRecognizer) {
guard let view = view as? SCNView else { return }
let location = panGesture.location(in: self.view)
switch panGesture.state {
case .began:
guard let hitNodeResult = view.hitTest(location, options: nil).first else { return }
// panStartZ and draggingNode should be defined in the containing class
panStartZ = CGFloat(view.projectPoint(lastPanLocation!).z)
draggingNode = hitNodeResult.node
case .changed:
@literalpie
literalpie / scenekit-pan-gesture-setup.swift
Last active May 19, 2019 16:38
for use in part 1 of a literalpie medium post
// Create the box:
let cube = SCNBox(width: 10, height: 10, length: 10, chamferRadius: 1.0)
let cubeNode = SCNNode(geometry: cube)
scene.rootNode.addChildNode(cubeNode)
// Create the gesture recognizer:
let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(handlePan(panGesture:)))
view.addGestureRecognizer(panRecognizer)