Giter VIP home page Giter VIP logo

magnetic-scroll's Introduction

thmb-modified

MagneticScroll

A Library that adds a sticky behavior to the SwiftUI's ScrollView, while triggering a smooth haptic feedback as you scroll through the views.

Installation

Requires iOS 14.0+

MagneticScroll currently can only be installed through the Swift Package Manager.

Swift Package Manager
Add the Package URL:

https://github.com/Poppin-Technologies/magnetic-scroll.git

Showcase

⚛️ Regular Magnetic Scroll

As you scroll, when the ScrollView's velocity is lesser than MagneticScrollView's velocity, magnetic scroll automatically sticks to the predicted end location.

regular

✨ Manually changing the blocks

manual

🙌 Magnetic Scroll with .matchedGeometryEffect modifier

mached

🔥 MagneticCarousel

If you set the velocityThreshold to .infinity, MagneticScroll becomes a carousel.

carousel

Usage

MagneticScroll is designed to operate with a view called Block. For MagneticScroll to detect scroll changes, it requires your content to be wrapped within Block elements.

import SwiftUI
import MagneticScroll

struct ContentView: View {
  // If you were to set activeBlock to "second" or "first" manually, MagneticScroll would automatically scroll to the block with that id.
  @State private var activeBlock = "first"
  var body: some View {
    MagneticScrollView(activeBlock: $activeBlock) { organizer in
      Block(id: "first", height: 400, inActiveHeight: 300) { // All of these fields are optional, except the ID, but magnetic scroll works x5 better with constant heights.
        Text("Hello World")
      }
      Block(id: "second", height: 400, inActiveHeight: 300) {
        Text("Hello World")
      }
    }
  }
}

Methods

Here are the methods available for configuring the behavior of MagneticScrollView:

🖱️ changesActiveBlockOnTapGesture(_ value: Bool)

Sets whether the active block should be changed on a tap gesture.

🏁 velocityThreshold(_ threshold: Double)

Sets the velocity threshold for MagneticScrollView to react to scroll view velocity.

📳 triggersHapticFeedbackOnBlockChange(_ bool: Bool)

Sets whether haptic feedback should be triggered when the active block changes.

📳 triggersHapticFeedbackOnActiveBlockChange(_ bool: Bool)

Sets whether haptic feedback should be triggered when the active block changes.

📋 formStyle(_ bool:)

Sets whether the form style should be enabled or not.

⏳ scrollAnimationDuration(_ duration: Double)

Sets the scroll animation duration when changing the active block.

⌛ setTimeout(_ duration: Double)

Sets the timeout duration needed to change a block to another.

Organizer

MagneticScrollView gives an organizer to control the behavior of itself. Organizer contains a ScrollViewProxy so if you want to control the ScrollView itself, you can use that.

🪐 activate(with: Block.ID)

Activates a block with given ID. But doesn't scroll to it

👇🏻 scrollTo(id: Block.ID, anchor: UnitPoint)

Scrolls and activates a block with given id and anchor

👆🏻 scrollToCurrentOffset()

Scrolls to the nearest block with the current offset of the MagneticScrollView.

Apps Using MagneticScroll

Poppin - The Party Platform

logoppin

poppin

magnetic-scroll's People

Contributors

grandsir avatar benlmyers avatar alexeloswift avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.