How rohanrhu/swipy works
Project Type and Purpose
• Swipy is a SwiftUI library that integrates with existing applications (or can be directly copied into a project as a single Swipy.swift file) to add swipe actions.
• Its purpose is to wrap SwiftUI views in a gesture-aware container that supports swiping with customizable actions, behaviors, and a central model to track swipe state.
Analyzing the File Structure
• The top-level files are Project management files such as Package.swift (for Swift Package Manager) and an Xcode project (Swipy.xcodeproj).
• The core logic lives in the single source file “Swipy/Swipy.swift” where the main SwiftUI components (views and model) are defined.
• Support files like README, LICENSE, CONTRIBUTING, and CODE_OF_CONDUCT are present for project governance, while Media holds relevant images used by the README.
Main Components
• Swipy View: The primary component that wraps any content view to capture swipe gestures. It accepts a binding for isSwipingAnItem, a content closure, and an actions closure.
• SwipyAction: The component that encapsulates an individual swipe action (e.g. delete, edit). It uses a closure that receives a SwipyModel for performing actions.
• SwipyModel: The internal state model that is passed into closures. It maintains properties such as swipeOffset, isSwiping, isSwiped, and supports imperative methods like swipe() and unswipe().
• Behaviors:
• SwipySwipeBehavior: Configures the starting and continuing conditions for swipe gestures using predefined methods (.normal, .soft, etc.) or custom decider functions.
• SwipyScrollBehavior: Configures the interaction with scrolling (prevents vertical scroll interference during swiping).
• External Dependencies: SwiftUI as the underlying UI framework; the library is intended to be integrated using Swift Package Manager or manually via copying the file.
Examining Interactions Between Components
• The user’s gesture on a swipeable view (wrapped within Swipy) initiates the gesture listening in the SwiftUI environment.
• Swipy captures the swipe gesture and updates the SwipyModel, which holds the current swipe state.
• The actions themselves are closures that may trigger a method on the model (like unswipe() after a deletion action), which then informs the UI to update accordingly.
• The isSwipingAnItem binding serves as a flag that’s also used to control container (e.g., ScrollView) scrolling via SwiftUI’s .scrollDisabled modifier.
Final Elements
• Clear labels for each component (e.g., “Swipy – swipeable container”, “SwipyAction – action button view”, “SwipyModel – tracking swipe state”).