An open API service indexing awesome lists of open source software.

https://github.com/aakarsh-verma/swiftuilayouts

Swift Package providing a collection of reusable SwiftUI layouts
https://github.com/aakarsh-verma/swiftuilayouts

ios layout-engine spm swiftui xcode

Last synced: 4 months ago
JSON representation

Swift Package providing a collection of reusable SwiftUI layouts

Awesome Lists containing this project

README

          

# SwiftUILayouts

SwiftUILayouts is a Swift Package providing a collection of reusable SwiftUI layouts and UI components. It is designed for iOS developers who want to quickly build modern and customizable interfaces with minimal boilerplate. The package leverages **SwiftUI** and integrates with **[Kingfisher](https://github.com/onevcat/Kingfisher)** for efficient image loading and caching.

---

## Highlights

- πŸ“ **Reusable Layouts** – Predefined SwiftUI layouts for carousels, grids, and cards.
- 🎨 **Customizable Components** – Highly flexible with configuration models.
- πŸ–ΌοΈ **Image Handling** – Supports remote and local images via Kingfisher.
- πŸš€ **Swift Package Manager (SPM)** – Easy integration into your project.
- βœ… **Unit Tests Included** – Ensures reliability and easy extension. (TBAπŸ₯²)

---

## Requirements

- **iOS**: 17.0+
- **Swift**: 6.0+
- **Xcode**: 15.0+

---

## Installation

### Swift Package Manager

In Xcode:

1. Go to **File β†’ Add Packages...**
2. Enter the repository URL:

```bash
https://github.com/your-username/SwiftUILayouts.git
```

3. Select the latest version and add the package to your project.

---

## Usage

### Import the Package

```swift
import SwiftUILayouts
```

### Example: Carousel View

```swift
struct DemoView: View {
let images: [CustomImageModel] = [
CustomImageModel(for: "https://picsum.photos/200"),
CustomImageModel(for: "https://picsum.photos/300"),
CustomImageModel(for: "mylocalImage")
]

var body: some View {
StackCarouselView(items: images, currentIndex: .constant(0)) { item in
CustomImageView(imageModel: item)
.clipShape(RoundedRectangle(cornerRadius: 12))
.shadow(radius: 5)
}
.frame(height: 300)
}
}
```

### Example: Custom Configurations

```swift
struct ConfiguredCarousel: View {
@State private var index = 0

var body: some View {
StackCarouselView(
items: Array(1...5),
config: SLStackCarouselModel(
cardWidthRatio: 0.8,
cardSizeDifferenceRatio: 0.05,
cardOffsetDifference: 20,
visibleCardIndexDifference: 3,
showSelected: true
),
currentIndex: $index
) { number in
Text("Item \(number)")
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.blue.opacity(0.7))
.cornerRadius(12)
}
.frame(height: 250)
}
}
```

---

## Project Structure

```code
SwiftUILayouts/
β”œβ”€β”€ Package.swift
β”œβ”€β”€ Sources/
β”‚ β”œβ”€β”€Interactions/
β”‚ β”œβ”€β”€ Models/
β”‚ β”œβ”€β”€ SwiftUILayouts/
β”‚ β”œβ”€β”€ Views/
| └──Components/
└── Tests/
└── SwiftUILayoutsTests/
```

- **Sources/** – Core components and layouts.
- **Tests/SwiftUILayoutsTests** – Unit tests for reliability.

---

## Dependencies

- [Kingfisher](https://github.com/onevcat/Kingfisher) – A powerful Swift library for downloading and caching images from the web.

---

## Features Index [Screen shots TBA]

### Layouts

1. Ambient Carousel Layout
2. Cover Carousel Layout
3. Grid Layout
4. Parallax Carousel Layout
5. Stack Carousel Layout

### Interactions

1. Pinch Pan Zoom

### Components

1. Image View

## Contributing

Contributions are welcome! πŸŽ‰
If you’d like to fix bugs or add new features:

1. Fork the repo
2. Create a feature branch: `git checkout -b feature/my-feature`
3. Commit your changes: `git commit -m "Add my feature"`
4. Push and open a PR

---

## License

This project is licensed under the **MIT License**.
See [LICENSE](https://choosealicense.com/licenses/mit/) for details.