mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-05-28 15:44:31 +08:00
Merge pull request #594 from clearsightstudio/bugfix/issue_ios8_splitview
iOS 8 SplitViewController issues (and spec updates)
This commit is contained in:
@@ -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:
|
||||
|
||||
3
Rakefile
3
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
|
||||
|
||||
@@ -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={})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user