|
1 |
| -# Scroller |
| 1 | +# **Scroller** |
| 2 | +You can animate in individual views based on scroll position. Developed with SwiftUI. This library supports iOS/macOS. |
| 3 | + |
| 4 | +[](https://developer.apple.com/macOS) |
| 5 | +[](https://developer.apple.com/iOS) |
| 6 | +[](https://developer.apple.com/macOS) |
| 7 | +[](https://www.instagram.com/dev.fabula) |
| 8 | +[](https://developer.apple.com/documentation/swift_packages/package/) |
| 9 | +[](https://opensource.org/licenses/MIT) |
| 10 | + |
| 11 | +## Screenshot |
| 12 | +<img src="Markdown/Scroller.gif"> |
| 13 | + |
| 14 | +## Usages |
| 15 | +1. Scroller |
| 16 | + ```swift |
| 17 | + Scroller(.vertical, value: $valueV) { |
| 18 | + ForEach(0...5, id: \.self) { index in |
| 19 | + GeometryReader { proxy in |
| 20 | + ScrollerVContent(value: proxy.scrollerValue(.vertical)) |
| 21 | + } |
| 22 | + } |
| 23 | + } lastContent: { |
| 24 | + Rectangle() |
| 25 | + .fill(Color.blue) |
| 26 | + .overlay(Text("LastView")) |
| 27 | + .foregroundColor(Color.white) |
| 28 | + } |
| 29 | + ``` |
| 30 | + |
| 31 | + |
| 32 | +3. Each view only needs to conform to the ScrollerContent protocol. |
| 33 | + ```swift |
| 34 | + struct ScrollerVContent: ScrollerContent { |
| 35 | + |
| 36 | + /// Bind each view's scroll-relative value. It is a value between 0 and 1. |
| 37 | + var value: CGFloat = 0 |
| 38 | + |
| 39 | + var body: some View { |
| 40 | + GeometryReader { proxy in |
| 41 | + ScrollerInfoView(axes: .vertical, value: value, proxy: proxy) |
| 42 | + .offset(y: proxy.size.height * value) |
| 43 | + .padding(10) |
| 44 | + Rectangle().fill(Color.blue) |
| 45 | + .frame(width: proxy.size.width * value, height: 5) |
| 46 | + .offset(y: proxy.size.height * value) |
| 47 | + } |
| 48 | + .background(Color.orange.opacity(1.0 - value)) |
| 49 | + } |
| 50 | + } |
| 51 | + ``` |
| 52 | + |
| 53 | +## Contact |
| 54 | +instagram : [@dev.fabula](https://www.instagram.com/dev.fabula) |
| 55 | +email : [dev.fabula@gmail.com](mailto:dev.fabula@gmail.com) |
| 56 | + |
| 57 | +## License |
| 58 | +Scroller is available under the MIT license. See the [LICENSE](LICENSE) file for more info. |
0 commit comments