diff --git a/.travis.yml b/.travis.yml index 13a5333..ece0503 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ before_install: - (ruby --version) - sudo chown -R travis ~/Library/RubyMotion - mkdir -p ~/Library/RubyMotion/build - - sudo motion update --cache-version=2.38 + - sudo motion update --cache-version=3.2 gemfile: - Gemfile script: diff --git a/Rakefile b/Rakefile index 7becf13..68348e2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -RM_VERSION = "2.38" # Update .travis.yml too +RM_VERSION = "3.2" # Update .travis.yml too unless File.exist?("/Library/RubyMotion#{RM_VERSION}/lib") abort "Couldn't find RubyMotion #{RM_VERSION}. Run `sudo motion update --cache-version=#{RM_VERSION}`." end @@ -14,6 +14,7 @@ Motion::Project::App.setup do |app| app.device_family = [ :ipad ] # so we can test split screen capability app.detect_dependencies = false app.info_plist["UIViewControllerBasedStatusBarAppearance"] = false + app.deployment_target = "7.1" # Adding file dependencies for tests # Not too many dependencies necessary diff --git a/app/test_screens/test_table_screen.rb b/app/test_screens/test_table_screen.rb index fec0fb3..ed03b33 100644 --- a/app/test_screens/test_table_screen.rb +++ b/app/test_screens/test_table_screen.rb @@ -65,24 +65,24 @@ class TestTableScreen < ProMotion::TableScreen action: :increment_counter_by, arguments: { number: 10 } }] + },{ + title: "Moveable Tests", + cells: [{ + title: 'Cell 1', + moveable: :section },{ - title: "Moveable Tests", - cells: [{ - title: 'Cell 1', - moveable: :section - },{ - title: 'Cell 2', - moveable: true - },{ - title: 'Cell 3' - },{ - title: 'Cell 4', - moveable: true - },{ - title: 'Cell 5', - moveable: false - }] - }] + title: 'Cell 2', + moveable: true + },{ + title: 'Cell 3' + },{ + title: 'Cell 4', + moveable: true + },{ + title: 'Cell 5', + moveable: false + }] + }] end def edit_profile(args={}) diff --git a/lib/ProMotion/ipad/split_screen.rb b/lib/ProMotion/ipad/split_screen.rb index dedd2f5..6ac8d17 100644 --- a/lib/ProMotion/ipad/split_screen.rb +++ b/lib/ProMotion/ipad/split_screen.rb @@ -16,15 +16,35 @@ module ProMotion # UISplitViewControllerDelegate methods - def splitViewController(svc, willHideViewController: vc, withBarButtonItem: button, forPopoverController: pc) + # iOS 7 and below + def splitViewController(svc, willHideViewController: vc, withBarButtonItem: button, forPopoverController: _) + button ||= self.displayModeButtonItem if self.respond_to?(:displayModeButtonItem) + return unless button button.title = @pm_split_screen_button_title || vc.title svc.detail_screen.navigationItem.leftBarButtonItem = button end - def splitViewController(svc, willShowViewController: vc, invalidatingBarButtonItem: barButtonItem) + def splitViewController(svc, willShowViewController: _, invalidatingBarButtonItem: _) svc.detail_screen.navigationItem.leftBarButtonItem = nil end + # iOS 8 and above + def splitViewController(svc, willChangeToDisplayMode: display_mode) + vc = svc.viewControllers.first + vc = vc.topViewController if vc.respond_to?(:topViewController) + case display_mode + # when UISplitViewControllerDisplayModeAutomatic then do_something? + when UISplitViewControllerDisplayModePrimaryHidden + self.splitViewController(svc, willHideViewController: vc, withBarButtonItem: nil, forPopoverController: nil) + # TODO: Add `self.master_screen.try(:will_hide_split_screen)` or similar? + when UISplitViewControllerDisplayModeAllVisible + self.splitViewController(svc, willShowViewController: vc, invalidatingBarButtonItem: nil) + # TODO: Add `self.master_screen.try(:will_show_split_screen)` or similar? + # when UISplitViewControllerDisplayModePrimaryOverlay + # TODO: Add `self.master_screen.try(:will_show_split_screen_overlay)` or similar? + end + end + private def split_screen_controller(master, detail) diff --git a/lib/ProMotion/screen/screen_module.rb b/lib/ProMotion/screen/screen_module.rb index 712dc26..98022fd 100644 --- a/lib/ProMotion/screen/screen_module.rb +++ b/lib/ProMotion/screen/screen_module.rb @@ -166,6 +166,10 @@ module ProMotion return self.view_or_self.frame end + def try(method, *args) + send(method, *args) if respond_to?(method) + end + private def apply_properties(args) @@ -184,10 +188,6 @@ module ProMotion end end - def try(method, *args) - send(method, *args) if respond_to?(method) - end - # Class methods module ClassMethods def title(t=nil) diff --git a/lib/ProMotion/table/table.rb b/lib/ProMotion/table/table.rb index f8b48f5..1eadfef 100644 --- a/lib/ProMotion/table/table.rb +++ b/lib/ProMotion/table/table.rb @@ -118,8 +118,7 @@ module ProMotion def delete_row(index_paths, animation = nil) deletable_index_paths = [] - index_paths = [index_paths] if index_paths.kind_of?(NSIndexPath) - index_paths.each do |index_path| + Array(index_paths).each do |index_path| delete_cell = false delete_cell = send(:on_cell_deleted, self.promotion_table_data.cell(index_path: index_path)) if self.respond_to?("on_cell_deleted:") unless delete_cell == false @@ -145,8 +144,7 @@ module ProMotion end def update_table_data(args = {}) - # Try and detect if the args param is a NSIndexPath or an array of them - args = { index_paths: args } if args.is_a?(NSIndexPath) || (args.is_a?(Array) && array_all_members_of?(args, NSIndexPath)) + args = { index_paths: args } unless args.is_a?(Hash) self.update_table_view_data(self.table_data, args) self.promotion_table_data.search(search_string) if searching? @@ -325,7 +323,14 @@ module ProMotion end def row_height(height, args={}) - height = UITableViewAutomaticDimension if height == :auto + if height == :auto + if UIDevice.currentDevice.systemVersion.to_f < 8.0 + height = args[:estimated] || 44.0 + PM.logger.warn "Using `row_height :auto` is not supported in iOS 7 apps. Setting to #{height}." + else + height = UITableViewAutomaticDimension + end + end args[:estimated] ||= height unless height == UITableViewAutomaticDimension @row_height = { height: height, estimated: args[:estimated] || 44.0 } end diff --git a/spec/functional/func_split_screen_spec.rb b/spec/functional/func_split_screen_spec.rb index 0e29562..1d1c77a 100644 --- a/spec/functional/func_split_screen_spec.rb +++ b/spec/functional/func_split_screen_spec.rb @@ -6,11 +6,12 @@ describe "Split screen functionality" do @app ||= TestDelegate.new @master = MasterScreen.new(nav_bar: true) @detail = DetailScreen.new(nav_bar: true) - @controller ||= @app.create_split_screen @master, @detail + @controller ||= @app.create_split_screen @master, @detail, { button_title: "Test Title" } end before do UIView.setAnimationDuration 0.01 + UIView.setAnimationsEnabled false rotate_device to: :landscape, button: :right end @@ -20,56 +21,48 @@ describe "Split screen functionality" do it "should allow opening a detail view from the master view" do - @master.open BasicScreen.new(nav_bar: true), in_detail: true + @master.open BasicScreen.new(nav_bar: true), in_detail: true, animated: false - wait 0.75 do - view("Master").should.be.kind_of UINavigationItemView - view("Basic").should.be.kind_of UINavigationItemView - views(UINavigationItemView).each { |v| v.title.should.not == "Detail" } - end + view("Master").should.be.kind_of UINavigationItemView + view("Basic").should.be.kind_of UINavigationItemView + views(UINavigationItemView).each { |v| v.title.should.not == "Detail" } end it "should allow opening another view from the master view" do - @master.open BasicScreen + @master.open BasicScreen, animated: false - wait 0.75 do - view("Basic").should.be.kind_of UINavigationItemView - view("Detail").should.be.kind_of UINavigationItemView - end + view("Basic").should.be.kind_of UINavigationItemView + view("Detail").should.be.kind_of UINavigationItemView end it "should allow opening a master view from the detail view" do - @detail.open BasicScreen.new(nav_bar: true), in_master: true + @detail.open BasicScreen.new(nav_bar: true), in_master: true, animated: false - wait 0.75 do - view("Basic").should.be.kind_of UINavigationItemView - view("Detail").should.be.kind_of UINavigationItemView - views(UINavigationItemView).each { |v| v.title.should.not == "Master" } - end + view("Basic").should.be.kind_of UINavigationItemView + view("Detail").should.be.kind_of UINavigationItemView + views(UINavigationItemView).each { |v| v.title.should.not == "Master" } end it "should allow opening another view from the detail view" do - @detail.open BasicScreen + @detail.open BasicScreen, animated: false - wait 0.75 do - view("Basic").should.be.kind_of UINavigationItemView - view("Master").should.be.kind_of UINavigationItemView - end + view("Basic").should.be.kind_of UINavigationItemView + view("Master").should.be.kind_of UINavigationItemView end it "should override the title on the button" do rotate_device to: :portrait, button: :bottom - test_title = "Test Title" - @alt_controller = @app.open_split_screen @master, @detail, button_title: test_title - @detail.navigationItem.leftBarButtonItem.title.should == test_title + @detail.navigationItem.should.be.kind_of UINavigationItem + @detail.navigationItem.leftBarButtonItem.should.be.kind_of UIBarButtonItem + @detail.navigationItem.leftBarButtonItem.title.should == "Test Title" end it "should override the default swipe action, that reveals the menu" do diff --git a/spec/functional/func_table_screen_spec.rb b/spec/functional/func_table_screen_spec.rb index 60f85ca..3efa75a 100644 --- a/spec/functional/func_table_screen_spec.rb +++ b/spec/functional/func_table_screen_spec.rb @@ -2,15 +2,11 @@ describe "ProMotion::TableScreen functionality" do tests PM::TestTableScreen def table_screen - @table_screen ||= begin - t = TestTableScreen.new(nav_bar: true) - t.on_load - t - end + @table_screen ||= TestTableScreen.new(nav_bar: true) end def controller - rotate_device to: :portrait, button: :bottom + # rotate_device to: :portrait, button: :bottom table_screen.navigationController end @@ -22,8 +18,6 @@ describe "ProMotion::TableScreen functionality" do TestHelper.ios7 ? "UILabel" : "UITableViewLabel" end - before { UIView.setAnimationDuration 0.01 } - after { @table_screen = nil } it "should have a navigation bar" do diff --git a/spec/helpers/test_helper.rb b/spec/helpers/test_helper.rb index b9d6133..9e8f486 100644 --- a/spec/helpers/test_helper.rb +++ b/spec/helpers/test_helper.rb @@ -13,6 +13,10 @@ class TestHelper UIDevice.currentDevice.systemVersion.to_f >= 8.0 && UIDevice.currentDevice.systemVersion.to_f < 9.0 end + + def self.gte_ios8 + UIDevice.currentDevice.systemVersion.to_f >= 8.0 + end end def silence_warnings(&block) diff --git a/spec/unit/tables/table_module_spec.rb b/spec/unit/tables/table_module_spec.rb index 85733cf..3b7e597 100644 --- a/spec/unit/tables/table_module_spec.rb +++ b/spec/unit/tables/table_module_spec.rb @@ -43,7 +43,7 @@ describe "PM::Table module" do def default_cell_height return UITableViewAutomaticDimension if TestHelper.ios8 - return 44.0 if TestHelper.ios7 + return 97.0 if TestHelper.ios7 # Normally 44, but 97 because of `row_height` designation end def default_header_height @@ -140,7 +140,6 @@ describe "PM::Table module" do @subject.tableView(@subject.table_view, didSelectRowAtIndexPath:ip) tapped_ip = @subject.got_index_path - tapped_ip.should.be.kind_of NSIndexPath tapped_ip.section.should == 6 tapped_ip.row.should == 0 end diff --git a/spec/unit/tables/table_screen_spec.rb b/spec/unit/tables/table_screen_spec.rb index b43d7cd..eb9871b 100644 --- a/spec/unit/tables/table_screen_spec.rb +++ b/spec/unit/tables/table_screen_spec.rb @@ -51,7 +51,8 @@ describe "table screens" do end it "sets the auto row height and estimated row height properly" do - @screen.view.rowHeight.should == UITableViewAutomaticDimension + @screen.view.rowHeight.should == UITableViewAutomaticDimension if TestHelper.gte_ios8 + @screen.view.rowHeight.should == 97 unless TestHelper.gte_ios8 @screen.view.estimatedRowHeight.should == 97 end