Swiftpack.co - kazuhiro4949/SwiftUIReplicator as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by kazuhiro4949.
kazuhiro4949/SwiftUIReplicator 1.0.2
SwiftUIReplicator is a pure SwiftUI library which replicates a specified number of views with varying geometric, temporal, and color transformations
⭐️ 5
🕓 32 weeks ago
iOS macOS
.package(url: "https://github.com/kazuhiro4949/SwiftUIReplicator.git", from: "1.0.2")

SwiftUIReplicator

SwiftUIReplicator is a container view that creates a specified number of view copies with varying geometric, temporal, and color transformations. The specification refers to CAReplicatorLayer.

You can copy a view with Replicator specifying transformation rules.

Feature

  • ☑ Pure SwiftUI library
  • ☑ CAReplicatorLayer like container view
  • ☑ UIKit like loading indicator

Requirements

  • iOS 14.0+
  • Xcode 12.0+
  • Swift 5.3

Installation

SwiftUIReplicator supports only SwiftPM.

Swift Package Manager

Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. It is in early development, but Alamofire does support its use on supported platforms.

Once you have your Swift package set up, adding SwiftUIReplicator as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/kazuhiro4949/SwiftUIReplicator.git", .upToNextMajor(from: "1.0.0"))
]

Usage

You can use a this library to build complex layouts based on a single source view that is replicated with transformation rules that can affect the position, rotation color, and time.

Replicator

Replicator is the most important in SwiftUIReplicator.

The following code shows a simple example: a red square is added to a replicator view with an instance count of 5. The position of each replicated instance is offset along the x axis so that it appears to the right of the previous instance. The blue and green color channels are offset so that their values reach 0 at the final instance.

Replicator(
    Rectangle()                                   // repeated view
        .fill(Color.white)
        .frame(width: 40, height: 40)
)
.repeatCount(5)                                  // how many views
.repeatTransform(.init(translationX: 42, y: 0))  // repeats the transformation
.instanceBlueOffset(-0.2)                        // the offset added to the blue component of the color
.instanceGreenOffset(-0.2)                       // the offset added to the green component of the color
.offset(x: -84)

The result of the code above is a row of five squares, with colors graduating from white to red, as shown in the figure.

UseCase: Loading Indicator

SwiftUIReplicator has many usecases. One of them is "Loading Indicator".

SwiftUI doesn't have UIActivityIndicator like view. Instead, SwiftUIReplicator provides some loading indicators.

classical circle bounce circle rotation circle scaling rectangle scaling
sample_5 sample_4 sample6 sample7 sample8

If you want to use a classical indicator, set ActivityIndicator with .classicalLarge in body.

struct ContentView: View {
    var body: some View {
        ActivityIndicator(style: .classicalLarge)
            .accentColor(.gray)
    }
}

License

Copyright (c) 2021 Kazuhiro Hayashi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

GitHub

link
Stars: 5
Last commit: 32 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

add available
32 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics