mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-05-26 23:30:38 +08:00
Merge pull request #514 from clearsightstudio/pm_issue_513
When closing to :root, properly trigger `on_return`
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user