All Projects → demharusnam → SwiftUIDrag

demharusnam / SwiftUIDrag

Licence: MIT license
A simple, customizable, and intuitive SwiftUI wrapper-view enabling dragging, floating, and/or collapsing for its content.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to SwiftUIDrag

Harbour
Docker/Portainer management app for iOS
Stars: ✭ 210 (+400%)
Mutual labels:  ios-app, swiftui
Tasky
Tasky is a task management app made with SwiftUI.
Stars: ✭ 22 (-47.62%)
Mutual labels:  ios-app, swiftui
LongWeekend-iOS
🏖📱 LongWeekend is iOS Application that supports checking long weekends when taking a vacation in Japan
Stars: ✭ 19 (-54.76%)
Mutual labels:  ios-app, swiftui
FootballDataSwiftUI
Display Football Data such as scores, upcoming match, team standing, top scorers with football Data API and SwiftUI
Stars: ✭ 76 (+80.95%)
Mutual labels:  ios-app, swiftui
o-fish-ios
iOS app for the Officer's Fishery Information Sharing Hub (O-FISH). The mobile app allows fisheries officers to document and share critical information gathered during a routine vessel inspection.
Stars: ✭ 28 (-33.33%)
Mutual labels:  ios-app, swiftui
Monthly-App-Challenge-2022
Retos mensuales de la comunidad MoureDev para crear pequeñas aplicaciones en base a requisitos
Stars: ✭ 153 (+264.29%)
Mutual labels:  ios-app, swiftui
Wiggles-iOS
Beautiful Puppy adoption app built to Demonstrate the SwiftUI and MVVM Architecture
Stars: ✭ 174 (+314.29%)
Mutual labels:  ios-app, swiftui
Hush
Noiseless Browsing – Content Blocker for Safari
Stars: ✭ 1,987 (+4630.95%)
Mutual labels:  ios-app, swiftui
Actions
⚙️ Supercharge your shortcuts
Stars: ✭ 640 (+1423.81%)
Mutual labels:  ios-app, swiftui
NYTimes-iOS
🗽 NY Times is an Minimal News 🗞 iOS app 📱 built to describe the use of SwiftSoup and CoreData with SwiftUI🔥
Stars: ✭ 152 (+261.9%)
Mutual labels:  ios-app, swiftui
puffery
A SwiftUI iOS App and Vapor Server to send push notifications fueled by Siri Shortcuts.
Stars: ✭ 17 (-59.52%)
Mutual labels:  ios-app, swiftui
Swiftui Tutorials
A code example and translation project of SwiftUI. / 一个 SwiftUI 的示例、翻译的教程项目。
Stars: ✭ 1,992 (+4642.86%)
Mutual labels:  ios-app, swiftui
Slipbox
The project is using Core Data with iCloud sync. It is a cross-platform app for iOS and macOS written in SwiftUI.
Stars: ✭ 49 (+16.67%)
Mutual labels:  swiftui
DAudiobook
模仿QQ布局写的一个小项目--小熊有声小说
Stars: ✭ 79 (+88.1%)
Mutual labels:  ios-app
ridesharing-ios
Ridesharing driver & rider sample apps using HyperTrack SDK
Stars: ✭ 97 (+130.95%)
Mutual labels:  swiftui
paragon firewall ce
Paragon Firewall for Mac
Stars: ✭ 63 (+50%)
Mutual labels:  swiftui
Windows11
💻 Windows 11 in SwiftUI.
Stars: ✭ 177 (+321.43%)
Mutual labels:  swiftui
ZudVPN
A mobile application to deploy private VPN servers in the cloud with DNS ad-blocking and other features
Stars: ✭ 119 (+183.33%)
Mutual labels:  ios-app
SwiftDown
📦 A themable markdown editor component for your SwiftUI apps.
Stars: ✭ 203 (+383.33%)
Mutual labels:  swiftui
Scout
Scout is a kotlin multiplatform application that allows users to search and save games to lists to be browsed later.
Stars: ✭ 28 (-33.33%)
Mutual labels:  ios-app

SwiftUIDrag

A simple, customizable, and intuitive wrapper-view enabling dragging, floating, and/or collapsing for its content. Written entirely in SwiftUI, SwiftUIDrag is inspired by iOS 14's Picture-in-Picture feature.

Floating TabView demo of SDView VideoPlayer demo of SDView Rectangle demo of SDView

Table of Contents

Usage

SDView(floating: .leading, collapse: .trailing) { geo, state in
    RoundedRectangle(cornerRadius: 25)
        .fill(Color.blue)
        .frame(width: geo.size.width / 2, height: geo.size.height / 4)
        .overlay(
            HStack {
                Image(systemName: "chevron.left")
                .foregroundColor(.white)
                .frame(width: 10, height: 20)
                .opacity(state.isCollapsed && state.isTrailing ? 1 : 0)
                .padding(.leading)
                
                Spacer()
            }
        )
}

This code enables the capabilities seen in the blue rectangle demo above.

Key Features

Below is the default initializer which requires you to enter only one parameter: the content to inherit the SDView drag, floating, and/or collapse properties. The remaining parameters all have default values that can be left as is or can be customized for your use-case.

SDView(
    alignment: Alignment = .center,
    floating: SDFloatingOptions = [],
    collapse: SDCollapseOptions = .horizontal,
    visibleSize: CGSize = CGSize(width: 60, height: 60),
    @ViewBuilder content: @escaping (GeometryProxy, SDContentState) -> Content
)

The quickest way to get started is with the default paramters as such:

SDView { _, _ in
    // your content.
}

Alignment

The alignment parameter allows you to position your content based on SwiftUI's Alignment struct. By default, it is set to center which positions your content in the center of SDView. Thus, you get access to the following options:

Options
topLeading
top
topTrailing
leading
center
trailing
bottomLeading
bottom
bottomTrailing

Floating

The floating parameter enables you to float your content on the edges of the SDView. By default, it is set to [] which disables floating. Customization is at the heart of this package, thus you get access to the following options:

Option Description
[] disables floating
topLeading enables floating content on the top-leading side of SDView
topTrailing enables floating content on the top-trailing side of SDView
bottomLeading enables floating on the bottom-leading side of SDView
bottomTrailing enables floating on the bottom-trailing side of SDView
top enables floating content on either the top-leading or top-trailing sides of SDView
bottom enables floating content on either the bottom-leading or bottom-trailing sides of SDView
leading enables floating content on either the top-leading or bottom-leading sides of SDView
trailing enables floating content on either the top-trailing or bottom-trailing sides of SDView
all enables floating content on either the top-leading, top-trailing, bottom-leading, bottom-trailing sides of SDView

Collapse

The collapse parameter enables you to collapse your content into the sides of the SDView with a set visibleSize. By default, it is set to horizontal which only enables collapsing on the leading and trailing sides. Customization is at the heart of this package, thus you get access to the following options:

Option Description
[] disables collapsing
top enables collapsing content on the top side of SDView
bottom enables collapsing content on the bottom side of SDView
leading enables collapsing on the leading side of SDView
trailing enables collapsing on the trailing side of SDView
horizontal enables collapsing content on either the leading or trailing sides of SDView
vertical enables collapsing content on either the top or bottom sides of SDView
all enables collapsing content on either the top, bottom, leading, trailing sides of SDView

Visible Size

The visibleSize parameter determines how much width or height of your content should be visible upon collapse. By default it is set to 60 for both.

Content

The content parameter is @escaping- and @ViewBuilder-wrapped which enables escaping into curly braces for you to easily describe your content in. Additionally, you get two callback parameters: GeometryProxy and SDContentState.

The GeometryProxy enables you to customize any framing, positioning, and/or sizing based on the SDView.

The SDContentState parameter indicates the state of your content. Once again, customization is at the heart of this package, so you get the following state options:

Option Description
top content is collapsed on the top side of SDView
bottom content is collapsed on bottom side of SDView
leading content is collapsed on leading side of SDView
trailing content is collapsed on trailing side of SDView
topLeading content is floating on top-leading side of SDView
topTrailing content is floating on top-trailing side of SDView
bottomLeading content is floating on the bottom-leading side of SDView
bottomTrailing content is floating on the bottom-trailing side of SDView
expanded content is neither collapse nor floating on any side of SDView

To take it a step further, you also get access to Bool variables that allow for swift verification of the content state:

Option Description
isTop content is either collapsed or floating on the top side of SDView
isBottom content is either collapsed or floating on the bottom side of SDView
isLeading content is either collapsed or floating on the leading side of SDView
isTrailing content is either collapsed or floating on the trailing side of SDView
isCollapsed content is collapsed in SDView
isFloating content is floating in SDView
isExpanded content is expanded

Installation

SwiftUIDrag can be installed via Swift Package Manager (SPM) in Xcode:

  1. Navigate to the SPM (File > Swift Packages > Add Package Dependency...)
  2. Either enter the URL (https://github.com/demharusnam/SwiftUIDrag) or the name of the package in the search bar. If you opted for the latter, select the displayed package with myself (demharusnam) as the owner.

Author

My name is Mansur. At the time of publishing SwiftUIDrag, I am an undergraduate computer engineering student from Toronto, Canada. I love Swift, SwiftUI, and creating software.

If you have any questions regarding SwiftUIDrag, please feel free to contact me.

Happy hacking!

License

SwiftUIDrag is available under the MIT license. See LICENSE for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].