diff --git a/Sources/ObjCSupport/Builders/LOKButtonLayoutBuilder.h b/Sources/ObjCSupport/Builders/LOKButtonLayoutBuilder.h index 49cf3232..3fca57cc 100644 --- a/Sources/ObjCSupport/Builders/LOKButtonLayoutBuilder.h +++ b/Sources/ObjCSupport/Builders/LOKButtonLayoutBuilder.h @@ -19,25 +19,76 @@ typedef NS_CLOSED_ENUM(NSInteger, LOKButtonLayoutType) { LOKButtonLayoutTypeContactAdd }; +/** + A layout builder for @c LOKButtonLayout. + */ @interface LOKButtonLayoutBuilder: NSObject +/** + Creates a @c LOKButtonLayoutBuilder with the given title. + @param title The button title. + */ - (nonnull instancetype)initWithTitle:(nullable NSString *)title; + (nonnull instancetype)withTitle:(nullable NSString *)title; +/** + @c LOKButtonLayoutBuilder block for setting the button type of the @c LOKButtonLayout. + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^type)(LOKButtonLayoutType); + +/** + @c LOKButtonLayoutBuilder block for setting title font of the @c LOKButtonLayout. + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^font)(UIFont * _Nullable); + +/** + @c LOKButtonLayoutBuilder block for setting button image of the @c LOKButtonLayout. + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^image)(UIImage * _Nullable); + +/** + @c LOKButtonLayoutBuilder block for setting image size of the @c LOKButtonLayout. + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^imageSize)(CGSize); + +/** + @c LOKButtonLayoutBuilder block for setting edge inset of the @c LOKButtonLayout. + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^contentEdgeInsets)(NSValue * _Nullable); +/** + @c LOKButtonLayoutBuilder block for defining how this layout is positioned inside its parent layout. + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^alignment)(LOKAlignment * _Nullable); + +/** + @c LOKButtonLayoutBuilder block for setting flexibility of the @c LOKButtonLayout. + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^flexibility)(LOKFlexibility * _Nullable); + +/** + @c LOKButtonLayoutBuilder block for setting the viewReuseId used by LayoutKit. + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^viewReuseId)(NSString * _Nullable); + +/** + @c LOKButtonLayoutBuilder block for setting the view class of the @c LOKButtonLayout (should be @c UIButton or subclass). + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^viewClass)(Class _Nullable); +/** + Layoutkit configuration block called with the created @c UIButton (or subclass). + */ @property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^config)( void(^ _Nullable)(UIButton *_Nonnull)); + +/** + @c LOKButtonLayoutBuilder block for setting edge insets (positive) of the @c LOKButtonLayout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^insets)(LOKEdgeInsets); +/** + Calling this builds and returns the @c LOKButtonLayout + */ @property (nonatomic, nonnull, readonly) LOKButtonLayout *layout; @end diff --git a/Sources/ObjCSupport/Builders/LOKInsetLayoutBuilder.h b/Sources/ObjCSupport/Builders/LOKInsetLayoutBuilder.h index a499a8f1..d6ac742b 100644 --- a/Sources/ObjCSupport/Builders/LOKInsetLayoutBuilder.h +++ b/Sources/ObjCSupport/Builders/LOKInsetLayoutBuilder.h @@ -11,20 +11,52 @@ #import "LOKLayoutBuilder.h" @class LOKInsetLayout; - +/** + A layout builder for @c LOKInsetLayout. + */ @interface LOKInsetLayoutBuilder: NSObject +/** + Creates a @c LOKInsetLayoutBuilder with the given insets and sublayout. + @param insets The @c LOKEdgeInsets for layout. + @param sublayout The layout placed inside the @c LOKInsetLayout. + */ - (nonnull instancetype)initWithInsets:(LOKEdgeInsets)insets around:(nonnull id)sublayout; + (nonnull instancetype)withInsets:(LOKEdgeInsets)insets around:(nonnull id)sublayout; +/** + @c LOKInsetLayoutBuilder block for defining how this layout is positioned inside its parent layout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^alignment)(LOKAlignment * _Nullable); + +/** + @c LOKInsetLayoutBuilder block for setting flexibility of the @c LOKInsetLayout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^flexibility)(LOKFlexibility * _Nullable); + +/** + @c LOKInsetLayoutBuilder block for setting the viewReuseId used by LayoutKit. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^viewReuseId)(NSString * _Nullable); + +/** + @c LOKInsetLayoutBuilder block for setting the view class for the @c LOKInsetLayout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^viewClass)(Class _Nullable); +/** + Layoutkit configuration block called with created @c LOKView. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^config)( void(^ _Nullable)(LOKView *_Nonnull)); + +/** + @c LOKInsetLayoutBuilder block for setting edge inset for the @c LOKInsetLayout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^insets)(LOKEdgeInsets); +/** + Calling this builds and returns the @c LOKInsetLayout + */ @property (nonatomic, nonnull, readonly) LOKInsetLayout *layout; @end diff --git a/Sources/ObjCSupport/Builders/LOKLabelLayoutBuilder.h b/Sources/ObjCSupport/Builders/LOKLabelLayoutBuilder.h index 3f1b42aa..b0f9b9b3 100644 --- a/Sources/ObjCSupport/Builders/LOKLabelLayoutBuilder.h +++ b/Sources/ObjCSupport/Builders/LOKLabelLayoutBuilder.h @@ -12,26 +12,74 @@ @class LOKLabelLayout; +/** + Layout builder for a @c LOKLabelLayout. + */ @interface LOKLabelLayoutBuilder: NSObject +/** + Creates a @c LOKLabelLayoutBuilder with the given string. + @param string The string to be used for label. + */ - (nonnull instancetype)initWithString:(nullable NSString *)string; + +/** + Creates a @c LOKLabelLayoutBuilder with the given attributed string. + @param attributedString The attributed string to set as the attributedText. + */ - (nonnull instancetype)initWithAttributedString:(nullable NSAttributedString *)attributedString; + (nonnull instancetype)withString:(nullable NSString *)string; + (nonnull instancetype)withAttributedString:(nullable NSAttributedString *)attributedString; +/** + @c LOKLabelLayoutBuilder block for setting font of the @c LOKLabelLayout. + */ @property (nonatomic, nonnull, readonly) LOKLabelLayoutBuilder * _Nonnull(^font)(UIFont * _Nullable); + +/** + @c LOKLabelLayoutBuilder block for setting the number of lines the label can have. + */ @property (nonatomic, nonnull, readonly) LOKLabelLayoutBuilder * _Nonnull(^numberOfLines)(NSInteger); + +/** + @c LOKLabelLayoutBuilder block for setting line height of the label. + */ @property (nonatomic, nonnull, readonly) LOKLabelLayoutBuilder * _Nonnull(^lineHeight)(CGFloat); +/** + @c LOKLabelLayoutBuilder block for defining how this layout is positioned inside its parent layout. + */ @property (nonatomic, nonnull, readonly) LOKLabelLayoutBuilder * _Nonnull(^alignment)(LOKAlignment * _Nullable); + +/** + @c LOKLabelLayoutBuilder block for setting flexibility of the @c LOKLabelLayout. + */ @property (nonatomic, nonnull, readonly) LOKLabelLayoutBuilder * _Nonnull(^flexibility)(LOKFlexibility * _Nullable); + +/** + @c LOKLabelLayoutBuilder block for setting the viewReuseId used by LayoutKit. + */ @property (nonatomic, nonnull, readonly) LOKLabelLayoutBuilder * _Nonnull(^viewReuseId)(NSString * _Nullable); + +/** + @c LOKLabelLayoutBuilder block for setting the view class of the @c LOKLabelLayout (should be UILabel or subclass). + */ @property (nonatomic, nonnull, readonly) LOKLabelLayoutBuilder * _Nonnull(^viewClass)(Class _Nullable); +/** + Layoutkit configuration block called with the created @c UILabel (or subclass). + */ @property (nonatomic, nonnull, readonly) LOKLabelLayoutBuilder * _Nonnull(^config)( void(^ _Nullable)(UILabel *_Nonnull)); + +/** + @c LOKLabelLayoutBuilder block for setting edge insets (positive) for the layout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^insets)(LOKEdgeInsets); +/** + Calling this builds and returns the @c LOKLabelLayout + */ @property (nonatomic, nonnull, readonly) LOKLabelLayout *layout; @end diff --git a/Sources/ObjCSupport/Builders/LOKOverlayLayoutBuilder.h b/Sources/ObjCSupport/Builders/LOKOverlayLayoutBuilder.h index 25bd2af2..80177a2e 100644 --- a/Sources/ObjCSupport/Builders/LOKOverlayLayoutBuilder.h +++ b/Sources/ObjCSupport/Builders/LOKOverlayLayoutBuilder.h @@ -12,22 +12,61 @@ @class LOKOverlayLayout; +/** + Builder for @c LOKOverlayLayout class. + */ @interface LOKOverlayLayoutBuilder: NSObject +/** + Creates a @c LOKOverlayLayoutBuilder with the given collection of primary layouts. + @param primaryLayouts The collection of layouts used inside the @c LOKOverlayLayout. + */ - (nonnull instancetype)initWithPrimaryLayouts:(nonnull NSArray< id > *)primaryLayouts; + (nonnull instancetype)withPrimaryLayouts:(nonnull NSArray< id > *)primaryLayouts; +/** + The layouts to put in front of the primary layout. They will be at most as large as the primary layout. + */ @property (nonatomic, nonnull, readonly) LOKOverlayLayoutBuilder * _Nonnull(^overlay)(NSArray< id > * _Nullable); + +/** + The layouts to put behind the primary layout. They will be at most as large as the primary layout. + */ @property (nonatomic, nonnull, readonly) LOKOverlayLayoutBuilder * _Nonnull(^background)(NSArray< id > * _Nullable); +/** + @c LOKOverlayLayoutBuilder block for defining how this layout is positioned inside its parent layout. + */ @property (nonatomic, nonnull, readonly) LOKOverlayLayoutBuilder * _Nonnull(^alignment)(LOKAlignment * _Nullable); + +/** + @c LOKOverlayLayoutBuilder block for setting flexibility of the @c LOKOverlayLayout. + */ @property (nonatomic, nonnull, readonly) LOKOverlayLayoutBuilder * _Nonnull(^flexibility)(LOKFlexibility * _Nullable); + +/** + @c LOKOverlayLayoutBuilder block for setting the viewReuseId used by LayoutKit. + */ @property (nonatomic, nonnull, readonly) LOKOverlayLayoutBuilder * _Nonnull(^viewReuseId)(NSString * _Nullable); + +/** + @c LOKOverlayLayoutBuilder block for setting the view class of the @c LOKOverlayLayout. + */ @property (nonatomic, nonnull, readonly) LOKOverlayLayoutBuilder * _Nonnull(^viewClass)(Class _Nullable); +/** + Layoutkit configuration block called with the created @c LOKView. + */ @property (nonatomic, nonnull, readonly) LOKOverlayLayoutBuilder * _Nonnull(^config)( void(^ _Nullable)(LOKView *_Nonnull)); + +/** + @c LOKOverlayLayoutBuilder block for setting edge inset (positive) for the layout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^insets)(LOKEdgeInsets); +/** + Calling this builds and returns the @c LOKOverlayLayout + */ @property (nonatomic, nonnull, readonly) LOKOverlayLayout *layout; @end diff --git a/Sources/ObjCSupport/Builders/LOKSizeLayoutBuilder.h b/Sources/ObjCSupport/Builders/LOKSizeLayoutBuilder.h index 58b74d15..d45171ce 100644 --- a/Sources/ObjCSupport/Builders/LOKSizeLayoutBuilder.h +++ b/Sources/ObjCSupport/Builders/LOKSizeLayoutBuilder.h @@ -9,27 +9,81 @@ #import "LOKLayoutBuilder.h" @class LOKSizeLayout; - +/** + A layout builder for @c LOKSizeLayout. + */ @interface LOKSizeLayoutBuilder: NSObject +/** + Creates a @c LOKSizeLayoutBuilder with the given sublayout. + @param sublayout The layout for which size layout is being created. + */ - (nonnull instancetype)initWithSublayout:(nullable id)sublayout; + (nonnull instancetype)withSublayout:(nullable id)sublayout; +/** + @c LOKSizeLayoutBuilder block for setting width of the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^width)(CGFloat); + +/** + @c LOKSizeLayoutBuilder block for setting height of the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^height)(CGFloat); + +/** + @c LOKSizeLayoutBuilder block for setting the minimum width of the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^minWidth)(CGFloat); + +/** + @c LOKSizeLayoutBuilder block for setting minimum height of the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^minHeight)(CGFloat); + +/** + @c LOKSizeLayoutBuilder block for setting maximum width of the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^maxWidth)(CGFloat); + +/** + @c LOKSizeLayoutBuilder block for setting maximum height of the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^maxHeight)(CGFloat); +/** + @c LOKSizeLayoutBuilder block for defining how this layout is positioned inside its parent layout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^alignment)(LOKAlignment * _Nullable); + +/** + @c LOKSizeLayoutBuilder block for setting flexibility of the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^flexibility)(LOKFlexibility * _Nullable); + +/** + @c LOKSizeLayoutBuilder block for setting the viewReuseId used by LayoutKit. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^viewReuseId)(NSString * _Nullable); + +/** + @c LOKSizeLayoutBuilder block for setting the view class of the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^viewClass)(Class _Nullable); +/** + Layoutkit configuration block called with the created @c LOKView. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^config)( void(^ _Nullable)(LOKView *_Nonnull)); + +/** + @c LOKSizeLayoutBuilder block for setting edge inset (positive) for the layout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^insets)(LOKEdgeInsets); +/** + Calling this builds and returns the @c LOKSizeLayout. + */ @property (nonatomic, nonnull, readonly) LOKSizeLayout *layout; @end diff --git a/Sources/ObjCSupport/Builders/LOKStackLayoutBuilder.h b/Sources/ObjCSupport/Builders/LOKStackLayoutBuilder.h index b982fb0d..eeff69e8 100644 --- a/Sources/ObjCSupport/Builders/LOKStackLayoutBuilder.h +++ b/Sources/ObjCSupport/Builders/LOKStackLayoutBuilder.h @@ -8,6 +8,9 @@ #import "LOKLayoutBuilder.h" +/** + Specifies how excess space along the axis is allocated. + */ typedef NS_CLOSED_ENUM(NSInteger, LOKStackLayoutDistribution) { LOKStackLayoutDistributionDefault, LOKStackLayoutDistributionLeading, @@ -18,6 +21,9 @@ typedef NS_CLOSED_ENUM(NSInteger, LOKStackLayoutDistribution) { LOKStackLayoutDistributionFillFlexing }; +/** + Specifies a horizontal or vertical layout along which sublayouts are stacked. + */ typedef NS_CLOSED_ENUM(NSInteger, LOKAxis) { LOKAxisVertical, LOKAxisHorizontal @@ -25,23 +31,67 @@ typedef NS_CLOSED_ENUM(NSInteger, LOKAxis) { @class LOKStackLayout; +/** + A layout builder that builds @c LOKStackLayout using sublayouts along the specified axis. + */ @interface LOKStackLayoutBuilder: NSObject +/** + Creates a @c LOKStackLayoutBuilder with the given sublayouts. + @param sublayouts The array of layouts to be push in @c LOKStackLayout. + */ - (nonnull instancetype)initWithSublayouts:(nonnull NSArray< id > *)sublayouts; + (nonnull instancetype)withSublayouts:(nonnull NSArray< id > *)sublayouts; +/** + @c LOKStackLayoutBuilder block for setting the axis along which sublayouts are stacked. + */ @property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^axis)(LOKAxis); + +/** + The distance in points between adjacent edges of sublayouts along the @c LOKStackLayout axis. + For Distribution.EqualSpacing, this is the minimum spacing. For all other distributions it is the exact spacing. + */ @property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^spacing)(CGFloat); + +/** + @c LOKStackLayoutBuilder block for setting distribution of space along the @c LOKStackLayout's axis. + */ @property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^distribution)(LOKStackLayoutDistribution); +/** + @c LOKStackLayoutBuilder block for defining how this layout is positioned inside its parent layout. + */ @property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^alignment)(LOKAlignment * _Nullable); + +/** + @c LOKStackLayoutBuilder block for setting flexibility of the @c LOKStackLayout. + */ @property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^flexibility)(LOKFlexibility * _Nullable); + +/** + @c LOKStackLayoutBuilder block for setting the viewReuseId used by LayoutKit. + */ @property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^viewReuseId)(NSString * _Nullable); + +/** + @c LOKStackLayoutBuilder block for setting the view class of the @c LOKStackLayout. + */ @property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^viewClass)(Class _Nullable); +/** + Layoutkit configuration block called with the created @c LOKView. + */ @property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^config)( void(^ _Nullable)(LOKView *_Nonnull)); + +/** + @c LOKStackLayoutBuilder block for setting edge insets (positive) of the @c LOKStackLayout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^insets)(LOKEdgeInsets); +/** + Calling this builds and returns the @c LOKStackLayout. + */ @property (nonatomic, nonnull, readonly) LOKStackLayout *layout; @end diff --git a/Sources/ObjCSupport/Builders/LOKTextViewLayoutBuilder.h b/Sources/ObjCSupport/Builders/LOKTextViewLayoutBuilder.h index c10554cb..fd7ac6ed 100644 --- a/Sources/ObjCSupport/Builders/LOKTextViewLayoutBuilder.h +++ b/Sources/ObjCSupport/Builders/LOKTextViewLayoutBuilder.h @@ -9,27 +9,74 @@ #import "LOKLayoutBuilder.h" @class LOKTextViewLayout; - +/** + LayoutBuilder for @c LOKTextViewLayout. + */ @interface LOKTextViewLayoutBuilder: NSObject +/** + Creates a @c LOKTextViewLayoutBuilder with the given string. + @param string The string set to the underlying @c UITextView's text. + */ - (nonnull instancetype)initWithString:(nullable NSString *)string; + +/** + Creates a @c LOKTextViewLayoutBuilder with the given attributed string. + @param attributedString The attributed string set as the underlying @c UITextView's attributedText. + */ - (nonnull instancetype)initWithAttributedString:(nullable NSAttributedString *)attributedString; + (nonnull instancetype)withString:(nullable NSString *)string; + (nonnull instancetype)withAttributedString:(nullable NSAttributedString *)attributedString; +/** + @c LOKTextViewLayoutBuilder block for setting font of the @c LOKTextViewLayout. + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayoutBuilder * _Nonnull(^font)(UIFont * _Nullable); + +/** + @c LOKTextViewLayoutBuilder block for setting insets for the text container of @c UITextViewLayout. + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayoutBuilder * _Nonnull(^textContainerInset)(UIEdgeInsets); + +/** + @c LOKTextViewLayoutBuilder block for setting line padding between text container and actual text in @c LOKTextViewLayout. + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayoutBuilder * _Nonnull(^lineFragmentPadding)(CGFloat); +/** + @c LOKTextViewLayoutBuilder block for defining how this layout is positioned inside its parent layout. + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayoutBuilder * _Nonnull(^alignment)(LOKAlignment * _Nullable); + +/** + @c LOKTextViewLayoutBuilder block for setting flexibility of the @c LOKTextViewLayout. + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayoutBuilder * _Nonnull(^flexibility)(LOKFlexibility * _Nullable); + +/** + @c LOKTextViewLayoutBuilder block for setting the viewReuseId used by LayoutKit. + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayoutBuilder * _Nonnull(^viewReuseId)(NSString * _Nullable); + +/** + @c LOKTextViewLayoutBuilder block for setting the view class of the @c LOKTextViewLayout(should be @c UITextView + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayoutBuilder * _Nonnull(^viewClass)(Class _Nullable); +/** + Layoutkit configuration block called with the created @c UITextView (or subclass). + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayoutBuilder * _Nonnull(^config)( void(^ _Nullable)(UITextView *_Nonnull)); + +/** + @c LOKTextViewLayoutBuilder block for setting edge inset (positive) for the @c LOKTextViewLayout. + */ @property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^insets)(LOKEdgeInsets); +/** + Calling this builds and returns the @c LOKTextViewLayout. + */ @property (nonatomic, nonnull, readonly) LOKTextViewLayout *layout; @end diff --git a/Sources/ObjCSupport/LOKAlignment.swift b/Sources/ObjCSupport/LOKAlignment.swift index 8a5f7388..3612595b 100644 --- a/Sources/ObjCSupport/LOKAlignment.swift +++ b/Sources/ObjCSupport/LOKAlignment.swift @@ -8,6 +8,9 @@ import CoreGraphics +/** + Specifies how a layout positions itself inside of the rect that it is given to it by its parent during arrangement. + */ @objc open class LOKAlignment: NSObject { let alignment: Alignment init(alignment: Alignment) { @@ -31,6 +34,9 @@ import CoreGraphics @objc public static let fillCenter = LOKAlignment(alignment: Alignment(vertical: .fill, horizontal: .center)) @objc public static let aspectFit = LOKAlignment(alignment: .aspectFit) + /** + Positions a rect of the given size inside the given rect using the alignment spec. + */ @objc public func position(size: CGSize, in rect: CGRect) -> CGRect { return alignment.position(size: size, in: rect) } diff --git a/Sources/ObjCSupport/LOKAnimation.swift b/Sources/ObjCSupport/LOKAnimation.swift index e5301f2e..49e34bc7 100644 --- a/Sources/ObjCSupport/LOKAnimation.swift +++ b/Sources/ObjCSupport/LOKAnimation.swift @@ -6,6 +6,9 @@ // software distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/** + An animation for a layout. + */ @objc open class LOKAnimation: NSObject { private let animation: Animation @@ -13,6 +16,10 @@ self.animation = animation } + /** + Apply the final state of the animation. + Call this inside a UIKit animation block. + */ @objc public func apply() { animation.apply() } diff --git a/Sources/ObjCSupport/LOKBaseLayout.swift b/Sources/ObjCSupport/LOKBaseLayout.swift index 817de651..1e949297 100644 --- a/Sources/ObjCSupport/LOKBaseLayout.swift +++ b/Sources/ObjCSupport/LOKBaseLayout.swift @@ -7,7 +7,10 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. import CoreGraphics - +/** + A base class for layouts. + This layout does not require a view at runtime unless a configuration block has been provided. + */ open class LOKBaseLayout: NSObject, LOKLayout { let layout: Layout @@ -15,10 +18,33 @@ open class LOKBaseLayout: NSObject, LOKLayout { self.layout = layout } + /** + Measures the minimum size of the layout and its sublayouts. + + It MAY be run on a background thread. + + - parameter maxSize: The maximum size available to the layout. + - returns: The minimum size required by the layout and its sublayouts given a maximum size. + The size of the layout MUST NOT exceed `maxSize`. + */ public func measurement(within maxSize: CGSize) -> LOKLayoutMeasurement { return LOKLayoutMeasurement(wrappedLayout: self, layoutMeasurement: layout.measurement(within: maxSize)) } + /** + Returns the arrangement of frames for the layout inside a given rect. + The frames SHOULD NOT overflow rect, otherwise they may overlap with adjacent layouts. + + The layout MAY choose to not use the entire rect (and instead align itself in some way inside of the rect), + but the caller SHOULD NOT reallocate unused space to other layouts because this could break the layout's desired alignment and padding. + Space allocation SHOULD happen during the measure pass. + + MAY be run on a background thread. + + - parameter rect: The rectangle that the layout must position itself in. + - parameter measurement: A measurement which has size less than or equal to `rect.size` and greater than or equal to `measurement.maxSize`. + - returns: A complete set of frames for the layout. + */ public func arrangement(within rect: CGRect, measurement: LOKLayoutMeasurement) -> LOKLayoutArrangement { let arrangement = layout.arrangement(within: rect, measurement: measurement.measurement) @@ -33,22 +59,41 @@ open class LOKBaseLayout: NSObject, LOKLayout { return LOKLayoutArrangement(layoutArrangement: arrangementWithUpdatedLayout) } + /** + Indicates whether a `View` object needs to be created for this layout. + Layouts that just position their sublayouts can return `false` here. + */ open var needsView: Bool { return layout.needsView } + /** + Returns a new `UIView` for the layout. + It is not called on a layout if the layout is using a recycled view. + + MUST be run on the main thread. + */ public func makeView() -> View { return layout.makeView() } + /** + A configuration block that is run on the main thread after the view is created. + */ open func configureView(_ view: View) { layout.configure(baseTypeView: view) } + /** + The flexibility of the layout. + */ public var flexibility: LOKFlexibility { return LOKFlexibility(flexibility: layout.flexibility) } + /** + An identifier for the view that is produced by this layout. + */ public var viewReuseId: String? { return layout.viewReuseId } diff --git a/Sources/ObjCSupport/LOKBatchUpdates.swift b/Sources/ObjCSupport/LOKBatchUpdates.swift index c5a6512e..e02da2e0 100644 --- a/Sources/ObjCSupport/LOKBatchUpdates.swift +++ b/Sources/ObjCSupport/LOKBatchUpdates.swift @@ -8,6 +8,12 @@ import Foundation +/** + A set of updates to apply to a `ReloadableView`. + + Inherits from `NSObject` in order to be exposable to Objective-C. + Objective-C exposability is needed in order to override methods from extensions that use `BatchUpdates` as parameter. + */ @objc open class LOKBatchUpdates: NSObject { @objc public var insertItems = [IndexPath]() @objc public var deleteItems = [IndexPath]() @@ -37,6 +43,9 @@ import Foundation } } +/** + Instruction to move an item from one index path to another. + */ @objc open class LOKBatchUpdateItemMove: NSObject { @objc public let from: IndexPath @objc public let to: IndexPath @@ -51,6 +60,9 @@ import Foundation } } +/** + Instruction to move a section from one index to another. + */ @objc open class LOKBatchUpdateSectionMove: NSObject { @objc public let from: Int @objc public let to: Int diff --git a/Sources/ObjCSupport/LOKButtonLayout.swift b/Sources/ObjCSupport/LOKButtonLayout.swift index e0db556c..a6b4aa2d 100644 --- a/Sources/ObjCSupport/LOKButtonLayout.swift +++ b/Sources/ObjCSupport/LOKButtonLayout.swift @@ -8,15 +8,63 @@ import UIKit +/** + Layout for a `UIButton`. + + Since UIKit does not provide threadsafe methods to determine the size of a button given its content + it's implememtation hard-codes the current observed style of `UIButton`. + If the style of `UIButton` changes in the future, then the current implementation will need to be updated to reflect the new style. + + If future-proofing is a concern for your application, then you should not use `LOKButtonLayout` and instead implement your own + custom layout that uses you own custom button view (e.g. by subclassing `UIControl`). + + Similary, if you have your own custom button view, you will need to create your own custom layout for it. + */ @objc open class LOKButtonLayout: LOKBaseLayout { + + /** + Button type for button layout. + */ @objc public let type: LOKButtonLayoutType + + /** + Title for button layout. + */ @objc public let title: String + + /** + Button image for button layout. + */ @objc public let image: UIImage? + + /** + Size for button image. + */ @objc public let imageSize: CGSize + + /** + Font for button layout. + */ @objc public let font: UIFont? + + /** + Edge inset for button layout. + */ @objc public let contentEdgeInsets: NSValue? + + /** + Specifies how this layout is positioned inside its parent layout. + */ @objc public let alignment: LOKAlignment + + /** + Class object for the created view. Should be a subclass of `UIButton`. + */ @objc public let viewClass: UIButton.Type + + /** + Layoutkit configuration block called with created `UIButton` + */ @objc public let config: ((UIButton) -> Void)? @objc public init(type: LOKButtonLayoutType, diff --git a/Sources/ObjCSupport/LOKButtonLayoutType.swift b/Sources/ObjCSupport/LOKButtonLayoutType.swift index 73be821c..fdd0476f 100644 --- a/Sources/ObjCSupport/LOKButtonLayoutType.swift +++ b/Sources/ObjCSupport/LOKButtonLayoutType.swift @@ -8,6 +8,10 @@ import Foundation +/** + Maps to `UIButtonType`. + This prevents LayoutKit from breaking if a new `UIButtonType` is added. + */ extension LOKButtonLayoutType { var unwrapped: ButtonLayoutType { switch self { diff --git a/Sources/ObjCSupport/LOKFlexibility.swift b/Sources/ObjCSupport/LOKFlexibility.swift index ebc602f0..818fbef0 100644 --- a/Sources/ObjCSupport/LOKFlexibility.swift +++ b/Sources/ObjCSupport/LOKFlexibility.swift @@ -8,6 +8,20 @@ import Foundation +/** + The flexibility of a layout along both dimensions. + + Flexibility is a hint to a layout's parent about how the parent should prioritize space allocation among its children + when there is either insufficient or too much space. + + A layout MAY use the flexibility of its sublayouts to determine how to allocate its available space between those sublayouts. + A layout SHOULD NOT ever need to inspect its own flexiblity. + + A parent layout MAY compress ANY sublayout (even sublayouts that are configured as inflexible) if there is insufficient space. + A parent layout MAY expand any flexible sublayout if there is excess space and if the parent layout wants to fill that space. + A parent layout SHOULD favor expanding/compressing more flexible sublayouts over less flexible sublayouts. + A parent layout SHOULD NOT expand inflexible sublayouts. + */ @objc open class LOKFlexibility: NSObject { let flexibility: Flexibility @@ -15,11 +29,34 @@ import Foundation self.flexibility = flexibility } + /** + The flexible flex value. + */ @objc public static let flexible = LOKFlexibility(flexibility: .flexible) + + /** + The inflexible flex value. + */ @objc public static let inflexible = LOKFlexibility(flexibility: .inflexible) + + /** + The minimum flex value that is still flexible. + */ @objc public static let min = LOKFlexibility(flexibility: .min) + + /** + The maximum flex value. + */ @objc public static let max = LOKFlexibility(flexibility: .max) + + /** + More flexible than the default flexibility. + */ @objc public static let high = LOKFlexibility(flexibility: .high) + + /** + Less flexible than the default flexibility. + */ @objc public static let low = LOKFlexibility(flexibility: .low) @objc public static let horizontallyHighlyFlexible = LOKFlexibility(flexibility: Flexibility(horizontal: Flexibility.highFlex, vertical: Flexibility.inflexibleFlex)) diff --git a/Sources/ObjCSupport/LOKInsetLayout.swift b/Sources/ObjCSupport/LOKInsetLayout.swift index 21267a4e..89ebf548 100644 --- a/Sources/ObjCSupport/LOKInsetLayout.swift +++ b/Sources/ObjCSupport/LOKInsetLayout.swift @@ -8,11 +8,34 @@ import CoreGraphics +/** + A layout that insets another layout. + */ @objc open class LOKInsetLayout: LOKBaseLayout { + + /** + `EdgeInsets` for layout. + */ @objc public let insets: EdgeInsets + + /** + Specifies how a layout positions itself inside of its parent view. + */ @objc public let alignment: LOKAlignment + + /** + Class object for the view class to be created. + */ @objc public let viewClass: View.Type + + /** + Sublayout for `LOKInsetLayout`. + */ @objc public let sublayout: LOKLayout + + /** + LayoutKit configuration block called with created View. + */ @objc public let configure: ((View) -> Void)? @objc public init(insets: EdgeInsets, diff --git a/Sources/ObjCSupport/LOKLabelLayout.swift b/Sources/ObjCSupport/LOKLabelLayout.swift index 3a76abed..f58d8a86 100644 --- a/Sources/ObjCSupport/LOKLabelLayout.swift +++ b/Sources/ObjCSupport/LOKLabelLayout.swift @@ -8,14 +8,49 @@ import UIKit +/** + Layout for a `UILabel`. + */ @objc open class LOKLabelLayout: LOKBaseLayout { + + /** + Attributed string to display as the label. + */ @objc public let attributedString: NSAttributedString? + + /** + String to display as the label. + */ @objc public let string: String? + + /** + Line height for label. + */ @objc public let lineHeight: CGFloat + + /** + Font for label. + */ @objc public let font: UIFont + + /** + Number of lines the label can have. + */ @objc public let numberOfLines: Int + + /** + Specifies how this layout is positioned inside its parent layout + */ @objc public let alignment: LOKAlignment + + /** + Class object for the created view. Should be a subclass of `UILabel`. + */ @objc public let viewClass: UILabel.Type + + /** + Layoutkit configuration block called with created `UIButton`. + */ @objc public let configure: ((UILabel) -> Void)? @objc public init(attributedString: NSAttributedString, diff --git a/Sources/ObjCSupport/LOKLayout.swift b/Sources/ObjCSupport/LOKLayout.swift index 10938862..655d994c 100644 --- a/Sources/ObjCSupport/LOKLayout.swift +++ b/Sources/ObjCSupport/LOKLayout.swift @@ -7,14 +7,100 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. import CoreGraphics +/** + A protocol for types that layout view frames. + ### Basic layouts + + Many UIs can be expressed by composing the basic layouts that LayoutKit provides: + + - `LOKLabelLayout` + - `LOKInsetLayout` + - `LOKSizeLayout` + - `LOKStackLayout` + + If your UI can not be expressed by composing these basic layouts, + then you can create a custom layout. Custom layouts are recommended but not required to conform + to the `ConfigurableLayout` protocol due to the type safety and default implementation that it adds. + + ### Layout algorithm + + Layout is performed in two steps: + + 1. `measurement(within:)` + 2. `arrangement(within:measurement:)`. + + ### Threading + + Layouts MUST be thread-safe. + */ @objc public protocol LOKLayout { + + /** + Measures the minimum size of the layout and its sublayouts. + + It MAY be run on a background thread. + + - parameter maxSize: The maximum size available to the layout. + - returns: The minimum size required by the layout and its sublayouts given a maximum size. + The size of the layout MUST NOT exceed `maxSize`. + */ @objc func measurement(within maxSize: CGSize) -> LOKLayoutMeasurement + + /** + Returns the arrangement of frames for the layout inside a given rect. + The frames SHOULD NOT overflow rect, otherwise they may overlap with adjacent layouts. + + The layout MAY choose to not use the entire rect (and instead align itself in some way inside of the rect), + but the caller SHOULD NOT reallocate unused space to other layouts because this could break the layout's desired alignment and padding. + Space allocation SHOULD happen during the measure pass. + + MAY be run on a background thread. + + - parameter rect: The rectangle that the layout must position itself in. + - parameter measurement: A measurement which has size less than or equal to `rect.size` and greater than or equal to `measurement.maxSize`. + - returns: A complete set of frames for the layout. + */ @objc func arrangement(within rect: CGRect, measurement: LOKLayoutMeasurement) -> LOKLayoutArrangement + + /** + Indicates whether a View object needs to be created for this layout. + Layouts that just position their sublayouts can return `false` here. + */ @objc var needsView: Bool { get } + + /** + Returns a new `UIView` for the layout. + It is not called on a layout if the layout is using a recycled view. + + MUST be run on the main thread. + */ @objc func makeView() -> View + + /** + Configures the given view. + + MUST be run on the main thread. + */ @objc func configureView(_ view: View) + + /** + The flexibility of the layout. + + If a layout has a single sublayout, it SHOULD inherit the flexiblity of its sublayout. + If a layout has no sublayouts (e.g. `LOKLabelLayout`), it SHOULD allow its flexibility to be configured. + All layouts SHOULD provide a default flexiblity. + + TODO: figure out how to assert if inflexible layouts are compressed. + */ @objc var flexibility: LOKFlexibility { get } + + /** + An identifier for the view that is produced by this layout. + + If this layout is applied to an existing view hierarchy, and if there is a view with an identical viewReuseId, + then that view will be reused for the new layout. If there is more than one view with the same viewReuseId, then an arbitrary one will be reused. + */ @objc var viewReuseId: String? { get } } diff --git a/Sources/ObjCSupport/LOKLayoutArrangement.swift b/Sources/ObjCSupport/LOKLayoutArrangement.swift index bae58953..2385a448 100644 --- a/Sources/ObjCSupport/LOKLayoutArrangement.swift +++ b/Sources/ObjCSupport/LOKLayoutArrangement.swift @@ -8,6 +8,9 @@ import CoreGraphics +/** + The frame of a layout and the frames of its sublayouts. + */ @objc open class LOKLayoutArrangement: NSObject { let layoutArrangement: LayoutArrangement @objc public let layout: LOKLayout @@ -38,25 +41,91 @@ import CoreGraphics height: height.isFinite ? height : nil)) } + /** + Creates the views for the layout and adds them as subviews to the provided view. + Existing subviews of the provided view will be removed. + If no view is provided, then a new one is created and returned. + + MUST be run on the main thread. + + - parameter view: The layout's views will be added as subviews to this view, if provided. + + - returns: The root view. If a view was provided, then the same view will be returned, otherwise, a new one will be created. + */ @discardableResult @objc public func makeViews(in view: View?) -> View { return layoutArrangement.makeViews(in: view) } + /** + Creates the views for the layout and adds them as subviews to the provided view. + Existing subviews of the provided view will be removed. + If no view is provided, then a new one is created and returned. + + MUST be run on the main thread. + + - parameter view: The layout's views will be added as subviews to this view, if provided. + - parameter direction: The natural direction of the layout (default: `.LeftToRight`). + If it does not match the user's language direction, then the layout's views will be flipped horizontally. + Only provide this parameter if you want to test the flipped version of your layout, + or if your layouts are declared for right-to-left languages and you want them to get flipped for left-to-right languages. + + - returns: The root view. If a view was provided, then the same view will be returned, otherwise, a new one will be created. + */ @discardableResult @objc public func makeViews(in view: View?, direction: UserInterfaceLayoutDirection) -> View { return layoutArrangement.makeViews(in: view, direction: direction) } + /** + Helper function for `makeViews(in:direction:)` and `prepareAnimation(for:direction:)`. + See the documentation for those two functions. + */ @objc public func makeViews() -> View { return layoutArrangement.makeViews() } + /** + Prepares the view to be animated to this arrangement. + + Call `prepareAnimation(for:direction)` before the animation block. + Call the returned animation's `apply()` method inside the animation block. + + ``` + let animation = nextLayout.arrangement().prepareAnimation(for: rootView, direction: .RightToLeft) + View.animateWithDuration(5.0, animations: { + animation.apply() + }) + ``` + + Subviews are reparented for the new arrangement, if necessary, but frames are adjusted so locations don't change. + No frames or configurations of the new arrangement are applied until `apply()` is called on the returned animation object. + + MUST be run on the main thread. + */ @objc(prepareAnimationForView:direction:) public func prepareAnimation(for view: View, direction: UserInterfaceLayoutDirection) -> LOKAnimation { return LOKAnimation(animation: layoutArrangement.prepareAnimation(for: view, direction: direction)) } + /** + Prepares the view to be animated to this arrangement. + + Call `prepareAnimation(for:)` before the animation block. + Call the returned animation's `apply()` method inside the animation block. + + ``` + let animation = nextLayout.arrangement().prepareAnimation(for: rootView, direction: .RightToLeft) + View.animateWithDuration(5.0, animations: { + animation.apply() + }) + ``` + + Subviews are reparented for the new arrangement, if necessary, but frames are adjusted so locations don't change. + No frames or configurations of the new arrangement are applied until `apply()` is called on the returned animation object. + + MUST be run on the main thread. + */ @objc(prepareAnimationForView:) public func prepareAnimation(for view: View) -> LOKAnimation { return prepareAnimation(for: view, direction: .leftToRight) diff --git a/Sources/ObjCSupport/LOKOverlayLayout.swift b/Sources/ObjCSupport/LOKOverlayLayout.swift index 5f2b186b..881025aa 100644 --- a/Sources/ObjCSupport/LOKOverlayLayout.swift +++ b/Sources/ObjCSupport/LOKOverlayLayout.swift @@ -8,12 +8,44 @@ import Foundation +/** + A layout that overlays others. Allows adding other layouts behind or above a primary layout. + The size of the primary, background, and overlay layouts will be determined based on the size + computed from the primary layout. + */ @objc open class LOKOverlayLayout: LOKBaseLayout { + + /** + The primary layouts that the `LOKOverlayLayout` will use for sizing and flexibility. + */ @objc public let primaryLayouts: [LOKLayout] + + /** + The layouts to put behind the primary layouts. They will be at most as large as the primary + layouts. + */ @objc public let backgroundLayouts: [LOKLayout] + + /** + The layouts to put in front of the primary layout. They will be at most as large as the primary + layouts. + */ @objc public let overlayLayouts: [LOKLayout] + + /** + Specifies how this layout is positioned inside its parent layout. + */ @objc public let alignment: LOKAlignment + + + /** + Class object for the view class to be created. + */ @objc public let viewClass: View.Type + + /** + LayoutKit configuration block called with created View. + */ @objc public let configure: ((View) -> Void)? @objc public init(primaryLayouts: [LOKLayout], diff --git a/Sources/ObjCSupport/LOKReloadableViewLayoutAdapter.swift b/Sources/ObjCSupport/LOKReloadableViewLayoutAdapter.swift index da6ba069..8d8de108 100644 --- a/Sources/ObjCSupport/LOKReloadableViewLayoutAdapter.swift +++ b/Sources/ObjCSupport/LOKReloadableViewLayoutAdapter.swift @@ -8,6 +8,11 @@ import UIKit +/** + Manages background layout for reloadable views, including `UICollectionView` and `UITableView`. + + Set it as a `UICollectionView` or `UITableView`s dataSource and delegate. + */ @objc open class LOKReloadableViewLayoutAdapter: NSObject { @objc public var log: ((String) -> Void)? { get { @@ -28,6 +33,21 @@ import UIKit adapter = ReloadableViewLayoutAdapter(reloadableView: tableView) } + /** + Reloads the view with the new layout. + + If synchronous is `false` and the view doesn't already have data loaded and no batch updates are provided, + then it will incrementally insert cells into the reloadable view as layouts are computed + to increase user perceived performance for large collections. Pass an empty `BatchUpdates` object + if you wish to disable this optimization for an asynchronous reload of an empty collection. + + - parameter synchronous: If true, `reload` will not return until the operation is complete. + - parameter width: The width of the layout's arrangement. `Nil` means no constraint. Default is `infinity`. + - parameter height: The height of the layout's arrangement. `Nil` means no constraint. Default is `infinity`. + - parameter batchUpdates: The updates to apply to the reloadable view after the layout is computed. If `nil`, then all data will be reloaded. Default is `nil`. + - parameter layoutProvider: A closure that produces the layout. It is called on a background thread so it must be threadsafe. + - parameter completion: A closure that is called on the main thread when the operation is complete. + */ @objc open func reload(synchronous: Bool, width: CGFloat = CGFloat.infinity, height: CGFloat = CGFloat.infinity, @@ -43,6 +63,13 @@ import UIKit completion: completion) } + /** + Reloads the view with a precomputed layout. + It must be called on the main thread. + + This is useful if you want to precompute the layout for this collection view as part of another layout. + One example is nested collection/table views (see `NestedCollectionViewController.swift` in the sample app). + */ @objc open func reload(arrangements: [LOKLayoutArrangementSection]) { adapter.reload(arrangement: arrangements.map { $0.unwrapped }) } diff --git a/Sources/ObjCSupport/LOKSizeLayout.swift b/Sources/ObjCSupport/LOKSizeLayout.swift index d2ca00ed..2fb2f3db 100644 --- a/Sources/ObjCSupport/LOKSizeLayout.swift +++ b/Sources/ObjCSupport/LOKSizeLayout.swift @@ -8,14 +8,75 @@ import CoreGraphics +/** + A layout that has size constraints. + + ## Default behavior + + Alignment along a dimension defaults to `.fill` if there is no maximum constraint along that dimension and `.center` otherwise. + + ## Constraint precedence + + Constraints are enforced with the following precedence: + 1. The `maxSize` paremeter of measurement. + 2. The SizeLayout's `maxSize` + 3. The SizeLayout's `minSize` + + In other words, if it is impossible to satisfy all constraints simultaneously then + constraints are broken starting with minSize. + + ## Use cases + + Some common use cases: + + ``` + // A label with maximum width. + LOKSizeLayout(maxWidth: 100, sublayout: LOKLabelLayout(text: "Spills onto two lines")) + + // A label with minimum width. + LOKSizeLayout(minWidth: 100, sublayout: LOKLabelLayout(text: "Hello", alignment: .fill)) + ``` + */ @objc open class LOKSizeLayout: LOKBaseLayout { + + /** + Minimum width for size layout. + */ @objc public let minWidth: CGFloat + + /** + Maximum width for size layout. + */ @objc public let maxWidth: CGFloat + + /** + Minimum height for size layout. + */ @objc public let minHeight: CGFloat + + /** + Maximum height for size layout. + */ @objc public let maxHeight: CGFloat + + /** + Alignment height for size layout. + */ @objc public let alignment: LOKAlignment + + /** + Class object for the view class to be created. + */ @objc public let viewClass: View.Type + + /** + Sublayout for which size layout is being created. + */ @objc public let sublayout: LOKLayout? + + /** + Layoutkit configuration block called with created `LOKView`. + */ @objc public let configure: ((View) -> Void)? @objc public init(minWidth: CGFloat, diff --git a/Sources/ObjCSupport/LOKStackLayout.swift b/Sources/ObjCSupport/LOKStackLayout.swift index ab825df0..b7c380f4 100644 --- a/Sources/ObjCSupport/LOKStackLayout.swift +++ b/Sources/ObjCSupport/LOKStackLayout.swift @@ -19,6 +19,10 @@ extension LOKAxis { } } + +/** + Specifies how excess space along the axis is allocated. + */ extension LOKStackLayoutDistribution { var distribution: StackLayoutDistribution? { switch self { @@ -40,13 +44,50 @@ extension LOKStackLayoutDistribution { } } +/** + A layout that stacks sublayouts along an axis. + + Axis space is allocated to sublayouts according to the distribution policy. + + If this not enough space along the axis for all sublayouts then layouts with the highest flexibility are removed + until there is enough space to posistion the remaining layouts. + */ @objc open class LOKStackLayout: LOKBaseLayout { + + /** + Axis along which sublayouts are stacked. + */ @objc public let axis: LOKAxis + + /** + The distance in points between adjacent edges of sublayouts along the axis. + For `Distribution.EqualSpacing`, this is a minimum spacing. For all other distributions it is an exact spacing. + */ @objc public let spacing: CGFloat + + /** + Distribution of space along the stack's axis. + */ @objc public let distribution: LOKStackLayoutDistribution + + /** + Specifies how this layout is positioned inside its parent layout. + */ @objc public let alignment: LOKAlignment + + /** + Class object for the view class to be created. + */ @objc public let viewClass: View.Type + + /** + The stacked layouts. + */ @objc public let sublayouts: [LOKLayout] + + /** + Layoutkit configuration block called with created view. + */ @objc public let configure: ((View) -> Void)? @objc public init(axis: LOKAxis = .vertical, diff --git a/Sources/ObjCSupport/LOKTextViewLayout.swift b/Sources/ObjCSupport/LOKTextViewLayout.swift index 40ce0bdc..6f5a677a 100644 --- a/Sources/ObjCSupport/LOKTextViewLayout.swift +++ b/Sources/ObjCSupport/LOKTextViewLayout.swift @@ -8,16 +8,55 @@ import UIKit +/** + Layout for a `UITextView`. + */ @objc open class LOKTextViewLayout: LOKBaseLayout { + + /** + `NSAttributedString` for textView's text. + */ @objc public let attributedText: NSAttributedString? + + /** + `NSString` for textView's text. + */ @objc public let text: String? + + /** + Font for text layout. + */ @objc public let font: UIFont? + + /** + Line padding between text container and actual text in text layout. + */ @objc public let lineFragmentPadding: CGFloat + + /** + EdgeInsets for text layout. + */ @objc public let textContainerInset: UIEdgeInsets + + /** + Specifies how this layout is positioned inside its parent layout. + */ @objc public let layoutAlignment: LOKAlignment + + /** + Class object for the created view. Should be a subclass of `UITextView`. + */ @objc public let viewClass: UITextView.Type + + /** + LayoutKit configuration block called with created `UITextView`. + */ @objc public let configure: ((UITextView) -> Void)? + /** + Don't change `textContainerInset`, `lineFragmentPadding` in `configure` closure that's passed to init. + By changing those, it will cause the Layout's size calculation to be incorrect. So they will be reset by using parameters from initializer. + */ @objc public init(text: String? = nil, font: UIFont? = nil, lineFragmentPadding: CGFloat = 0,