colinta / teacup

This project has been sunset in favor of MotionKit
github.com/motion-kit/motion-kit
Other
602 stars 85 forks source link

Calling systomFontOfSize on UIFont from Teacup::Stylesheet.new block #27

Closed colinta closed 12 years ago

colinta commented 12 years ago

Can someone try and reproduce this bug?

If I set font: UIFont.systemFontOfSize(17) in a stylesheet, the simulator crashes.

If, instead, I move the instance_eval &block code in stylesheet.rb to the query method, it works fine.

def initialize(name=nil, &block)
  if name
    @name = name.to_sym
    Teacup::Stylesheet[@name] = self
  end

  # we just store the block for now, because some classes are not "ready"
  # for instance, calling `UIFont.systemFontOfSize()` will cause the
  # application to crash.  We will lazily-load this block in `query`, and
  # then set it to nil.
  @block = block
end

def query(stylename)
  if @block
    instance_eval &@block
    @block = nil
  end
  # ...

Very odd, and I don't like the fix, but if this is happening elsewhere, it'll have to stay in some form. O_o?

colinta commented 12 years ago

this spec wouldn't pass anymore:

imported_anonymously = Teacup::Stylesheet.new do
  style :label,
    title: "Imported anonymously"
end

@anonymous_importer = Teacup::Stylesheet.new do
  import imported_anonymously

  style :label,
    backgroundColor: :blue
end

how do we feel about that?