Coder Social home page Coder Social logo

scrolledgecontrol's Introduction

ScrollEdgeControl

Replacement of UIRefreshControl, and more functions.

Overview

ScrollEdgeControl is a UI component that is similar to UIRefreshControl. but it pulls up to the even further abstracted component.

ScrollEdgeControl can attach to every edge in a scroll view. For instance, pulling to down, up, left, right to trigger something activity such as refreshing. (pull-to-activate)

It supports also disabling pull-to-activate, it would be useful in case of displaying as a loading indicator at bottom of the list.

The content on this control supports display any view you want.

Showcase

Vertical

Top Bottom

Horizontal

Left Right

More patterns

pull to refresh and additional loadings

Installation

Cocoapods

Including custom activity indicator

pod "ScrollEdgeControl"

If you need only core component

pod "ScrollEdgeControl/Core"

SwiftPM

dependencies: [
    .package(url: "https://github.com/muukii/ScrollEdgeControl.git", exact: "<VERSION>")
]

How to use

Setting up

let scrollEdgeControl = ScrollEdgeControl(
  edge: .top, // ✅ a target edge to add this control
  configuration: .init(),  // ✅ customizing behavior of this control
  activityIndicatorView: ScrollEdgeActivityIndicatorView(color: .black) // ✅ Adding your own component to display on this control
)
let scrollableView: UIScrollView // ✅ could be `UIScrollView`, `UITableView`, `UICollectionView`

scrollableView.addSubview(scrollEdgeControl) // ✅ Could add multiple controls for each edge

Handling

scrollEdgeControl.handlers.onDidActivate = { instance in

  ...

  // after activity completed
  instance.setActivityState(.inactive, animated: true)
}

Customizing the content

ScrollEdgeControl supports to display any content you want by following protocol.
Which means you can create fully customized design to display the activity.

protocol ScrollEdgeActivityIndicatorViewType
class YourContent: ScrollEdgeActivityIndicatorViewType {

  func update(withState state: ScrollEdgeControl.ActivatingState) {
    // Needs implementation
  }
}
let scrollEdgeControl: ScrollEdgeControl

let yourContent: YourContent

scrollEdgeControl.setActivityIndicatorView(yourContent)

Behind the scenes

Creating a component such as UIRefreshControl is quite hard.
Observing scroll, layout, updating content-inset.
While we were inspecting UIRefreshControl, we noticed UIScrollView's content-inset return 0 when it's refreshing. but adjusted-content-inset presents actual value in displaying.
(for example, content-inset-top: 0, adjusted-content-inset-top: 50)

So UIRefreshControl works internally to prevent spreading side-effect by changing content-inset.
We need this trick to create our own custom control for UIScrollView.

In the end, we decided to get this done with method-swizzling.
Swapping content-inset getter setter, managing local content-inset, and then we return the value to outside including adding, subtracting actual content-inset and local content-inset.

Why uses Advance in dependency

Advance helps animation in the scroll view.

It is a library to run animations with fully computable values using CADisplayLink.

UIScrollView's animations are not in CoreAnimation.
Those are computed in CPU every frame. that's why we can handle it in the UIScrollView delegate.
We can update content offset with UIView animation, but sometimes it's going to be weird animation.
To solve it, using CADisplayLink, update values for each frame.

Refs:

Author

License

MIT

scrolledgecontrol's People

Contributors

bagusandinata avatar kaneshin avatar kenjitayama avatar muukii avatar takumatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scrolledgecontrol's Issues

Dependency not working - missing link to ScrollEdgeControl

Hey guys,
i have implemented your library with Swift PM. The problem i have is attached below. Even if i clean -> run again, it keeps giving compilation error. As I can see the classes are there and public access is, so it should work. I don't know what could be the problem. Thanks

Screenshot 2024-05-15 at 10 44 04
Screenshot 2024-05-15 at 10 44 13

Screenshot 2024-05-15 at 10 43 58

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.