Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix :insert_mode => :button bug #24

Merged
merged 1 commit into from
Nov 20, 2015

Conversation

jeffcarbs
Copy link
Contributor

This is a fix for #23 (cc @bmichotte)

Setting :insert_mode to :button was causing a crash. Here was the issue:

This gem was monkey patching sectionOptions to return the Ruby object's options instance variable. However, sectionOptions was being called in the Obj-C section initializer (XLFormSectionDescriptor.formSectionWithTitle) BEFORE we were able to set options on the ruby object.

Why was this only an issue with the :button option? Well in that Obj-C initializer there's a call to canInsertUsingButton:

That method is a two-part conditional. The first is is the insert mode set to button? and the second is do the section options indicate that I can insert?. The second part was where the crash was occurring but it was never getting there because the first part was evaluating to false.

The changes here:

  • Stop monkey-patching sectionOptions. I couldn't see any reason this gem needed to be doing that.
  • Took out the setter/getter for section#options. The custom setter was unnecessary since we're already parsing the options in the only spot where we're calling that setter. And then if we don't need a custom setter, both the setter/getter are redundant because options is an attr_accessor.

@bmichotte
Copy link
Owner

I'm ok for everything, except the sectionOptions. I added this override mainly for reasons like #3 where we need a way to change the options elsewhere (look at the exemple with the gif) and I didn't think using sectionOptions with the objc values is a good thing.

Maybe, we can keep the options as an alias for sectionOptions with something like

 def options=(value)        
   self.sectionOptions = self.class.parse_section_options(value)        
end     
alias :options :sectionOptions

What do you think ?

@jeffcarbs
Copy link
Contributor Author

Ah I didn't consider modifying the options on-the-fly. I think I've got something working based on your suggestion. Going to clean it up and push and update.

Setting :insert_mode to :button was causing a crash. Here was the
issue:

This gem was monkey patching sectionOptions to return the Ruby
object's `options` instance variable. However, sectionOptions was
being called from the Obj-C section initializer
(XLFormSectionDescriptor.formSectionWithTitle) BEFORE we were able to
set `options` on the ruby object. So it was

Why was this only an issue with the :button option? Well:
In that Obj-C initializer there's a call to canInsertUsingButton:
- https://github.com/xmartlabs/XLForm/blob/master/XLForm/XL/Descriptors/XLFormSectionDescriptor.m#L85
- https://github.com/xmartlabs/XLForm/blob/master/XLForm/XL/Descriptors/XLFormSectionDescriptor.m#L322-L325

That method is a two-part conditional. The first is 'is the insert
mode set to button?' and the second is 'do the section options indicate that
I can insert'. The second part was where the crash was occurring but
it was never getting there because of the first part was evaluating to
false.

The main change here is to update our `sectionOptions` monkeypatch
to use the ruby instance variable options if set but otherwise
fallback to the initial value.
@jeffcarbs
Copy link
Contributor Author

@bmichotte - check the updated code. I've tested locally that it works with the example you gave in #3 and it still fixes the main bug 👍

bmichotte added a commit that referenced this pull request Nov 20, 2015
Fix :insert_mode => :button bug
@bmichotte bmichotte merged commit e846112 into bmichotte:master Nov 20, 2015
@bmichotte
Copy link
Owner

Thanks @jcarbo !

@jeffcarbs jeffcarbs deleted the bug/insert-mode branch November 20, 2015 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants