Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

Commit

Permalink
Added inits to builders, so they can be subclassed
Browse files Browse the repository at this point in the history
  • Loading branch information
drumnkyle committed Jun 12, 2018
1 parent ef1b370 commit 77d6358
Show file tree
Hide file tree
Showing 14 changed files with 82 additions and 35 deletions.
1 change: 1 addition & 0 deletions Sources/ObjCSupport/Builders/LOKButtonLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef NS_ENUM(NSInteger, LOKButtonLayoutType) {

@interface LOKButtonLayoutBuilder: NSObject<LOKLayoutBuilder>

- (nonnull instancetype)initWithTitle:(nullable NSString *)title;
+ (nonnull instancetype)withTitle:(nullable NSString *)title;

@property (nonatomic, nonnull, readonly) LOKButtonLayoutBuilder * _Nonnull(^type)(LOKButtonLayoutType);
Expand Down
10 changes: 7 additions & 3 deletions Sources/ObjCSupport/Builders/LOKButtonLayoutBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ @interface LOKButtonLayoutBuilder ()

@implementation LOKButtonLayoutBuilder

- (instancetype)initWithTitle:(NSString *)title {
self = [super init];
_privateTitle = title;
return self;
}

+ (instancetype)withTitle:(NSString *)title {
LOKButtonLayoutBuilder *builder = [[self alloc] init];
builder.privateTitle = title;
return builder;
return [[self alloc] initWithTitle:title];
}

- (LOKButtonLayout *)layout {
Expand Down
1 change: 1 addition & 0 deletions Sources/ObjCSupport/Builders/LOKInsetLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@interface LOKInsetLayoutBuilder: NSObject<LOKLayoutBuilder>

- (nonnull instancetype)initWithInsets:(LOKEdgeInsets)insets around:(nonnull id<LOKLayout>)sublayout;
+ (nonnull instancetype)withInsets:(LOKEdgeInsets)insets around:(nonnull id<LOKLayout>)sublayout;

@property (nonatomic, nonnull, readonly) LOKInsetLayoutBuilder * _Nonnull(^alignment)(LOKAlignment * _Nullable);
Expand Down
12 changes: 8 additions & 4 deletions Sources/ObjCSupport/Builders/LOKInsetLayoutBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ @interface LOKInsetLayoutBuilder()

@implementation LOKInsetLayoutBuilder

- (instancetype)initWithInsets:(LOKEdgeInsets)insets around:(id<LOKLayout>)sublayout {
self = [super init];
_privateInsets = insets;
_privateSublayout = sublayout;
return self;
}

+ (nonnull instancetype)withInsets:(LOKEdgeInsets)insets around:(nonnull id<LOKLayout>)sublayout {
LOKInsetLayoutBuilder *builder = [[self alloc] init];
builder.privateInsets = insets;
builder.privateSublayout = sublayout;
return builder;
return [[self alloc] initWithInsets:insets around:sublayout];
}

- (nonnull LOKInsetLayout *)layout {
Expand Down
3 changes: 3 additions & 0 deletions Sources/ObjCSupport/Builders/LOKLabelLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

@interface LOKLabelLayoutBuilder: NSObject<LOKLayoutBuilder>

- (nonnull instancetype)initWithString:(nullable NSString *)string;
- (nonnull instancetype)initWithAttributedString:(nullable NSAttributedString *)attributedString;

+ (nonnull instancetype)withString:(nullable NSString *)string;
+ (nonnull instancetype)withAttributedString:(nullable NSAttributedString *)attributedString;

Expand Down
20 changes: 14 additions & 6 deletions Sources/ObjCSupport/Builders/LOKLabelLayoutBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@ @interface LOKLabelLayoutBuilder ()

@implementation LOKLabelLayoutBuilder

- (instancetype)initWithString:(NSString *)string {
self = [super init];
_privateString = string;
return self;
}

- (instancetype)initWithAttributedString:(NSAttributedString *)attributedString {
self = [super init];
_privateAttributedString = attributedString;
return self;
}

+ (nonnull instancetype)withString:(nullable NSString *)string {
LOKLabelLayoutBuilder *builder = [[self alloc] init];
builder.privateString = string;
return builder;
return [[self alloc] initWithString:string];
}

+ (nonnull instancetype)withAttributedString:(nullable NSAttributedString *)attributedString {
LOKLabelLayoutBuilder *builder = [[self alloc] init];
builder.privateAttributedString = attributedString;
return builder;
return [[self alloc] initWithAttributedString:attributedString];
}

- (nonnull LOKLabelLayout *)layout {
Expand Down
1 change: 1 addition & 0 deletions Sources/ObjCSupport/Builders/LOKOverlayLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@interface LOKOverlayLayoutBuilder: NSObject<LOKLayoutBuilder>

- (nonnull instancetype)initWithPrimaryLayout:(nonnull id<LOKLayout>)primaryLayout;
+ (nonnull instancetype)withPrimaryLayout:(nonnull id<LOKLayout>)primaryLayout;

@property (nonatomic, nonnull, readonly) LOKOverlayLayoutBuilder * _Nonnull(^overlay)(NSArray< id<LOKLayout> > * _Nullable);
Expand Down
14 changes: 9 additions & 5 deletions Sources/ObjCSupport/Builders/LOKOverlayLayoutBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ @interface LOKOverlayLayoutBuilder ()

@implementation LOKOverlayLayoutBuilder

- (instancetype)initWithPrimaryLayout:(id<LOKLayout>)primaryLayout {
self = [super init];
_privatePrimary = primaryLayout;
_privateBackground = @[];
_privateOverlay = @[];
return self;
}

+ (instancetype)withPrimaryLayout:(id<LOKLayout>)primaryLayout {
LOKOverlayLayoutBuilder *builder = [[self alloc] init];
builder.privatePrimary = primaryLayout;
builder.privateBackground = @[];
builder.privateOverlay = @[];
return builder;
return [[self alloc] initWithPrimaryLayout:primaryLayout];
}

- (LOKOverlayLayout *)layout {
Expand Down
1 change: 1 addition & 0 deletions Sources/ObjCSupport/Builders/LOKSizeLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@interface LOKSizeLayoutBuilder: NSObject<LOKLayoutBuilder>

- (nonnull instancetype)initWithSublayout:(nullable id<LOKLayout>)sublayout;
+ (nonnull instancetype)withSublayout:(nullable id<LOKLayout>)sublayout;

@property (nonatomic, nonnull, readonly) LOKSizeLayoutBuilder * _Nonnull(^width)(CGFloat);
Expand Down
18 changes: 11 additions & 7 deletions Sources/ObjCSupport/Builders/LOKSizeLayoutBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ @interface LOKSizeLayoutBuilder ()

@implementation LOKSizeLayoutBuilder

- (instancetype)initWithSublayout:(id<LOKLayout>)sublayout {
self = [super init];
_privateSublayout = sublayout;
_privateMinWidth = 0;
_privateMinHeight = 0;
_privateMaxWidth = INFINITY;
_privateMaxHeight = INFINITY;
return self;
}

+ (instancetype)withSublayout:(id<LOKLayout>)sublayout {
LOKSizeLayoutBuilder *builder = [[self alloc] init];
builder.privateSublayout = sublayout;
builder.privateMinWidth = 0;
builder.privateMinHeight = 0;
builder.privateMaxWidth = INFINITY;
builder.privateMaxHeight = INFINITY;
return builder;
return [[self alloc] initWithSublayout:sublayout];
}

- (CGFloat)privateWidth {
Expand Down
1 change: 1 addition & 0 deletions Sources/ObjCSupport/Builders/LOKStackLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ typedef NS_ENUM(NSInteger, LOKAxis) {

@interface LOKStackLayoutBuilder: NSObject<LOKLayoutBuilder>

- (nonnull instancetype)initWithSublayouts:(nonnull NSArray< id<LOKLayout> > *)sublayouts;
+ (nonnull instancetype)withSublayouts:(nonnull NSArray< id<LOKLayout> > *)sublayouts;

@property (nonatomic, nonnull, readonly) LOKStackLayoutBuilder * _Nonnull(^axis)(LOKAxis);
Expand Down
12 changes: 8 additions & 4 deletions Sources/ObjCSupport/Builders/LOKStackLayoutBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ @interface LOKStackLayoutBuilder ()

@implementation LOKStackLayoutBuilder

- (instancetype)initWithSublayouts:(NSArray<id<LOKLayout>> *)sublayouts {
self = [super init];
_privateAxis = LOKAxisVertical;
_privateSublayouts = sublayouts;
return self;
}

+ (instancetype)withSublayouts:(NSArray<id<LOKLayout>> *)sublayouts {
LOKStackLayoutBuilder *builder = [[self alloc] init];
builder.privateAxis = LOKAxisVertical;
builder.privateSublayouts = sublayouts;
return builder;
return [[self alloc] initWithSublayouts:sublayouts];
}

- (LOKStackLayout *)layout {
Expand Down
3 changes: 3 additions & 0 deletions Sources/ObjCSupport/Builders/LOKTextViewLayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

@interface LOKTextViewLayoutBuilder: NSObject<LOKLayoutBuilder>

- (nonnull instancetype)initWithString:(nullable NSString *)string;
- (nonnull instancetype)initWithAttributedString:(nullable NSAttributedString *)attributedString;

+ (nonnull instancetype)withString:(nullable NSString *)string;
+ (nonnull instancetype)withAttributedString:(nullable NSAttributedString *)attributedString;

Expand Down
20 changes: 14 additions & 6 deletions Sources/ObjCSupport/Builders/LOKTextViewLayoutBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@ @interface LOKTextViewLayoutBuilder ()

@implementation LOKTextViewLayoutBuilder

- (instancetype)initWithString:(NSString *)string {
self = [super init];
_privateString = string;
return self;
}

- (instancetype)initWithAttributedString:(NSAttributedString *)attributedString {
self = [super init];
_privateAttributedString = attributedString;
return self;
}

+ (nonnull instancetype)withString:(nullable NSString *)string {
LOKTextViewLayoutBuilder *builder = [[self alloc] init];
builder.privateString = string;
return builder;
return [[self alloc] initWithString:string];
}

+ (nonnull instancetype)withAttributedString:(nullable NSAttributedString *)attributedString {
LOKTextViewLayoutBuilder *builder = [[self alloc] init];
builder.privateAttributedString = attributedString;
return builder;
return [[self alloc] initWithAttributedString:attributedString];
}

- (nonnull LOKTextViewLayout *)layout {
Expand Down

0 comments on commit 77d6358

Please sign in to comment.