rubymotion-community / BubbleWrap

Cocoa wrappers and helpers for RubyMotion (Ruby for iOS and OS X) - Making Cocoa APIs more Ruby like, one API at a time. Fork away and send your pull requests
Other
1.18k stars 208 forks source link

Adds BW::UIActivityViewController for a more Ruby-like interface to activity view controllers #335

Closed markrickert closed 10 years ago

markrickert commented 10 years ago

This is my first attempt. Some guidance on how the DSL should work would be greatly appreciated. I'll write tests once I've nailed down functionality.

Usage:

# Without a completion handler
BW::UIActivityViewController.new(
  items: "Some Text", # or ["Some Text", NSURL.URLWithString('http://www.rubymotion.com')] or a UIImage
  excluded: :add_to_reading_list
)

# With completion handler
BW::UIActivityViewController.new(
  items: "Some Text",
  excluded: [:add_to_reading_list, :print, :air_drop]
) do |activity_type, completed|
  puts "completed with activity: #{activity_type} - finished?: #{completed}"
end

Let me know if i'm on the right track here.

markrickert commented 10 years ago

I just patched BW::Constants.get() so that it doesn't try and bitwise an array of strings like ["com.apple.UIKit.activity.AirDrop", "com.apple.UIKit.activity.Print"]

I suppose the next step could be to have helper methods like BW::UIActivityViewController.email() and BW::UIActivityViewController.airdrop() that only allow that one activity type.

markrickert commented 10 years ago

Huh... Travis returned back this error:

  - should return an array of string constant values [ERROR: NameError - uninitialized constant Kernel::UIActivityTypeAirDrop]
NameError: uninitialized constant Kernel::UIActivityTypeAirDrop
    constants.rb:41:in `get:': .get - should return an array of string constant values
    constants.rb:32:in `get:'
    spec.rb:314:in `block in run_spec_block'
    spec.rb:438:in `execute_block'
    spec.rb:314:in `run_spec_block'
    spec.rb:329:in `run'
222 specifications (496 requirements), 0 failures, 1 errors

Wonder why, when I'm initializing those constants in the module?

markrickert commented 10 years ago

Any feedback on this feature @colinta, @clayallsopp or @supermarin ?

colinta commented 10 years ago

The API looks solid, I wonder if Travis is running an old version, and doesn't have that AirDrop constant...

colinta commented 10 years ago

items: "string" looks funny to me, seems like it should require an array; item: "string" would then delegate to items: [..]

clayallsopp commented 10 years ago

Yeah, +1 on @colinta's thoughts. seems like :items or :item should be valid options, for readability

Also editing the readme would be :+1:

Travis is yelling because on OS X the Airdrop constant doesn't exist; you should do something like this in the specs:

if App.ios?
  it "should bitmask array values" do
   #...
  end
end
markrickert commented 10 years ago

Aha! Thanks for the tip on the tests. I'll try and get it refactored a bit and get the tests working on Travis here in the next few days. FYI, I'm using this code in production in my Textables app to display the UIActivityViewController.

markrickert commented 10 years ago

Is there a preferred way to accept both item and items?

something like:

items = Array(options[:items] || options[:item])

??

clayallsopp commented 10 years ago

Yup, that looks good to me

markrickert commented 10 years ago

Once Travis passes, this is good to go! Working tests: 809 specifications (1202 requirements), 0 failures, 0 errors

markrickert commented 10 years ago

:sparkles: It passed :)

clayallsopp commented 10 years ago

Awesome - update the README as well?

markrickert commented 10 years ago

Done. Added it to the UI section of the readme.

clayallsopp commented 10 years ago

:+1: most excellent, great work!

markrickert commented 10 years ago

Thanks! Glad to contribute!

markrickert commented 10 years ago

:sparkles: YAY!