{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/yoga/issues/289","repository_url":"https://api.github.com/repos/facebook/yoga","labels_url":"https://api.github.com/repos/facebook/yoga/issues/289/labels{/name}","comments_url":"https://api.github.com/repos/facebook/yoga/issues/289/comments","events_url":"https://api.github.com/repos/facebook/yoga/issues/289/events","html_url":"https://github.com/facebook/yoga/pull/289","id":196300666,"number":289,"title":"WIP: Improve the Objective-C and Swift bridge","user":{"login":"hartbit","id":325519,"avatar_url":"https://avatars.githubusercontent.com/u/325519?v=3","gravatar_id":"","url":"https://api.github.com/users/hartbit","html_url":"https://github.com/hartbit","followers_url":"https://api.github.com/users/hartbit/followers","following_url":"https://api.github.com/users/hartbit/following{/other_user}","gists_url":"https://api.github.com/users/hartbit/gists{/gist_id}","starred_url":"https://api.github.com/users/hartbit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hartbit/subscriptions","organizations_url":"https://api.github.com/users/hartbit/orgs","repos_url":"https://api.github.com/users/hartbit/repos","events_url":"https://api.github.com/users/hartbit/events{/privacy}","received_events_url":"https://api.github.com/users/hartbit/received_events","type":"User","site_admin":false},"labels":[{"id":196858700,"url":"https://api.github.com/repos/facebook/yoga/labels/CLA%20Signed","name":"CLA Signed","color":"009900","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":20,"created_at":"2016-12-18T21:32:53Z","updated_at":"2016-12-19T18:53:26Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/facebook/yoga/pulls/289","html_url":"https://github.com/facebook/yoga/pull/289","diff_url":"https://github.com/facebook/yoga/pull/289.diff","patch_url":"https://github.com/facebook/yoga/pull/289.patch"},"body":"# What I've done\r\n\r\nHere is what I've done so far:\r\n\r\n- I created a framework target in the Xcode project to support Carthage\r\n- I renamed the prefix from `YG` to `YK` to support custom enums\r\n- I modified the enums.py generator to add a generation of Objective-C enums\r\n    - I removed enums which were not used in the Objective-C bridge\r\n    - I made sure not to generate the `Count` items\r\n    - I renamed LTR and RTL to `LeftToRight` and `RightToLeft` :-) we don't mind being verbose if it makes identifiers clearer\r\n- I transformed the style setters into properties and added the getter methods\r\n- I renamed the swift names to drop the prefix, which is not Swift style.\r\n\r\nFor example, here are what the Objective-C and Swift sample code look like:\r\n\r\n## Objective-C\r\n\r\n```objc\r\n- (void)viewDidLoad\r\n{\r\n    UIView *root = self.view;\r\n    root.backgroundColor = [UIColor redColor];\r\n    [root yk_setUsesYoga:YES];\r\n    [root yk_setWidth:self.view.bounds.size.width];\r\n    [root yk_setHeight:self.view.bounds.size.height];\r\n    [root yk_setAlignItems:YKAlignCenter];\r\n    [root yk_setJustifyContent:YKJustifyCenter];\r\n\r\n    UIView *child1 = [UIView new];\r\n    child1.backgroundColor = [UIColor blueColor];\r\n    [child1 yk_setUsesYoga:YES];\r\n    [child1 yk_setWidth:100];\r\n    [child1 yk_setHeight:100];\r\n\r\n    UIView *child2 = [UIView new];\r\n    child2.backgroundColor = [UIColor greenColor];\r\n    child2.frame = (CGRect) {\r\n        .size = {\r\n            .width = 200,\r\n            .height = 100,\r\n        }\r\n    };\r\n\r\n    UIView *child3 = [UIView new];\r\n    child3.backgroundColor = [UIColor yellowColor];\r\n    child3.frame = (CGRect) {\r\n        .size = {\r\n            .width = 100,\r\n            .height = 100,\r\n        }\r\n    };\r\n\r\n    [child2 addSubview:child3];\r\n    [root addSubview:child1];\r\n    [root addSubview:child2];\r\n    [root yk_applyLayout];\r\n}\r\n```\r\n\r\n## Swift\r\n\r\n```swift\r\n    override func viewDidLoad() {\r\n        let root = view!\r\n        root.backgroundColor = .red\r\n        root.usesYoga = true\r\n        root.layoutWidth = view.bounds.size.width\r\n        root.layoutHeight = view.bounds.size.height\r\n        root.layoutAlignItems = .center\r\n        root.layoutJustifyContent = .center\r\n      \r\n        let child1 = UIView()\r\n        child1.backgroundColor = .blue\r\n        child1.usesYoga = true\r\n        child1.layoutWidth = 100\r\n        child1.layoutHeight = 100\r\n      \r\n        let child2 = UIView()\r\n        child2.backgroundColor = .green\r\n        child2.frame = CGRect(origin: .zero, size: CGSize(width: 200, height: 100))\r\n      \r\n        let child3 = UIView()\r\n        child3.backgroundColor = .yellow\r\n        child3.frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))\r\n      \r\n        child2.addSubview(child3)\r\n        root.addSubview(child1)\r\n        root.addSubview(child2)\r\n        root.applyLayout()\r\n    }\r\n```\r\n\r\nHere's what I'd still like to do, but not sure on how best to achieve:\r\n\r\n# YKEdge based style values\r\n\r\nI have purposefully left the style values which depend on an `YKEdge` alone because I'd like to improve them to be properties, but I'm undecided on how to. Here are my two solutions:\r\n\r\n## Normalization\r\n\r\nWe could create `yk_positionLeft`, `yk_positionRight`, etc... properties. The pro is that it's simple and efficient, but it's a bit messy.\r\n\r\n## Sub-types\r\n\r\nOr we could go through sub-types with `left`, `right, etc.. properties:\r\n\r\n```\r\n@interface YKPosition\r\n@property (nonatomic) CGFloat left;\r\n@property (nonatomic) CGFloat top;\r\n@property (nonatomic) CGFloat right;\r\n@property (nonatomic) CGFloat bottom;\r\n@property (nonatomic) CGFloat start;\r\n@property (nonatomic) CGFloat end;\r\n@property (nonatomic) CGFloat horizontal;\r\n@property (nonatomic) CGFloat vertical;\r\n@property (nonatomic) CGFloat all;\r\n@end\r\n```\r\n\r\n Getting and setting such a property would look like this:\r\n\r\n```\r\nview.yk_position.left = 20;\r\n```\r\n\r\nThis would be the cleanest solution. But it forces us to initialise three extra objects per view. We could however restrict this solution to Swift and use a struct, which would reduce the performance cost.\r\n\r\n# Prefix in Swift\r\n\r\nI removed the `yk_` prefix in Swift because its an anti-pattern and replaced it with `layout`. The first question is: would it be better if it were `yoga` instead?\r\n\r\nWhatever it is, I think we still need some kind of prefix to make sure there is no ambiguity that values like `width` and `height` are for layout calculations and not values of `UIView` derived from `frame`. But I'm not 100% happy of the solution. Like for the edge values, how about a sub-type?\r\n\r\n```\r\nlet root = view!\r\nroot.backgroundColor = .red\r\nroot.yoga.usesYoga = true\r\nroot.yoga.width = view.bounds.size.width\r\nroot.yoga.height = view.bounds.size.height\r\nroot.yoga.alignItems = .center\r\nroot.yoga.justifyContent = .center\r\n```"},"comment":{"url":"https://api.github.com/repos/facebook/yoga/issues/comments/268046194","html_url":"https://github.com/facebook/yoga/pull/289#issuecomment-268046194","issue_url":"https://api.github.com/repos/facebook/yoga/issues/289","id":268046194,"user":{"login":"facebook-github-bot","id":6422482,"avatar_url":"https://avatars.githubusercontent.com/u/6422482?v=3","gravatar_id":"","url":"https://api.github.com/users/facebook-github-bot","html_url":"https://github.com/facebook-github-bot","followers_url":"https://api.github.com/users/facebook-github-bot/followers","following_url":"https://api.github.com/users/facebook-github-bot/following{/other_user}","gists_url":"https://api.github.com/users/facebook-github-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/facebook-github-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/facebook-github-bot/subscriptions","organizations_url":"https://api.github.com/users/facebook-github-bot/orgs","repos_url":"https://api.github.com/users/facebook-github-bot/repos","events_url":"https://api.github.com/users/facebook-github-bot/events{/privacy}","received_events_url":"https://api.github.com/users/facebook-github-bot/received_events","type":"User","site_admin":false},"created_at":"2016-12-19T18:53:26Z","updated_at":"2016-12-19T18:53:26Z","body":"@hartbit updated the pull request - [view changes](https://github.com/facebook/yoga/pull/289/files/5f5e5df32808c773fe1c2615388d49f6eb4c40f0..7158fc24a3c50ef89dd849ec591c22a174035f42)"}}
{"actor":{"display_login":"facebook-github-bot"}}