Giter Club home page Giter Club logo

Comments (4)

Brandon-T avatar Brandon-T commented on July 25, 2024 1

This works. However, you cannot use UITableViewAutomaticDimension with the above. For example, if you constrained [shimmerView.heightAnchor constraintGreaterThanOrEqualToConstant:50.0].active = YES and made the UITableView height dynamic, you will get more constraint problems. However if you did the same to bottomView, it will work just fine.

I will be using a static height anyway so it doesn't matter, but I just thought I'd mention it in case someone came along with the same issue.

from shimmer.

grp avatar grp commented on July 25, 2024

You don't need to constrain the size of the content view: it is automatically sized to match the shimmer view, through the lines of code you showed above.

Does it work without that constraint?

from shimmer.

Brandon-T avatar Brandon-T commented on July 25, 2024

No it doesn't work without that constraint. Instead it doesn't display at all.

With FBShimmeringView: http://imgur.com/50W0YOc
Without FBShimmeringView: http://imgur.com/v2hB2Qw

I created a sample test project to show the issue: https://github.com/Brandon-T/FBShimmerTest/tree/master/FacebookShimmerTest

In the LoadingCell class I added a macro #define kDisableFBShimmering. If it is defined, then you can see everything works perfectly. The views get displayed. Console does not log any errors.

However, when I comment it out (enable FBShimmering), you can see the console spitting out a lot of errors and nothing gets disabled on screen.

from shimmer.

grp avatar grp commented on July 25, 2024

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.

Changing 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 of the BottomView happens after the autolayout pass, so the BottomView needs a sufficient initial size.

In summary, the two fixes to make this work:

  • 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.

    self.bottomView.frame = CGRectMake(0, 0, 500, 1000);

    Alternatively, you could add the constraints in BottomView later, after initialization, when the view has a correct size.

  • In Shimmer's FBShimmeringView.m, add this method to set the frame of the view instead of the layer:

    - (void)layoutSubviews
    {
      // Autolayout requires these to be set on the UIView, not the CALayer.
      // Do this *before* the layer has a chance to set the properties, as the
      // setters would be ignored (even for autolayout) if set to the same value.
      _contentView.bounds = self.bounds;
      _contentView.center = self.center;
    
      [super layoutSubviews];
    }

    This is pushed to master as 3589bd7.

from shimmer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.