Top Related Projects
Yoga is an embeddable layout engine targeting web standards.
Epoxy is an Android library for building complex screens in a RecyclerView
A powerful image downloading and caching library for Android
Reactive Programming in Swift
Realm is a mobile database: a replacement for Core Data & SQLite
A React-inspired view framework for iOS.
Quick Overview
LayoutKit is a fast and efficient layout framework for iOS, macOS, and tvOS applications. It's designed to be an alternative to Auto Layout, offering improved performance and flexibility for complex user interfaces. LayoutKit allows developers to create layouts programmatically with a simple and intuitive API.
Pros
- High performance: Significantly faster than Auto Layout, especially for complex layouts
- Flexible and customizable: Supports a wide range of layout types and custom layouts
- Thread-safe: Can perform layout calculations on background threads
- Testable: Includes tools for unit testing layouts
Cons
- Learning curve: Requires learning a new API and approach to layout
- Less visual editing: No built-in Interface Builder support like Auto Layout
- Limited community: Smaller ecosystem compared to Auto Layout
- Maintenance: Last updated in 2019, which may indicate less active development
Code Examples
- Creating a simple vertical stack layout:
let layout = StackLayout(
axis: .vertical,
spacing: 10,
sublayouts: [
LabelLayout(text: "Hello"),
LabelLayout(text: "World")
]
)
- Implementing a horizontal layout with flexible spacing:
let layout = HorizontalLayout(
sublayouts: [
SizeLayout<UIView>(width: 100, height: 50),
InsetLayout(insets: UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10),
sublayout: LabelLayout(text: "Center")),
SizeLayout<UIView>(width: 100, height: 50)
]
)
- Creating a custom layout:
class MyCustomLayout: Layout {
func measurement(within maxSize: CGSize) -> LayoutMeasurement {
// Custom measurement logic
}
func arrangement(within rect: CGRect, measurement: LayoutMeasurement) -> LayoutArrangement {
// Custom arrangement logic
}
}
Getting Started
To use LayoutKit in your project:
- Add LayoutKit to your project using CocoaPods, Carthage, or Swift Package Manager.
- Import LayoutKit in your Swift file:
import LayoutKit
- Create a layout and apply it to a view:
let layout = StackLayout(
axis: .vertical,
spacing: 10,
sublayouts: [
LabelLayout(text: "Hello LayoutKit"),
SizeLayout<UIImageView>(width: 200, height: 200)
]
)
let rootView = UIView(frame: view.bounds)
let arrangement = layout.arrangement(width: view.bounds.width, height: nil)
arrangement.makeViews(in: rootView)
view.addSubview(rootView)
This example creates a vertical stack with a label and an image view, then applies it to a root view and adds it to the main view.
Competitor Comparisons
Yoga is an embeddable layout engine targeting web standards.
Pros of Yoga
- Cross-platform support (iOS, Android, Web)
- More active development and community support
- Flexible layout system with support for Flexbox
Cons of Yoga
- Steeper learning curve due to its more complex API
- Requires integration with native code for some platforms
Code Comparison
LayoutKit:
let layout = StackLayout(
axis: .vertical,
spacing: 10,
sublayouts: [
LabelLayout(text: "Hello"),
LabelLayout(text: "World")
]
)
Yoga:
const root = Yoga.Node.create();
root.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
root.setWidth(100);
root.setHeight(100);
const child1 = Yoga.Node.create();
child1.setWidth(50);
child1.setHeight(50);
root.insertChild(child1, 0);
Summary
Yoga offers cross-platform support and a more flexible layout system based on Flexbox, making it suitable for complex layouts across different platforms. However, it has a steeper learning curve and may require native code integration.
LayoutKit, while more straightforward to use, is primarily focused on iOS and has a simpler API. It may be a better choice for iOS-specific projects or developers looking for a more intuitive layout system.
The code comparison shows that LayoutKit uses a more declarative approach, while Yoga requires more explicit node creation and property setting.
Epoxy is an Android library for building complex screens in a RecyclerView
Pros of Epoxy
- More active development and community support
- Broader feature set, including support for RecyclerView, ViewPager, and Carousel
- Built-in diffing for efficient updates
Cons of Epoxy
- Steeper learning curve due to more complex API
- Requires more boilerplate code for setup
- Potentially higher memory usage for complex layouts
Code Comparison
LayoutKit example:
let layout = InsetLayout(
insets: UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4),
sublayout: LabelLayout(text: "Hello, World!")
)
Epoxy example:
@EpoxyModelClass
abstract class HelloWorldModel : EpoxyModelWithHolder<HelloWorldHolder>() {
@EpoxyAttribute lateinit var text: String
override fun bind(holder: HelloWorldHolder) {
holder.textView.text = text
}
}
Key Differences
- LayoutKit focuses on declarative layout creation, while Epoxy emphasizes building complex RecyclerView layouts
- LayoutKit is Swift-based for iOS, whereas Epoxy is Kotlin-based for Android
- Epoxy provides more granular control over item updates and animations
- LayoutKit offers better performance for static layouts, while Epoxy excels in dynamic list scenarios
Both libraries aim to simplify UI development, but they target different platforms and use cases. Choose based on your specific project requirements and platform constraints.
A powerful image downloading and caching library for Android
Pros of Picasso
- Widely adopted and well-maintained image loading library for Android
- Supports image transformations and caching out of the box
- Extensive documentation and community support
Cons of Picasso
- Limited to image loading and manipulation
- Android-specific, not suitable for cross-platform development
- May have a steeper learning curve for complex use cases
Code Comparison
LayoutKit (Swift):
let layout = StackLayout(
axis: .vertical,
spacing: 10,
sublayouts: [
LabelLayout(text: "Hello"),
ImageLayout(image: UIImage(named: "example"))
]
)
Picasso (Java):
Picasso.get()
.load("https://example.com/image.jpg")
.resize(200, 200)
.centerCrop()
.into(imageView);
Key Differences
- LayoutKit focuses on efficient UI layout for iOS, while Picasso specializes in image loading for Android
- LayoutKit provides a declarative approach to UI layout, whereas Picasso offers a fluent API for image manipulation
- LayoutKit is more versatile for general UI construction, while Picasso excels in image-specific tasks
Use Cases
- Choose LayoutKit for building complex, performant UI layouts in iOS applications
- Opt for Picasso when working on Android apps that require efficient image loading and basic transformations
Reactive Programming in Swift
Pros of RxSwift
- Comprehensive reactive programming framework for Swift
- Large community and extensive documentation
- Supports complex asynchronous operations and event handling
Cons of RxSwift
- Steeper learning curve for developers new to reactive programming
- Can lead to increased code complexity for simple tasks
- Potential performance overhead for small-scale applications
Code Comparison
LayoutKit example:
let layout = StackLayout(
axis: .vertical,
spacing: 10,
sublayouts: [
LabelLayout(text: "Hello"),
ButtonLayout(type: .system, title: "Click me")
]
)
RxSwift example:
Observable.combineLatest(nameObservable, ageObservable) { name, age in
return "Name: \(name), Age: \(age)"
}
.bind(to: resultLabel.rx.text)
.disposed(by: disposeBag)
Summary
LayoutKit focuses on efficient UI layout creation, while RxSwift provides a comprehensive reactive programming framework. LayoutKit offers simplicity and performance for UI-centric tasks, whereas RxSwift excels in managing complex asynchronous operations and data flows. The choice between the two depends on the specific requirements of the project and the development team's familiarity with reactive programming concepts.
Realm is a mobile database: a replacement for Core Data & SQLite
Pros of Realm Swift
- Robust database solution with advanced querying capabilities
- Cross-platform support (iOS, Android, and more)
- Real-time synchronization and offline-first architecture
Cons of Realm Swift
- Steeper learning curve compared to LayoutKit
- Larger footprint and potential performance overhead for simple use cases
- Less flexibility in terms of data model changes
Code Comparison
LayoutKit (UI layout):
let layout = StackLayout(
axis: .vertical,
spacing: 10,
sublayouts: [
LabelLayout(text: "Hello"),
ButtonLayout(type: .system, title: "Click me")
]
)
Realm Swift (database operations):
let realm = try! Realm()
try! realm.write {
let person = Person()
person.name = "John"
realm.add(person)
}
Summary
LayoutKit focuses on efficient UI layout, while Realm Swift is a comprehensive database solution. LayoutKit is simpler and more lightweight, ideal for UI-centric projects. Realm Swift offers powerful data management features but may be overkill for basic layouts. Choose based on your project's primary needs: UI layout efficiency (LayoutKit) or robust data handling (Realm Swift).
A React-inspired view framework for iOS.
Pros of ComponentKit
- More mature and widely adopted, with a larger community and extensive documentation
- Offers a more comprehensive UI framework with advanced features like state management and animations
- Provides better performance optimization for complex UIs with many components
Cons of ComponentKit
- Steeper learning curve due to its more complex architecture and Objective-C++ implementation
- Requires more boilerplate code for simple layouts compared to LayoutKit
- Less flexible for projects that don't align with ComponentKit's opinionated approach
Code Comparison
LayoutKit:
let layout = StackLayout(
axis: .vertical,
spacing: 10,
sublayouts: [
LabelLayout(text: "Hello"),
LabelLayout(text: "World")
]
)
ComponentKit:
CKComponentScope scope(self);
CKStackLayoutComponent *component =
[CKStackLayoutComponent
newWithView:{[UIView class]}
size:{}
style:{.direction = CKStackLayoutDirectionVertical, .spacing = 10}
children:{
{[CKLabelComponent newWithLabelAttributes:{.text = @"Hello"}]},
{[CKLabelComponent newWithLabelAttributes:{.text = @"World"}]}
}];
Both frameworks aim to simplify UI layout, but ComponentKit offers more advanced features at the cost of increased complexity, while LayoutKit focuses on simplicity and ease of use for basic layouts.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
ð¨ UNMAINTAINED ð¨
This project is no longer used by LinkedIn and is currently unmaintained.
LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
Motivation
LinkedIn created LayoutKit because we have found that Auto Layout is not performant enough for complicated view hierarchies in scrollable views. For more background, read the blog post.
Benefits
LayoutKit has many benefits over using Auto Layout:
- Fast: LayoutKit is as fast as manual layout code and is significantly faster than Auto Layout.
- Asynchronous: Layouts can be computed in a background thread so user interactions are not interrupted.
- Declarative: Layouts are declared with immutable data structures. This makes layout code easier to develop, document, code review, test, debug, profile, and maintain.
- Cacheable: Layout results are immutable data structures so they can be precomputed in the background and cached to increase user perceived performance.
LayoutKit also provides benefits that make it as easy to use as Auto Layout:
- UIKit friendly: LayoutKit produces UIViews and also provides an adapter that makes it easy to use with UITableView and UICollectionView.
- Internationalization: LayoutKit automatically adjusts view frames for right-to-left languages.
- Swift: LayoutKit can be used in Swift applications and playgrounds.
- Tested and production ready: LayoutKit is covered by unit tests and is being used inside of recent versions of the LinkedIn and LinkedIn Job Search iOS apps.
- Open-source: Not a black box like Auto Layout.
- Apache License (v2): Your lawyers will be happy that there are no patent shenanigans.
Hello world
let image = SizeLayout<UIImageView>(width: 50, height: 50, config: { imageView in
imageView.image = UIImage(named: "earth.jpg")
})
let label = LabelLayout(text: "Hello World!", alignment: .center)
let stack = StackLayout(
axis: .horizontal,
spacing: 4,
sublayouts: [image, label])
let insets = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 8)
let helloWorld = InsetLayout(insets: insets, sublayout: stack)
helloWorld.arrangement().makeViews(in: rootView)
Limitations
We have found LayoutKit to be a useful tool, but you should be aware of what it is not.
- LayoutKit is not a constraint based layout system. If you wish to express a constraint between views, then those views need to be children of a single layout that implements code to enforce that constraint.
- LayoutKit is not flexbox, but you may find similarities.
Installation
LayoutKit can be installed with CocoaPods or Carthage.
CocoaPods
Add this to your Podspec:
pod 'LayoutKit'
Then run pod install
.
Carthage
Add this to your Cartfile:
github "linkedin/LayoutKit"
Then run carthage update
.
Documentation
Now you are ready to start building UI.
Top Related Projects
Yoga is an embeddable layout engine targeting web standards.
Epoxy is an Android library for building complex screens in a RecyclerView
A powerful image downloading and caching library for Android
Reactive Programming in Swift
Realm is a mobile database: a replacement for Core Data & SQLite
A React-inspired view framework for iOS.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot