Skip to content

Commit 72692e9

Browse files
authored
feat(ui): add fluent subview management methods (#46)
- Add `addSubview` and `addSubviews` with method chaining support. - Implement variadic and array-based `addSubviews` variants.
1 parent e7e8358 commit 72692e9

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Sources/FlexUI/Classes/Extensions/FlexUI+UIView.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,37 @@ public extension FlexUI where Component: UIView {
176176
component.setContentCompressionResistancePriority(priority, for: axis)
177177
return self
178178
}
179+
180+
/// Adds a view to the end of the receiver’s list of subviews.
181+
///
182+
/// - Parameter view: The view to be added. After being added, this view appears on top of any other subviews.
183+
/// - Returns: The current instance, allowing method chaining.
184+
@discardableResult
185+
@MainActor
186+
func addSubview(_ view: UIView) -> Self {
187+
component.addSubview(view)
188+
return self
189+
}
190+
191+
/// Adds an array of views to the end of the receiver’s list of subviews.
192+
///
193+
/// - Parameter views: An array of views to be added.
194+
/// - Returns: The current instance, allowing method chaining.
195+
@discardableResult
196+
@MainActor
197+
func addSubviews(_ views: [UIView]) -> Self {
198+
views.forEach { component.addSubview($0) }
199+
return self
200+
}
201+
202+
/// Adds multiple views as variadic parameters to the end of the receiver’s list of subviews.
203+
///
204+
/// - Parameter views: A variable number of views to be added.
205+
/// - Returns: The current instance, allowing method chaining.
206+
@discardableResult
207+
@MainActor
208+
func addSubviews(_ views: UIView...) -> Self {
209+
views.forEach { component.addSubview($0) }
210+
return self
211+
}
179212
}

0 commit comments

Comments
 (0)