All Projects → faberNovel → DynamicOverlay

faberNovel / DynamicOverlay

Licence: MIT License
A SwiftUI library that makes easier to develop overlay based interfaces, such as the one presented in the Apple Maps app.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to DynamicOverlay

MultiModal
Use multiple .sheet, .alert, etc. modifiers in the same SwiftUI View
Stars: ✭ 49 (-45.56%)
Mutual labels:  sheet, swiftui
Zhpopupcontroller
Help you pop up custom views easily. and support pop-up animation, layout position, mask effect and gesture interaction etc.
Stars: ✭ 1,481 (+1545.56%)
Mutual labels:  overlay, sheet
BottomSheet
BottomSheet lets you add custom bottom sheets to your SwiftUI apps.
Stars: ✭ 111 (+23.33%)
Mutual labels:  sheet, swiftui
react-spring-bottom-sheet
Accessible ♿️, Delightful ✨, & Fast 🚀
Stars: ✭ 604 (+571.11%)
Mutual labels:  overlay, sheet
busy-load
A flexible loading-mask jQuery-plugin
Stars: ✭ 76 (-15.56%)
Mutual labels:  overlay
ColorUp
An easy way to generate strongly typed Swift extensions for either UIColor or Color based off of your colors within the project's asset catalog.
Stars: ✭ 16 (-82.22%)
Mutual labels:  swiftui
android-textoverlay
Provides a simple service that allows to display arbitrary text as a system-window overlay.
Stars: ✭ 20 (-77.78%)
Mutual labels:  overlay
aws-serverless-fullstack-swift-apple-carplay-example
This application demonstrates a full-stack Apple CarPlay app that uses Swift for both the UI and the backend services in AWS. The app accesses Lambda functions written in Swift and deployed from Docker images. The app accesses Amazon Location Service and a 3rd party weather api to display information in the vicinity of the user.
Stars: ✭ 84 (-6.67%)
Mutual labels:  swiftui
SwiftUIRealtimeShoppingCart
SwiftUI Collaborative Shopping Cart with Firestore Database
Stars: ✭ 34 (-62.22%)
Mutual labels:  swiftui
esm-overlay
ESM's portage overlay. It's useful for especially Ruby/Rails application development.
Stars: ✭ 19 (-78.89%)
Mutual labels:  overlay
tapit-app
App which lets two people share their social media details by simply putting one phone on top of the other ("tapping"). Currently in development by Nikita Mounier.
Stars: ✭ 18 (-80%)
Mutual labels:  swiftui
IndieApps
A platform to showcase your side projects/apps
Stars: ✭ 23 (-74.44%)
Mutual labels:  swiftui
PathBuilder
SwiftUI result builder for Path
Stars: ✭ 48 (-46.67%)
Mutual labels:  swiftui
SettingsAppInSwiftUI
I have recreated a Settings App in iPhoneXR using SwiftUI concepts such as Form,Section,Toggle,Picker,Stack..etc
Stars: ✭ 37 (-58.89%)
Mutual labels:  swiftui
root-ro
Read-only root filesystem for Raspbian Stretch (using overlay)
Stars: ✭ 75 (-16.67%)
Mutual labels:  overlay
column-text-view-ui
📄 Column Text View is an adaptive UI component that renders text in columns, horizontally [iOS 12, UIKit, TextKit, SwiftUI].
Stars: ✭ 11 (-87.78%)
Mutual labels:  swiftui
BDUIKnit
A Swift Package Manager packed with SwiftUI custom reusable UI components and extensions.
Stars: ✭ 21 (-76.67%)
Mutual labels:  swiftui
TagField
🏷 Simple Tag Field for SwiftUI 🏷
Stars: ✭ 19 (-78.89%)
Mutual labels:  swiftui
SwiftUI-Shimmer
Shimmer is a super-light modifier that adds a shimmering effect to any SwiftUI View, for example, to show that an operation is in progress. It works well on light and dark modes, and across iOS, macOS, tvOS and watchOS.
Stars: ✭ 168 (+86.67%)
Mutual labels:  swiftui
Helm
A graph-based SwiftUI router
Stars: ✭ 64 (-28.89%)
Mutual labels:  swiftui

DynamicOverlay

DynamicOverlay is a SwiftUI library. It makes easier to develop overlay based interfaces, such as the one presented in the Apple Maps, Stocks or Shortcuts apps.

Platform Swift5 CocoaPods Carthage Build Status License


Requirements

DynamicOverlay is written in Swift 5. Compatible with iOS 13.0+.

Getting started

A dynamic overlay is an overlay that dynamically reveals or hides the content underneath it.

You add a dynamic overlay as a regular one using a view modifier:

Color.blue.dynamicOverlay(Color.red)

Its behavior is defined by the DynamicOverlayBehavior associated to it if any.

Color.blue
    .dynamicOverlay(Color.red)
    .dynamicOverlayBehavior(myOverlayBehavior)

var myOverlayBehavior: some DynamicOverlayBehavior {
    ...
}

If you do not specify a behavior in the overlay view hierarchy, it uses a default one.

Examples

Min Max

Magnetic notch overlay

MagneticNotchOverlayBehavior is a DynamicOverlayBehavior instance. It is the only behavior available for now.

It describes an overlay that can be dragged up and down alongside predefined notches. Whenever a drag gesture ends, the overlay motion will continue until it reaches one of its notches.

