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

Commit

Permalink
Adding builders for Objective-C wrappers. (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
staguer authored Mar 9, 2018
1 parent 123492b commit 65f40d6
Show file tree
Hide file tree
Showing 18 changed files with 577 additions and 48 deletions.
72 changes: 72 additions & 0 deletions LayoutKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@
7E233E63202E5F870012DD1E /* LOKButtonLayoutType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E233E62202E5F870012DD1E /* LOKButtonLayoutType.swift */; };
7E233E65203129680012DD1E /* LOKOverlayLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E233E64203129680012DD1E /* LOKOverlayLayout.swift */; };
7E233E67203130110012DD1E /* LOKTextViewLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E233E66203130110012DD1E /* LOKTextViewLayout.swift */; };
7E7370EA2051A494007C19FF /* LOKInsetLayoutBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E7370E82051A494007C19FF /* LOKInsetLayoutBuilder.h */; };
7E7370EB2051A494007C19FF /* LOKInsetLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7370E92051A494007C19FF /* LOKInsetLayoutBuilder.m */; };
7E7370EE2051E08F007C19FF /* LOKLabelLayoutBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E7370EC2051E08F007C19FF /* LOKLabelLayoutBuilder.h */; };
7E7370EF2051E08F007C19FF /* LOKLabelLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7370ED2051E08F007C19FF /* LOKLabelLayoutBuilder.m */; };
7E7370F22051E3E6007C19FF /* LOKBaseLayoutBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E7370F02051E3E6007C19FF /* LOKBaseLayoutBuilder.h */; };
7E7370F32051E3E6007C19FF /* LOKBaseLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7370F12051E3E6007C19FF /* LOKBaseLayoutBuilder.m */; };
7E7370F62051ED84007C19FF /* LOKButtonLayoutBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E7370F42051ED84007C19FF /* LOKButtonLayoutBuilder.h */; };
7E7370F72051ED84007C19FF /* LOKButtonLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7370F52051ED84007C19FF /* LOKButtonLayoutBuilder.m */; };
7E7370FA2051F415007C19FF /* LOKOverlayLayoutBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E7370F82051F415007C19FF /* LOKOverlayLayoutBuilder.h */; };
7E7370FB2051F415007C19FF /* LOKOverlayLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7370F92051F415007C19FF /* LOKOverlayLayoutBuilder.m */; };
7E7370FE2051F86D007C19FF /* LOKSizeLayoutBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E7370FC2051F86D007C19FF /* LOKSizeLayoutBuilder.h */; };
7E7370FF2051F86D007C19FF /* LOKSizeLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7370FD2051F86D007C19FF /* LOKSizeLayoutBuilder.m */; };
7E73710220520CA8007C19FF /* LOKStackLayoutBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E73710020520CA8007C19FF /* LOKStackLayoutBuilder.h */; };
7E73710320520CA8007C19FF /* LOKStackLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E73710120520CA8007C19FF /* LOKStackLayoutBuilder.m */; };
7E73710620520F5F007C19FF /* LOKTextViewLayoutBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E73710420520F5F007C19FF /* LOKTextViewLayoutBuilder.h */; };
7E73710720520F5F007C19FF /* LOKTextViewLayoutBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E73710520520F5F007C19FF /* LOKTextViewLayoutBuilder.m */; };
7E7B83B6201E550F0001E279 /* LOKLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E7B83B5201E550F0001E279 /* LOKLayout.swift */; };
7E7B83B8201E554A0001E279 /* WrappedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E7B83B7201E554A0001E279 /* WrappedLayout.swift */; };
7E7B83BA201E55690001E279 /* ReverseWrappedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E7B83B9201E55690001E279 /* ReverseWrappedLayout.swift */; };
Expand Down Expand Up @@ -432,6 +448,22 @@
7E233E62202E5F870012DD1E /* LOKButtonLayoutType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOKButtonLayoutType.swift; sourceTree = "<group>"; };
7E233E64203129680012DD1E /* LOKOverlayLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOKOverlayLayout.swift; sourceTree = "<group>"; };
7E233E66203130110012DD1E /* LOKTextViewLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOKTextViewLayout.swift; sourceTree = "<group>"; };
7E7370E82051A494007C19FF /* LOKInsetLayoutBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LOKInsetLayoutBuilder.h; sourceTree = "<group>"; };
7E7370E92051A494007C19FF /* LOKInsetLayoutBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LOKInsetLayoutBuilder.m; sourceTree = "<group>"; };
7E7370EC2051E08F007C19FF /* LOKLabelLayoutBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LOKLabelLayoutBuilder.h; sourceTree = "<group>"; };
7E7370ED2051E08F007C19FF /* LOKLabelLayoutBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LOKLabelLayoutBuilder.m; sourceTree = "<group>"; };
7E7370F02051E3E6007C19FF /* LOKBaseLayoutBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LOKBaseLayoutBuilder.h; sourceTree = "<group>"; };
7E7370F12051E3E6007C19FF /* LOKBaseLayoutBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LOKBaseLayoutBuilder.m; sourceTree = "<group>"; };
7E7370F42051ED84007C19FF /* LOKButtonLayoutBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LOKButtonLayoutBuilder.h; sourceTree = "<group>"; };
7E7370F52051ED84007C19FF /* LOKButtonLayoutBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LOKButtonLayoutBuilder.m; sourceTree = "<group>"; };
7E7370F82051F415007C19FF /* LOKOverlayLayoutBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LOKOverlayLayoutBuilder.h; sourceTree = "<group>"; };
7E7370F92051F415007C19FF /* LOKOverlayLayoutBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LOKOverlayLayoutBuilder.m; sourceTree = "<group>"; };
7E7370FC2051F86D007C19FF /* LOKSizeLayoutBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LOKSizeLayoutBuilder.h; sourceTree = "<group>"; };
7E7370FD2051F86D007C19FF /* LOKSizeLayoutBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LOKSizeLayoutBuilder.m; sourceTree = "<group>"; };
7E73710020520CA8007C19FF /* LOKStackLayoutBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LOKStackLayoutBuilder.h; sourceTree = "<group>"; };
7E73710120520CA8007C19FF /* LOKStackLayoutBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LOKStackLayoutBuilder.m; sourceTree = "<group>"; };
7E73710420520F5F007C19FF /* LOKTextViewLayoutBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LOKTextViewLayoutBuilder.h; sourceTree = "<group>"; };
7E73710520520F5F007C19FF /* LOKTextViewLayoutBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LOKTextViewLayoutBuilder.m; sourceTree = "<group>"; };
7E7B83B5201E550F0001E279 /* LOKLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LOKLayout.swift; sourceTree = "<group>"; };
7E7B83B7201E554A0001E279 /* WrappedLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrappedLayout.swift; sourceTree = "<group>"; };
7E7B83B9201E55690001E279 /* ReverseWrappedLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReverseWrappedLayout.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -752,9 +784,33 @@
path = Internal;
sourceTree = "<group>";
};
7E7370E72051A3FA007C19FF /* Builders */ = {
isa = PBXGroup;
children = (
7E7370F02051E3E6007C19FF /* LOKBaseLayoutBuilder.h */,
7E7370F12051E3E6007C19FF /* LOKBaseLayoutBuilder.m */,
7E7370F42051ED84007C19FF /* LOKButtonLayoutBuilder.h */,
7E7370F52051ED84007C19FF /* LOKButtonLayoutBuilder.m */,
7E7370E82051A494007C19FF /* LOKInsetLayoutBuilder.h */,
7E7370E92051A494007C19FF /* LOKInsetLayoutBuilder.m */,
7E7370EC2051E08F007C19FF /* LOKLabelLayoutBuilder.h */,
7E7370ED2051E08F007C19FF /* LOKLabelLayoutBuilder.m */,
7E7370F82051F415007C19FF /* LOKOverlayLayoutBuilder.h */,
7E7370F92051F415007C19FF /* LOKOverlayLayoutBuilder.m */,
7E7370FC2051F86D007C19FF /* LOKSizeLayoutBuilder.h */,
7E7370FD2051F86D007C19FF /* LOKSizeLayoutBuilder.m */,
7E73710020520CA8007C19FF /* LOKStackLayoutBuilder.h */,
7E73710120520CA8007C19FF /* LOKStackLayoutBuilder.m */,
7E73710420520F5F007C19FF /* LOKTextViewLayoutBuilder.h */,
7E73710520520F5F007C19FF /* LOKTextViewLayoutBuilder.m */,
);
path = Builders;
sourceTree = "<group>";
};
7E7B83B4201E54F30001E279 /* ObjCSupport */ = {
isa = PBXGroup;
children = (
7E7370E72051A3FA007C19FF /* Builders */,
7E3107A82033B820009BA47A /* Internal */,
7E7B83C3201E5EB20001E279 /* LOKAlignment.swift */,
7E7B83C7201E8DDF0001E279 /* LOKBaseLayout.swift */,
Expand Down Expand Up @@ -810,6 +866,14 @@
buildActionMask = 2147483647;
files = (
0BCB75701D8720110065E02A /* LayoutKit.h in Headers */,
7E7370F62051ED84007C19FF /* LOKButtonLayoutBuilder.h in Headers */,
7E7370FA2051F415007C19FF /* LOKOverlayLayoutBuilder.h in Headers */,
7E7370FE2051F86D007C19FF /* LOKSizeLayoutBuilder.h in Headers */,
7E7370EA2051A494007C19FF /* LOKInsetLayoutBuilder.h in Headers */,
7E7370F22051E3E6007C19FF /* LOKBaseLayoutBuilder.h in Headers */,
7E73710220520CA8007C19FF /* LOKStackLayoutBuilder.h in Headers */,
7E7370EE2051E08F007C19FF /* LOKLabelLayoutBuilder.h in Headers */,
7E73710620520F5F007C19FF /* LOKTextViewLayoutBuilder.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1191,6 +1255,7 @@
files = (
0BCB76051D8724800065E02A /* StackLayout.swift in Sources */,
7E233E58202CEAB80012DD1E /* LOKLayoutArrangementSection.swift in Sources */,
7E7370F72051ED84007C19FF /* LOKButtonLayoutBuilder.m in Sources */,
0BCB760D1D8724800065E02A /* LayoutAdapterTableView.swift in Sources */,
0BCB76071D8724800065E02A /* AxisPoint.swift in Sources */,
7E7B83BA201E55690001E279 /* ReverseWrappedLayout.swift in Sources */,
Expand All @@ -1211,13 +1276,15 @@
7E7B83B6201E550F0001E279 /* LOKLayout.swift in Sources */,
75D94A361EA01B6A00A5FD01 /* OverlayLayout.swift in Sources */,
0BCB75FD1D8724800065E02A /* CGSizeExtension.swift in Sources */,
7E7370FB2051F415007C19FF /* LOKOverlayLayoutBuilder.m in Sources */,
7E7B83E120279CD10001E279 /* LOKReloadableViewLayoutAdapter.swift in Sources */,
0BCB760B1D8724800065E02A /* BatchUpdates.swift in Sources */,
7E7B83DF202101340001E279 /* LOKStackLayout.swift in Sources */,
0BCB76011D8724800065E02A /* BaseLayout.swift in Sources */,
7E7B83C2201E57230001E279 /* LOKInsetLayout.swift in Sources */,
0BCB75FA1D8724800065E02A /* ConfigurableLayout.swift in Sources */,
7E233E56202CEA8A0012DD1E /* LOKLayoutSection.swift in Sources */,
7E7370EF2051E08F007C19FF /* LOKLabelLayoutBuilder.m in Sources */,
0BCB76111D8724800065E02A /* ReloadableViewLayoutAdapter.swift in Sources */,
0BCB75F91D8724800065E02A /* Axis.swift in Sources */,
0BCB760A1D8724800065E02A /* ViewRecycler.swift in Sources */,
Expand All @@ -1228,24 +1295,29 @@
0BCB75FF1D8724800065E02A /* LayoutArrangement.swift in Sources */,
0BCB760F1D8724800065E02A /* ReloadableViewLayoutAdapter+UICollectionView.swift in Sources */,
0BCB75F61D8724800065E02A /* Alignment.swift in Sources */,
7E73710720520F5F007C19FF /* LOKTextViewLayoutBuilder.m in Sources */,
7E7B83C6201E60BA0001E279 /* LOKLabelLayout.swift in Sources */,
7E73710320520CA8007C19FF /* LOKStackLayoutBuilder.m in Sources */,
7E233E65203129680012DD1E /* LOKOverlayLayout.swift in Sources */,
0B193BB91D887BCF00FCA22D /* IndexSetExtension.swift in Sources */,
0BCB75FC1D8724800065E02A /* CFAbsoluteTimeExtension.swift in Sources */,
0B765F2C1DC0514F000BF1FD /* CGFloatExtension.swift in Sources */,
7E233E67203130110012DD1E /* LOKTextViewLayout.swift in Sources */,
7E7370EB2051A494007C19FF /* LOKInsetLayoutBuilder.m in Sources */,
0BCB76041D8724800065E02A /* SizeLayout.swift in Sources */,
7E233E61202E2CC00012DD1E /* LOKButtonLayout.swift in Sources */,
7E7B83C0201E56590001E279 /* LOKLayoutMeasurement.swift in Sources */,
0BCB76031D8724800065E02A /* LabelLayout.swift in Sources */,
0BCB76101D8724800065E02A /* ReloadableViewLayoutAdapter+UITableView.swift in Sources */,
7E7B83DD2020F7830001E279 /* LOKSizeLayout.swift in Sources */,
7E7370FF2051F86D007C19FF /* LOKSizeLayoutBuilder.m in Sources */,
7E7B83BC201E55B30001E279 /* LOKFlexibility.swift in Sources */,
7E233E63202E5F870012DD1E /* LOKButtonLayoutType.swift in Sources */,
0BCB75FB1D8724800065E02A /* Flexibility.swift in Sources */,
0BCB76121D8724800065E02A /* ReloadableViewUpdateManager.swift in Sources */,
44F968151E425F5D00392763 /* TextViewLayout.swift in Sources */,
0BD42BDC1DB5EAAD00E04AA3 /* Text.swift in Sources */,
7E7370F32051E3E6007C19FF /* LOKBaseLayoutBuilder.m in Sources */,
0BCB76131D8724800065E02A /* StackView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
75 changes: 27 additions & 48 deletions LayoutKitObjCSampleApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

#import "ViewController.h"
#import "RotationLayout.h"
#import "LOKLabelLayoutBuilder.h"
#import "LOKInsetLayoutBuilder.h"
#import "LOKSizeLayoutBuilder.h"
#import "LOKStackLayoutBuilder.h"

@import Foundation;
@import UIKit;
Expand Down Expand Up @@ -64,16 +68,9 @@ - (void)viewDidLoad {
collectionView.delegate = self.adapter;
collectionView.dataSource = self.adapter;

LOKSizeLayout *cellLayout = [[LOKSizeLayout alloc] initWithMinWidth:self.view.bounds.size.width
maxWidth:self.view.bounds.size.width
minHeight:0
maxHeight:INFINITY
alignment:nil
flexibility:nil
viewReuseId:nil
viewClass:nil
sublayout:self.helloWorldLayout
configure:nil];
LOKSizeLayoutBuilder *cellLayoutBuilder = [LOKSizeLayoutBuilder withSublayout:self.helloWorldLayout];
cellLayoutBuilder.width = self.view.bounds.size.width;
LOKSizeLayout *cellLayout = [cellLayoutBuilder build];

NSArray *items = @[
cellLayout, cellLayout, cellLayout, cellLayout,
Expand Down Expand Up @@ -109,44 +106,26 @@ - (void)viewDidLayoutSubviews {
}

+ (id<LOKLayout>)makeHelloLayout {
LOKLabelLayout *labelLayoutA = [[LOKLabelLayout alloc] initWithString:@"Hello"
font:[UIFont systemFontOfSize:UIFont.systemFontSize]
lineHeight:0
numberOfLines:0
alignment:LOKAlignment.fill
flexibility:LOKFlexibility.flexible
viewReuseId:nil
viewClass:MyLabelView.class
configure:^(UILabel *label) {
label.backgroundColor = UIColor.whiteColor;
}];
LOKLabelLayout *labelLayoutB = [[LOKLabelLayout alloc] initWithString:@"world!"
font:[UIFont systemFontOfSize:UIFont.systemFontSize]
lineHeight:0
numberOfLines:0
alignment:LOKAlignment.fill
flexibility:LOKFlexibility.flexible
viewReuseId:nil
viewClass:MyLabelView.class
configure:^(UILabel *label) {
label.backgroundColor = UIColor.whiteColor;
}];
LOKStackLayout *stackLayout = [[LOKStackLayout alloc] initWithAxis:LOKAxisHorizontal
spacing:10
distribution:LOKStackLayoutDistributionDefault
alignment:nil
flexibility:nil
viewClass:nil
viewReuseId:nil
sublayouts:@[labelLayoutA, labelLayoutB]
configure:nil];
LOKInsetLayout *insetLayout = [[LOKInsetLayout alloc] initWithInsets:UIEdgeInsetsMake(20, 20, 20, 20)
alignment:LOKAlignment.fill
viewReuseId:nil
viewClass:LabelBackgroundView.class
sublayout:stackLayout
configure:^(UIView *view) { }];
return [[RotationLayout alloc] initWithSublayout:insetLayout
LOKLabelLayoutBuilder *labelLayoutBuilderA = [LOKLabelLayoutBuilder withString:@"Hello"];
labelLayoutBuilderA.viewClass = MyLabelView.class;
labelLayoutBuilderA.configure = ^(UIView * _Nonnull label) {
label.backgroundColor = UIColor.whiteColor;
};
LOKLabelLayout *labelLayoutA = [labelLayoutBuilderA build];
LOKLabelLayoutBuilder *labelLayoutBuilderB = [LOKLabelLayoutBuilder withString:@"world!"];
labelLayoutBuilderB.viewClass = MyLabelView.class;
labelLayoutBuilderB.configure = ^(UIView * _Nonnull label) {
label.backgroundColor = UIColor.whiteColor;
};
LOKLabelLayout *labelLayoutB = [labelLayoutBuilderB build];
LOKStackLayoutBuilder *stackLayoutBuilder = [LOKStackLayoutBuilder withSublayouts:@[labelLayoutA, labelLayoutB]];
stackLayoutBuilder.axis = LOKAxisHorizontal;
stackLayoutBuilder.spacing = 10;
LOKInsetLayoutBuilder *insetLayoutBuilder = [LOKInsetLayoutBuilder withInsets:UIEdgeInsetsMake(20, 20, 20, 20) around:[stackLayoutBuilder build]];
insetLayoutBuilder.alignment = LOKAlignment.fill;
insetLayoutBuilder.viewClass = LabelBackgroundView.class;
insetLayoutBuilder.configure = ^(UIView * _Nonnull view) { };
return [[RotationLayout alloc] initWithSublayout:[insetLayoutBuilder build]
alignment:LOKAlignment.center
viewReuseId:nil];
}
Expand Down
Loading

0 comments on commit 65f40d6

Please sign in to comment.