{"action":"created","issue":{"url":"https://api.github.com/repos/facebook/Shimmer/issues/68","repository_url":"https://api.github.com/repos/facebook/Shimmer","labels_url":"https://api.github.com/repos/facebook/Shimmer/issues/68/labels{/name}","comments_url":"https://api.github.com/repos/facebook/Shimmer/issues/68/comments","events_url":"https://api.github.com/repos/facebook/Shimmer/issues/68/events","html_url":"https://github.com/facebook/Shimmer/issues/68","id":186005389,"number":68,"title":"ShimmerView does NOT work with Constraints","user":{"login":"Brandon-T","id":1530031,"avatar_url":"https://avatars.githubusercontent.com/u/1530031?v=3","gravatar_id":"","url":"https://api.github.com/users/Brandon-T","html_url":"https://github.com/Brandon-T","followers_url":"https://api.github.com/users/Brandon-T/followers","following_url":"https://api.github.com/users/Brandon-T/following{/other_user}","gists_url":"https://api.github.com/users/Brandon-T/gists{/gist_id}","starred_url":"https://api.github.com/users/Brandon-T/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Brandon-T/subscriptions","organizations_url":"https://api.github.com/users/Brandon-T/orgs","repos_url":"https://api.github.com/users/Brandon-T/repos","events_url":"https://api.github.com/users/Brandon-T/events{/privacy}","received_events_url":"https://api.github.com/users/Brandon-T/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-28T19:43:27Z","updated_at":"2016-10-30T05:02:49Z","closed_at":"2016-10-30T05:02:49Z","body":"I created a UIView. Added it as contentView of the shimmerView.\r\n\r\nshimmerView is constrained to my TableViewCell.contentView  -- left, right, top, bottom.\r\nThe UIView is then constrained to shimmerView -- left, right, top, bottom.\r\n\r\n[shimmerView setShimmering:YES]; then gives the error:\r\n\r\n```\r\n[LayoutConstraints] Unable to simultaneously satisfy constraints.\r\n\tProbably at least one of the constraints in the following list is one you don't want. \r\n\tTry this: \r\n\t\t(1) look at each constraint and try to figure out which you don't expect; \r\n\t\t(2) find the code that added the unwanted constraint or constraints and fix it. \r\n(\r\n    \"<NSLayoutConstraint:0x170284150 V:|-(0)-[UIImageView:0x1008b6b90]   (active, names: '|':UITableViewCellContentView:0x1008b1f10 )>\",\r\n    \"<NSLayoutConstraint:0x1702841f0 UIImageView:0x1008b6b90.height == 175   (active)>\",\r\n    \"<NSLayoutConstraint:0x170284380 V:[UIImageView:0x1008b6b90]-(0)-[FBShimmeringView:0x1008b4de0]   (active)>\",\r\n    \"<NSLayoutConstraint:0x1702843d0 FBShimmeringView:0x1008b4de0.bottom == UITableViewCellContentView:0x1008b1f10.bottom   (active)>\",\r\n    \"<NSLayoutConstraint:0x17409ab80 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x1008b1f10.height == 43.5   (active)>\"\r\n)\r\n```\r\n\r\nIf I go to `FBShimmeringLayer` layoutSubViews and comment out:\r\n\r\n```\r\n_contentLayer.anchorPoint = CGPointMake(0.5, 0.5);\r\n  _contentLayer.bounds = r;\r\n  _contentLayer.position = CGPointMake(CGRectGetMidX(r), CGRectGetMidY(r));\r\n```\r\n\r\nthe errors go away but Shimmering no longer works."},"comment":{"url":"https://api.github.com/repos/facebook/Shimmer/issues/comments/257132317","html_url":"https://github.com/facebook/Shimmer/issues/68#issuecomment-257132317","issue_url":"https://api.github.com/repos/facebook/Shimmer/issues/68","id":257132317,"user":{"login":"grp","id":163390,"avatar_url":"https://avatars.githubusercontent.com/u/163390?v=3","gravatar_id":"","url":"https://api.github.com/users/grp","html_url":"https://github.com/grp","followers_url":"https://api.github.com/users/grp/followers","following_url":"https://api.github.com/users/grp/following{/other_user}","gists_url":"https://api.github.com/users/grp/gists{/gist_id}","starred_url":"https://api.github.com/users/grp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grp/subscriptions","organizations_url":"https://api.github.com/users/grp/orgs","repos_url":"https://api.github.com/users/grp/repos","events_url":"https://api.github.com/users/grp/events{/privacy}","received_events_url":"https://api.github.com/users/grp/received_events","type":"User","site_admin":false},"created_at":"2016-10-30T05:02:49Z","updated_at":"2016-10-30T05:02:49Z","body":"I took a look in the Xcode view debugger, and it looked like the bottom view is positioned and sized correctly. The issue is the subviews of the bottom view. I remembered that autolayout requires geometry methods to be called on `UIView`, rather than `CALayer`, as Shimmer is currently implemented.\r\n\r\nChanging that makes the views appear, but there's still log messages about unsatisfied constraints. Investigating those, it appears the issue is that your constraints setup in `BottomView` require a certain minimum width and height of the `BottomView` to resolve. In a pure-autolayout world, that's OK, because that requirement is factored into constraint resolution. But Shimmer's manual sizing the `BottomView` happens *after* the autolayout pass, so the `BottomView` needs a sufficient initial size.\r\n\r\nIn summary, the two fixes to make this work:\r\n\r\n - In your `LoadingCell.m`, right after creating a `BottomView`, give it an initial size. Note that the size is arbitrary, as long as it's as big as `BottomView`'s layout requires, and that this can't use `-initWithFrame:` because `BottomView` overrides the convenience initializer `-init` instead.\r\n\r\n    ```objective-c\r\n    self.bottomView.frame = CGRectMake(0, 0, 500, 1000);\r\n    ```\r\n\r\n - In Shimmer's `FBShimmeringView.m`, add this method to set the frame of the view instead of the layer:\r\n\r\n   ```objective-c\r\n    - (void)layoutSubviews\r\n    {\r\n      // Autolayout requires these to be set on the UIView, not the CALayer.\r\n      // Do this *before* the layer has a chance to set the properties, as the\r\n      // setters would be ignored (even for autolayout) if set to the same value.\r\n      _contentView.bounds = self.bounds;\r\n      _contentView.center = self.center;\r\n\r\n      [super layoutSubviews];\r\n    }\r\n    ```\r\n\r\n    This is pushed to master as 3589bd7ca0d122fe06792868485d79c622a3f47d."}}
{"actor":{"display_login":"grp"}}