LinkedInAttic / LayoutKit

LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
http://layoutkit.org
Apache License 2.0
3.16k stars 267 forks source link

Adding an Objective-C compatible API to LayoutKit #180

Closed staguer closed 6 years ago

staguer commented 6 years ago

This is related to issue #178 regarding adding support for Objective-C consumers. This objc-api branch is now ready for review.

Two of the open questions are: 1) How do we make these long initializers more convenient for use from Objective-C? I have several options in mind. 2) Should we make these new classes unavailable from Swift somehow? My understanding is that there's a way to use pods to exclude some directories at import time?

The builders for (1) can be added as a separate follow-up change. Currently working on figuring out what we can do for (2).

nicksnyder commented 6 years ago
  1. My guess is that the best thing to do will be to make initializers take a single object. That object will have instance properties for the properties that you would normally pass in. This will save you from making a ridiculous number of initializer variants. e.g.
    LOKLinearLayoutOptions *linearLayoutOptions = [LOKLinearLayoutOptions new];
    linearLayoutOptions.arrangement = /* */
    linearLayoutOptions.size = CGSizeMake(10, 10);
    LOKLinearLayout *linearLayout = [LOKLinearLayout newWithOptions:options];
  2. I don't remember if this is possible or how to do it. If it is possible, it seems like it would be nice to do to avoid confusion in Swift.
staguer commented 6 years ago

This PR should be ready for review now. Two things are still missing from it: documentation comments and some support for splitting out the ObjC support code. I'll be working on the first one and investigating the second one.

staguer commented 6 years ago

Regarding question (2) of how to avoid the overhead of this new code for Swift consumers, @chenxiao0228 's suggestion is to make a separate GitHub repo and Cocoapod named something like LayoutKit-objc. These wrapper classes and sample app in this PR would not go into this LayoutKit repo but into the new LayoutKit-objc repo/pod and the new pod would import the current LayoutKit pod. Swift consumers will continue to use this repo/pod without incurring the weight of this new code.

jingwei-huang1 commented 6 years ago

Additional to @chenxiao0228 comment, we can still keep them in the same repo, but 2 x pods and that would be easier to manage.

jingwei-huang1 commented 6 years ago

Also, we need to setup the test for wrappers because the current CI doesn't compile objective-c wrappers