HipByte / Flow

Cross-platform libraries for RubyMotion
BSD 2-Clause "Simplified" License
141 stars 29 forks source link

UI layout throws exception on Android but not iOS #68

Open amirrajan opened 7 years ago

amirrajan commented 7 years ago
border = UI::View.new

{
  background_color: :black,
  width: 50,
  height: 50,
  align_self: :center
}.each do |k, v|
    border.send("#{k}=", v)
  end
end

view.add_child border
view.update_layout

This however works:

border = UI::View.new

{
  background_color: :black,
  width: 50,
  height: 50,
  align_self: :center
}.each do |k, v|
    if v == :center
      border.send("#{k}=", :center)
    else
      border.send("#{k}=", v)
    end
  end
end

view.add_child border
view.update_layout

The following properties would be impacted because of this (I think):

jjaffeux commented 7 years ago

I think there's probably a bug in:

#define define_property_sym(name, count) \
    static VALUE node_##name##s[count] = { Qnil } ; \
    static VALUE \
    node_##name##_get(VALUE rcv, SEL sel) \
    { \
        int value = NODE(rcv)->node->style.name; \
    if (value >= count) { \
        rb_raise(rb_eArgError, "incorrect value for %s", #name); \
    } \
        return node_##name##s[value]; \
    } \
    static VALUE \
    node_##name##_set(VALUE rcv, SEL sel, VALUE value) \
    { \
    struct ruby_css_node *node = NODE(rcv); \
        for (int i = 0; i < count; i++) { \
        if (node_##name##s[i] == value) { \
        (*(int *)&node->node->style.name) = i; \
        return value; \
        } \
    } \
    rb_raise(rb_eArgError, "incorrect value for %s", #name); \
    }

more exactly:

    static VALUE \
    node_##name##_set(VALUE rcv, SEL sel, VALUE value) \
    { \
    struct ruby_css_node *node = NODE(rcv); \
        for (int i = 0; i < count; i++) { \
        if (node_##name##s[i] == value) { \
        (*(int *)&node->node->style.name) = i; \
        return value; \
        } \
    } \
    rb_raise(rb_eArgError, "incorrect value for %s", #name); \
    }