Merge pull request #514 from clearsightstudio/pm_issue_513

When closing to :root, properly trigger `on_return`
This commit is contained in:
Jamon Holmgren
2014-08-02 17:26:21 -07:00
3 changed files with 28 additions and 6 deletions

View File

@@ -47,7 +47,7 @@ module ProMotion
elsif self.navigationController
close_nav_screen args
send_on_return(args) # TODO: this would be better implemented in a callback or view_did_disappear.
send_on_return(args)
else
PM.logger.warn "Tried to close #{self.to_s}; however, this screen isn't modal or in a nav bar."
@@ -138,6 +138,7 @@ module ProMotion
def close_nav_screen(args={})
args[:animated] = true unless args.has_key?(:animated)
if args[:to_screen] == :root
self.parent_screen = self.navigationController.viewControllers.first
self.navigationController.popToRootViewControllerAnimated args[:animated]
elsif args[:to_screen] && args[:to_screen].is_a?(UIViewController)
self.parent_screen = args[:to_screen]

View File

@@ -87,7 +87,8 @@ module ProMotion
def delete_row(index_paths, animation = nil)
deletable_index_paths = []
Array(index_paths).each do |index_path|
index_paths = [index_paths] if index_paths.kind_of?(NSIndexPath)
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

View File

@@ -231,10 +231,6 @@ describe "screen helpers" do
describe "closing a screen" do
before do
@second_screen = BasicScreen.new
end
it "should close a modal screen" do
parent_screen = HomeScreen.new
@screen.parent_screen = parent_screen
@@ -291,6 +287,30 @@ describe "screen helpers" do
@screen.send_on_return key: :value
end
context "there are two parent screens and we're closing to the first" do
it "#send_on_return should pass args to the first screen" do
first_screen = HomeScreen.new(nav_bar: true)
second_screen = first_screen.open(BasicScreen)
second_screen.open @screen
second_screen.stub!(:on_return) { |args| should.flunk "shouldn't call on_return on second_screen!" }
first_screen.mock!(:on_return) { |args| args[:key].should == :value }
@screen.close({ key: :value, to_screen: first_screen })
end
it "#send_on_return should pass args to the first screen with :root" do
first_screen = HomeScreen.new(nav_bar: true)
second_screen = first_screen.open(BasicScreen)
second_screen.open @screen
second_screen.stub!(:on_return) { |args| should.flunk "shouldn't call on_return on second_screen!" }
first_screen.mock!(:on_return) { |args| args[:key].should == :value }
@screen.close({ key: :value, to_screen: :root })
end
end
end
end