Specifying the notches

The preferred way to define the notches is to declare an CaseIterable enum:

enum Notch: CaseIterable, Equatable {
    case min, max
}

You specify the dimensions of each notch when you create a MagneticNotchOverlayBehavior instance:

@State var isCompact = false

var myOverlayBehavior: some DynamicOverlayBehavior {
    MagneticNotchOverlayBehavior<Notch> { notch in
        switch notch {
        case .max:
            return isCompact ? .fractional(0.5) : .fractional(0.8)
        case .min:
            return .fractional(0.3)
        }
    }
}

There are two kinds of dimension:

extension NotchDimension {

    /// Creates a dimension with an absolute point value.
    static func absolute(_ value: Double) -> NotchDimension

    /// Creates a dimension that is computed as a fraction of the height of the overlay parent view.
    static func fractional(_ value: Double) -> NotchDimension
}

Drag gesture support

By default, all the content of the overlay is draggable but you can limit this behavior using the draggable view modifier.

Here only the list header is draggable:

var body: some View {
    Color.green
        .dynamicOverlay(myOverlayContent)
        .dynamicOverlayBehavior(myOverlayBehavior)
}

var myOverlayContent: some View {
    VStack {
        Text("Header").draggable()
        List {
            Text("Row 1")
            Text("Row 2")
            Text("Row 3")
        }
    }
}

var myOverlayBehavior: some DynamicOverlayBehavior {
    MagneticNotchOverlayBehavior<Notch> { ... }
}

Here we disable the drag gesture entirely:

var myOverlayContent: some View {
    VStack {
        Text("Header")
        List {
            Text("Row 1")
            Text("Row 2")
            Text("Row 3")
        }
    }
    .draggable(false)
}

Scroll view support

A magnetic notch overlay can coordinate its motion with the scrolling of a scroll view.

Mark the ScrollView or List that should dictate the overlays movement with divingScrollView().

var myOverlayContent: some View {
    VStack {
        Text("Header").draggable()
        List {
            Text("Row 1")
            Text("Row 2")
            Text("Row 3")
        }
        .drivingScrollView()
    }
}

Responding to overlay updates

You can track the overlay motions using the onTranslation(_:) view modifier. It is a great occasion to update your UI based on the current overlay state.

Here we define a control that should be right above the overlay:

struct ControlView: View {

    let height: CGFloat
    let action: () -> Void

    var body: some View {
        VStack {
            Button("Action", action: action)
            Spacer().frame(height: height)
        }
    }
}

We make sure the control is always visible thanks to the translation parameter:

@State var height: CGFloat = 0.0

var body: some View {
    ZStack {
        Color.blue
        ControlView(height: height, action: {})
    }
    .dynamicOverlay(Color.red)
    .dynamicOverlayBehavior(myOverlayBehavior)
}

var myOverlayBehavior: some DynamicOverlayBehavior {
    MagneticNotchOverlayBehavior<Notch> { ... }
    .onTranslation { translation in
        height = translation.height
    }
}

You can also be notified when a notch is reached using a binding:

@State var notch: Notch = .min

var body: some View {
    Color.blue
        .dynamicOverlay(Text("\(notch)"))
        .dynamicOverlayBehavior(myOverlayBehavior)
}

var myOverlayBehavior: some DynamicOverlayBehavior {
    MagneticNotchOverlayBehavior<Notch> { ... }
    .notchChange($notch)
}

Moving the overlay

You can move explicitly the overlay using a notch binding.

@State var notch: Notch = .min

var body: some View {
    ZStack {
        Color.green
        Button("Move to top") {
            notch = .max
        }
    }
    .dynamicOverlay(Color.red)
    .dynamicOverlayBehavior(myOverlayBehavior)
}

var myOverlayBehavior: some DynamicOverlayBehavior {
    MagneticNotchOverlayBehavior<Notch> { ... }
    .notchChange($notch)
}

Wrap the change in an animation block to animate the change.

Button("Move to top") {
    withAnimation {
        notch = .max
    }
}

Disabling notches

When a notch is disabled, the overlay will ignore it. Here we block the overlay in its min position:

@State var notch: Notch = .max

var myOverlayBehavior: some DynamicOverlayBehavior {
    MagneticNotchOverlayBehavior<Notch> { ... }
    .notchChange($notch)
    .disable(.max, notch == .min)
}

Under the hood

DynamicOverlay is built on top of OverlayContainer. If you need more control, consider using it or open an issue.

Installation

DynamicOverlay is available through CocoaPods. To install it, simply add the following line to your Podfile:

Cocoapods

pod 'DynamicOverlay'

Carthage

Add the following to your Cartfile:

github "https://github.com/fabernovel/DynamicOverlay"

Swift Package Manager

DynamicOverlay can be installed as a Swift Package with Xcode 11 or higher. To install it, add a package using Xcode or a dependency to your Package.swift file:

.package(url: "https://github.com/fabernovel/DynamicOverlay.git")

Release

  • Create a release branch for the new version (release/#version#)
  • Update the CHANGELOG.md (Be sure to spell your release version correctly)
  • Push your release branch
  • Run the release workflow from your release branch

Author

@gaetanzanella, [email protected]

License

DynamicOverlay is available under the MIT license. See the LICENSE file for more info.

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].