nsstudent/tearkit
This repository contains:
Inspiration
This project is a clear reference to the idea presented by @naoenomoto on X.
Project Overview
- Edge-based interactive tear gesture.
- Real-time Metal distortion shader.
- Direction modes for tearing (
.vertical,.horizontal,.anyDirection). - Configurable threshold logic (
breakThreshold) for full break vs recovery. - External progress/completion callbacks so host apps define final UI behavior.
Demo
[TearKit demo]
Photo Credit
- Demo photo source: Unsplash
- Photographer: Philipp Dice
Structure
Package.swift: package manifest.Sources/TearKit/TearTypes.swift: shared tear types (TearEdge,TearCutDirection).Sources/TearKit/TearState.swift: tear state and gesture math.Sources/TearKit/TearModifier.swift: SwiftUI modifier that wires gesture + shader.Sources/TearKit/Extensions/View+TearKitExtensions.swift: publicViewextension (tearable).Sources/TearKit/TearEffect.metal: tear shader.TearKitDemo/ContentView.swift: demo usage and host-side animation.Tests/TearKitTests/TearStateTests.swift: unit tests for geometry/state rules.docs/: detailed documentation.
Installation
Swift Package Manager (Xcode)
- In Xcode, go to
File > Add Package Dependencies... - Enter your repository URL.
- Select the
TearKitlibrary product in your target.
Swift Package Manager (Package.swift)
dependencies: [
.package(url: "https://github.com/<your-org>/TearKit.git", from: "1.0.0")
],
targets: [
.target(
name: "MyFeature",
dependencies: [
.product(name: "TearKit", package: "TearKit")
]
)
]Usage
import TearKit
MyView()
.tearable(
edgeRoughness: 4,
maxGapWidth: 20,
breakThreshold: 0.9,
cutDirection: .anyDirection, // .vertical | .horizontal | .anyDirection
isBroken: $isBroken, // set false to recover, set true to force broken state
onProgressChanged: { progress in
// 0...1
},
onCompletion: { isFullyBroken in
// true: fully torn, false: recovered
}
)API Notes
breakThresholdis clamped to0...1.edgeRoughnessandmaxGapWidthare clamped to non-negative values.isBrokencan be used to externally reset (false) or force the broken state (true).
Documentation
Running
- Open
TearKitDemo.xcodeprojin Xcode. - Build and run the
TearKitDemoscheme. - Drag from any edge on the demo card to test tearing behavior.
Package Metadata
Repository: nsstudent/tearkit
Default branch: main
README: README.md