mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-05-30 00:30:40 +08:00
Merge pull request #165 from clearsightstudio/refactor_folder_structure
Refactor folder structure, remove pm_main_controller monkey-patch
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
class SplitViewController < UISplitViewController
|
||||
def master_screen
|
||||
s = self.viewControllers.first
|
||||
s.respond_to?(:visibleViewController) ? s.visibleViewController : s
|
||||
end
|
||||
def detail_screen
|
||||
s = self.viewControllers.last
|
||||
s.respond_to?(:visibleViewController) ? s.visibleViewController : s
|
||||
end
|
||||
def master_screen=(s)
|
||||
self.viewControllers = [s.pm_main_controller, self.viewControllers.last]
|
||||
end
|
||||
def detail_screen=(s)
|
||||
# set the button from the old detail screen to the new one
|
||||
button = detail_screen.navigationItem.leftBarButtonItem
|
||||
s.navigationItem.leftBarButtonItem = button
|
||||
module ProMotion
|
||||
class SplitViewController < UISplitViewController
|
||||
def master_screen
|
||||
s = self.viewControllers.first
|
||||
s.respond_to?(:visibleViewController) ? s.visibleViewController : s
|
||||
end
|
||||
|
||||
def detail_screen
|
||||
s = self.viewControllers.last
|
||||
s.respond_to?(:visibleViewController) ? s.visibleViewController : s
|
||||
end
|
||||
|
||||
def master_screen=(s)
|
||||
self.viewControllers = [ (s.navigationController || s), self.viewControllers.last]
|
||||
end
|
||||
|
||||
def detail_screen=(s)
|
||||
# set the button from the old detail screen to the new one
|
||||
button = detail_screen.navigationItem.leftBarButtonItem
|
||||
s.navigationItem.leftBarButtonItem = button
|
||||
|
||||
self.viewControllers = [self.viewControllers.first, s.pm_main_controller]
|
||||
self.viewControllers = [self.viewControllers.first, (s.navigationController || s)]
|
||||
end
|
||||
|
||||
def screens=(s_array)
|
||||
self.viewControllers = s_array
|
||||
end
|
||||
end
|
||||
def screens=(s_array)
|
||||
self.viewControllers = s_array
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,6 +15,5 @@ module ProMotion
|
||||
self.imageView.frame = CGRectInset(f, size_inset_x, size_inset_y)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
module ProMotion
|
||||
module ViewControllerModule
|
||||
def pm_main_controller
|
||||
navigationController || self
|
||||
end
|
||||
alias_method :main_controller, :pm_main_controller
|
||||
end
|
||||
end
|
||||
|
||||
UIViewController.send :include, ProMotion::ViewControllerModule
|
||||
@@ -16,7 +16,7 @@ module ProMotion
|
||||
s.parent_screen = self if self.is_a?(UIViewController) && s.respond_to?("parent_screen=")
|
||||
s.tab_bar = tab_bar_controller if s.respond_to?("tab_bar=")
|
||||
|
||||
view_controllers << s.pm_main_controller
|
||||
view_controllers << (s.navigationController || s)
|
||||
|
||||
tag_index += 1
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ module ProMotion
|
||||
self.home_screen = screen
|
||||
|
||||
self.window ||= self.ui_window.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
||||
self.window.rootViewController = screen.pm_main_controller
|
||||
self.window.rootViewController = (screen.navigationController || screen)
|
||||
self.window.makeKeyAndVisible
|
||||
|
||||
end
|
||||
|
||||
@@ -1,54 +1,56 @@
|
||||
class MapScreenAnnotation
|
||||
module ProMotion
|
||||
class MapScreenAnnotation
|
||||
|
||||
#Creates the new crime object
|
||||
def initialize(params = {})
|
||||
@params = params
|
||||
set_defaults
|
||||
#Creates the new crime object
|
||||
def initialize(params = {})
|
||||
@params = params
|
||||
set_defaults
|
||||
|
||||
unless @params[:latitude] && @params[:longitude]
|
||||
PM.logger.error("You are required to specify :latitude and :longitude for annotations.")
|
||||
return nil
|
||||
unless @params[:latitude] && @params[:longitude]
|
||||
PM.logger.error("You are required to specify :latitude and :longitude for annotations.")
|
||||
return nil
|
||||
end
|
||||
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
|
||||
end
|
||||
@coordinate = CLLocationCoordinate2D.new(@params[:latitude], @params[:longitude])
|
||||
end
|
||||
|
||||
def set_defaults
|
||||
@params = {
|
||||
title: "Title",
|
||||
pin_color: MKPinAnnotationColorRed,
|
||||
identifier: "Annotation-#{@params[:pin_color]}",
|
||||
show_callout: true,
|
||||
animates_drop: false
|
||||
}.merge(@params)
|
||||
end
|
||||
|
||||
def title
|
||||
@params[:title]
|
||||
end
|
||||
|
||||
def subtitle
|
||||
@params[:subtitle] ||= nil
|
||||
end
|
||||
|
||||
def coordinate
|
||||
@coordinate
|
||||
end
|
||||
|
||||
def cllocation
|
||||
CLLocation.alloc.initWithLatitude(@params[:latitude], longitude:@params[:longitude])
|
||||
end
|
||||
|
||||
def setCoordinate(new_coordinate);
|
||||
if new_coordinate.is_a? Hash
|
||||
@coordinate = CLLocationCoordinate2D.new(new_coordinate[:latitude], new_coordinate[:longitude])
|
||||
else
|
||||
@coordinate = new_coordinate
|
||||
def set_defaults
|
||||
@params = {
|
||||
title: "Title",
|
||||
pin_color: MKPinAnnotationColorRed,
|
||||
identifier: "Annotation-#{@params[:pin_color]}",
|
||||
show_callout: true,
|
||||
animates_drop: false
|
||||
}.merge(@params)
|
||||
end
|
||||
end
|
||||
|
||||
# Allows for retrieving your own custom values on the annotation
|
||||
def annotation_params
|
||||
@params
|
||||
end
|
||||
def title
|
||||
@params[:title]
|
||||
end
|
||||
|
||||
def subtitle
|
||||
@params[:subtitle] ||= nil
|
||||
end
|
||||
|
||||
def coordinate
|
||||
@coordinate
|
||||
end
|
||||
|
||||
def cllocation
|
||||
CLLocation.alloc.initWithLatitude(@params[:latitude], longitude:@params[:longitude])
|
||||
end
|
||||
|
||||
def setCoordinate(new_coordinate);
|
||||
if new_coordinate.is_a? Hash
|
||||
@coordinate = CLLocationCoordinate2D.new(new_coordinate[:latitude], new_coordinate[:longitude])
|
||||
else
|
||||
@coordinate = new_coordinate
|
||||
end
|
||||
end
|
||||
|
||||
# Allows for retrieving your own custom values on the annotation
|
||||
def annotation_params
|
||||
@params
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ module ProMotion
|
||||
push_view_controller screen
|
||||
|
||||
else
|
||||
open_root_screen screen.pm_main_controller
|
||||
open_root_screen (screen.navigationController || screen)
|
||||
|
||||
end
|
||||
|
||||
@@ -120,7 +120,7 @@ module ProMotion
|
||||
end
|
||||
|
||||
def present_modal_view_controller(screen, animated)
|
||||
self.presentModalViewController(screen.pm_main_controller, animated:animated)
|
||||
self.presentModalViewController((screen.navigationController || screen), animated:animated)
|
||||
end
|
||||
|
||||
def present_view_controller_in_tab_bar_controller(screen, tab_name)
|
||||
|
||||
@@ -7,7 +7,7 @@ describe "ProMotion::TestMapScreen functionality" do
|
||||
@map ||= TestMapScreen.new(nav_bar: true)
|
||||
@map.on_load
|
||||
@map.will_appear
|
||||
@map.main_controller
|
||||
@map.navigation_controller
|
||||
end
|
||||
|
||||
after do
|
||||
|
||||
@@ -5,7 +5,7 @@ describe "ProMotion::Screen functional" do
|
||||
def controller
|
||||
rotate_device to: :portrait, button: :bottom
|
||||
@controller ||= FunctionalScreen.new(nav_bar: true)
|
||||
@controller.main_controller
|
||||
@controller.navigation_controller
|
||||
end
|
||||
|
||||
after do
|
||||
|
||||
@@ -5,7 +5,7 @@ describe "Searchable table spec" do
|
||||
def controller
|
||||
@controller ||= TableScreenSearchable.new(nav_bar: true)
|
||||
@controller.on_load
|
||||
@controller.main_controller
|
||||
@controller.navigation_controller
|
||||
end
|
||||
|
||||
it "should be rotated in portrait mode" do
|
||||
|
||||
@@ -6,7 +6,7 @@ describe "ProMotion::TestTableScreen functionality" do
|
||||
rotate_device to: :portrait, button: :bottom
|
||||
@controller ||= TestTableScreen.new(nav_bar: true)
|
||||
@controller.on_load
|
||||
@controller.main_controller
|
||||
@controller.navigation_controller
|
||||
end
|
||||
|
||||
after do
|
||||
|
||||
@@ -5,7 +5,7 @@ describe "ProMotion::TestWebScreen functionality" do
|
||||
def controller
|
||||
rotate_device to: :portrait, button: :bottom
|
||||
@webscreen ||= TestWebScreen.new(nav_bar: true)
|
||||
@webscreen.main_controller
|
||||
@webscreen.navigation_controller
|
||||
end
|
||||
|
||||
after do
|
||||
@@ -18,7 +18,7 @@ describe "ProMotion::TestWebScreen functionality" do
|
||||
@webscreen.set_content(file_name)
|
||||
|
||||
@loaded_file = File.read(File.join(NSBundle.mainBundle.resourcePath, file_name))
|
||||
wait 0.5 do
|
||||
wait 1.0 do
|
||||
@webscreen.html.should == @loaded_file
|
||||
end
|
||||
end
|
||||
|
||||
@@ -121,11 +121,11 @@ describe "screen helpers" do
|
||||
new_screen.nav_bar?.should == true
|
||||
end
|
||||
|
||||
it "should present the #main_controller when showing a modal screen" do
|
||||
it "should present the navigationController when showing a modal screen" do
|
||||
new_screen = @screen.send(:set_up_screen_for_open, BasicScreen, modal: true)
|
||||
|
||||
@screen.mock!('presentModalViewController:animated:') do |vc, animated|
|
||||
vc.should == new_screen.main_controller
|
||||
vc.should == (new_screen.navigationController || new_screen)
|
||||
animated.should == true
|
||||
end
|
||||
@screen.send(:present_modal_view_controller, new_screen, true)
|
||||
|
||||
@@ -109,30 +109,15 @@ describe "screen properties" do
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe "pm_main_controller" do
|
||||
|
||||
it "should return the navigation controller wrapper" do
|
||||
@screen.pm_main_controller.should.be.instance_of ProMotion::NavigationController
|
||||
end
|
||||
|
||||
it "should return itself when screen is a plain UIViewController" do
|
||||
vc = UIViewController.alloc.initWithNibName(nil, bundle: nil)
|
||||
vc.respond_to?(:pm_main_controller).should == true
|
||||
vc.pm_main_controller.should == vc
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
describe "navigation controller behavior" do
|
||||
|
||||
it "should have a nav bar" do
|
||||
@screen.nav_bar?.should == true
|
||||
end
|
||||
|
||||
it "#main_controller should return a navigation controller" do
|
||||
@screen.main_controller.should.be.instance_of ProMotion::NavigationController
|
||||
it "#navigation_controller should return a navigation controller" do
|
||||
@screen.navigation_controller.should.be.instance_of ProMotion::NavigationController
|
||||
@screen.navigationController.should.be.instance_of ProMotion::NavigationController
|
||||
end
|
||||
|
||||
it "have a right bar button item" do
|
||||
|
||||
@@ -38,12 +38,12 @@ describe "split screen in tab bar functionality" do
|
||||
|
||||
it "should set the first viewController to HomeScreen's main controller" do
|
||||
@split_screen.master_screen.should == @master_screen
|
||||
@split_screen.viewControllers.first.should == @master_screen.pm_main_controller
|
||||
@split_screen.viewControllers.first.should == (@master_screen.navigationController || @master_screen)
|
||||
end
|
||||
|
||||
it "should set the second viewController to BasicScreen's main controller" do
|
||||
@split_screen.detail_screen.should == @detail_screen
|
||||
@split_screen.viewControllers.last.should == @detail_screen.pm_main_controller
|
||||
@split_screen.viewControllers.last.should == (@detail_screen.navigationController || @detail_screen)
|
||||
end
|
||||
|
||||
it "should set the tab bar first viewController to the split screen" do
|
||||
|
||||
@@ -17,15 +17,15 @@ describe "split screen `open` functionality" do
|
||||
it "should open a new screen in the detail view" do
|
||||
@master_screen.open @detail_screen_2, in_detail: true
|
||||
@split_screen.detail_screen.should == @detail_screen_2
|
||||
@split_screen.viewControllers.first.should == @master_screen.pm_main_controller
|
||||
@split_screen.viewControllers.last.should == @detail_screen_2.pm_main_controller
|
||||
@split_screen.viewControllers.first.should == (@master_screen.navigationController || @master_screen)
|
||||
@split_screen.viewControllers.last.should == (@detail_screen_2.navigationController || @detail_screen_2)
|
||||
end
|
||||
|
||||
it "should open a new screen in the master view" do
|
||||
@detail_screen_1.open @detail_screen_2, in_master: true
|
||||
@split_screen.master_screen.should == @detail_screen_2
|
||||
@split_screen.viewControllers.first.should == @detail_screen_2.pm_main_controller
|
||||
@split_screen.viewControllers.last.should == @detail_screen_1.pm_main_controller
|
||||
@split_screen.viewControllers.first.should == (@detail_screen_2.navigationController || @detail_screen_2)
|
||||
@split_screen.viewControllers.last.should == (@detail_screen_1.navigationController || @detail_screen_1)
|
||||
end
|
||||
|
||||
it "should open a new screen in the master view's navigation controller" do
|
||||
@@ -37,7 +37,7 @@ describe "split screen `open` functionality" do
|
||||
it "should open a new modal screen in the detail view" do
|
||||
@detail_screen_1.open @detail_screen_2, modal: true
|
||||
@split_screen.detail_screen.should == @detail_screen_1
|
||||
@detail_screen_1.presentedViewController.should == @detail_screen_2.pm_main_controller
|
||||
@detail_screen_1.presentedViewController.should == (@detail_screen_2.navigationController || @detail_screen_2)
|
||||
end
|
||||
|
||||
it "should not interfere with normal non-split screen navigation" do
|
||||
|
||||
@@ -28,12 +28,12 @@ describe "split screen functionality" do
|
||||
|
||||
it "should set the first viewController to MasterScreen" do
|
||||
@split_screen.master_screen.should == @master_screen
|
||||
@split_screen.viewControllers.first.should == @master_screen.pm_main_controller
|
||||
@split_screen.viewControllers.first.should == (@master_screen.navigationController || @master_screen)
|
||||
end
|
||||
|
||||
it "should set the second viewController to DetailScreen" do
|
||||
@split_screen.detail_screen.should == @detail_screen
|
||||
@split_screen.viewControllers.last.should == @detail_screen.pm_main_controller
|
||||
@split_screen.viewControllers.last.should == (@detail_screen.navigationController || @detail_screen)
|
||||
end
|
||||
|
||||
it "should set the title on both screens" do
|
||||
|
||||
Reference in New Issue
Block a user