mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-06-04 19:45:35 +08:00
Tests pass, split screen looking good.
This commit is contained in:
2
lib/ProMotion/cocoatouch/SplitViewController.rb
Normal file
2
lib/ProMotion/cocoatouch/SplitViewController.rb
Normal file
@@ -0,0 +1,2 @@
|
||||
class SplitViewController < UISplitViewController
|
||||
end
|
||||
@@ -7,11 +7,11 @@ module ProMotion
|
||||
def application(application, didFinishLaunchingWithOptions:launch_options)
|
||||
return true if RUBYMOTION_ENV == "test"
|
||||
|
||||
Console.log(" Your AppDelegate (usually in app_delegate.rb) needs an on_load(options) method.", with_color: Console::RED_COLOR) unless self.respond_to?("on_load:")
|
||||
Console.log(" Your AppDelegate (usually in app_delegate.rb) needs an on_load(application, options) method.", with_color: Console::RED_COLOR) unless self.respond_to?("on_load:")
|
||||
|
||||
on_load(application, launch_options)
|
||||
|
||||
open_home_screen if has_home_screen
|
||||
open_home_screen if has_home_screen && self.window.nil?
|
||||
|
||||
true
|
||||
end
|
||||
@@ -24,6 +24,11 @@ module ProMotion
|
||||
self.app_delegate.window
|
||||
end
|
||||
|
||||
def home(screen)
|
||||
screen = screen.new if screen.respond_to?(:new)
|
||||
@home_screen = screen
|
||||
end
|
||||
|
||||
def load_root_screen(new_screen)
|
||||
new_screen = new_screen.main_controller if new_screen.respond_to?(:main_controller)
|
||||
|
||||
@@ -32,21 +37,14 @@ module ProMotion
|
||||
self.window.makeKeyAndVisible
|
||||
end
|
||||
|
||||
def open_screen(screen)
|
||||
def open_screen(screen, args={})
|
||||
home(screen)
|
||||
end
|
||||
alias :open :open_screen
|
||||
|
||||
def home(screen)
|
||||
screen = screen.new if screen.respond_to?(:new)
|
||||
@home_screen = screen
|
||||
end
|
||||
|
||||
def open_root_screen(new_screen)
|
||||
home(new_screen)
|
||||
open_home_screen
|
||||
end
|
||||
alias :fresh_start :open_root_screen
|
||||
# TODO: This is ridiculous.
|
||||
alias :open :open_screen
|
||||
alias :open_root_screen :open_screen
|
||||
alias :fresh_start :open_screen
|
||||
|
||||
def open_home_screen
|
||||
get_home_screen.send(:on_load) if get_home_screen.respond_to?(:on_load)
|
||||
|
||||
@@ -81,9 +81,6 @@ module ProMotion
|
||||
nav_controller.pushViewController(vc, animated: true)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
protected
|
||||
|
||||
def setup_screen_for_open(screen, args={})
|
||||
|
||||
@@ -9,17 +9,18 @@ module ProMotion
|
||||
screens.map! { |s| s.respond_to?(:new) ? s.new : s } # Initialize any classes
|
||||
|
||||
screens.each do |s|
|
||||
if s.is_a?(ProMotion::Screen) || s.is_a?(ProMotion::TableScreen) || s.is_a?(ProMotion::ScreenModule)
|
||||
s = s.new if s.respond_to?(:new)
|
||||
s.tabBarItem.tag = tag_index
|
||||
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.main_controller
|
||||
tag_index += 1
|
||||
else
|
||||
Console.log("Non-Screen passed into tab_bar_controller: #{s.to_s}", withColor: Console::RED_COLOR)
|
||||
end
|
||||
s = s.new if s.respond_to?(:new)
|
||||
|
||||
s.tabBarItem.tag = tag_index
|
||||
|
||||
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=")
|
||||
|
||||
vc = s.respond_to?(:main_controller) ? s.main_controller : s
|
||||
view_controllers << vc
|
||||
|
||||
tag_index += 1
|
||||
|
||||
s.on_load if s.respond_to?(:on_load)
|
||||
end
|
||||
|
||||
@@ -33,7 +34,10 @@ module ProMotion
|
||||
# @return [UITabBarController]
|
||||
def open_tab_bar(*screens)
|
||||
tab_bar = tab_bar_controller(*screens)
|
||||
UIApplication.sharedApplication.delegate.load_root_screen(tab_bar)
|
||||
|
||||
a = self.respond_to?(:load_root_screen) ? self : UIApplication.sharedApplication.delegate
|
||||
|
||||
a.load_root_screen(tab_bar)
|
||||
tab_bar
|
||||
end
|
||||
|
||||
|
||||
@@ -1,18 +1,27 @@
|
||||
module ProMotion
|
||||
module SplitScreen
|
||||
def open_split_screen(master, child, args={})
|
||||
def create_split_screen(master, detail, args={})
|
||||
master = master.new if master.respond_to?(:new)
|
||||
child = child.new if child.respond_to?(:new)
|
||||
detail = detail.new if detail.respond_to?(:new)
|
||||
|
||||
split = SplitViewController.alloc.init
|
||||
split.viewControllers = [ master, child ]
|
||||
split.viewControllers = [ master, detail ]
|
||||
split.delegate = self
|
||||
|
||||
open split
|
||||
[master, detail].each do |s|
|
||||
s.split_screen = split if s.respond_to?("split_screen=")
|
||||
s.on_load if s.respond_to?(:on_load)
|
||||
end
|
||||
|
||||
split
|
||||
end
|
||||
|
||||
def open_split_screen(master, detail, args={})
|
||||
split = create_split_screen(master, detail, args)
|
||||
open split, args
|
||||
split
|
||||
end
|
||||
|
||||
# This is why you're using ProMotion. You don't want to write method defs like this.
|
||||
def splitViewController(svc, willHideViewController: vc, withBarButtonItem: button, forPopoverController: pc)
|
||||
button.title = vc.title
|
||||
svc.viewControllers.last.navigationItem.leftBarButtonItem = button;
|
||||
|
||||
@@ -4,8 +4,9 @@ module ProMotion
|
||||
include ProMotion::ScreenElements
|
||||
include ProMotion::SystemHelper
|
||||
include ProMotion::ScreenTabs
|
||||
include ProMotion::SplitScreen if NSBundle.mainBundle.infoDictionary["UIDeviceFamily"].include?("2")
|
||||
|
||||
attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal
|
||||
attr_accessor :parent_screen, :first_screen, :tab_bar_item, :tab_bar, :modal, :split_screen
|
||||
|
||||
def on_create(args = {})
|
||||
unless self.is_a?(UIViewController)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class TestDelegate < ProMotion::Delegate
|
||||
def on_load(app, options)
|
||||
return false
|
||||
end
|
||||
end
|
||||
37
spec/split_screen_in_tab_bar_spec.rb
Normal file
37
spec/split_screen_in_tab_bar_spec.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
describe "split screen in tab bar functionality" do
|
||||
|
||||
before do
|
||||
@app = TestDelegate.new
|
||||
|
||||
@master_screen = HomeScreen.new nav_bar: true
|
||||
@child_screen = BasicScreen.new nav_bar: true
|
||||
|
||||
@split_screen = @app.create_split_screen @master_screen, @child_screen
|
||||
@tab = @app.open_tab_bar @split_screen, HomeScreen, BasicScreen
|
||||
end
|
||||
|
||||
it "should create a UISplitViewController" do
|
||||
@split_screen.is_a?(UISplitViewController).should == true
|
||||
end
|
||||
|
||||
it "should have two viewControllers" do
|
||||
@split_screen.viewControllers.length.should == 2
|
||||
end
|
||||
|
||||
it "should set the root view to the tab bar" do
|
||||
@app.window.rootViewController.should == @tab
|
||||
end
|
||||
|
||||
it "should set the first viewController to HomeScreen" do
|
||||
@split_screen.viewControllers.first.should == @master_screen
|
||||
end
|
||||
|
||||
it "should set the second viewController to BasicScreen" do
|
||||
@split_screen.viewControllers.last.should == @child_screen
|
||||
end
|
||||
|
||||
it "should set the tab bar first viewController to the split screen" do
|
||||
@tab.viewControllers.first.should == @split_screen
|
||||
end
|
||||
|
||||
end
|
||||
@@ -9,6 +9,11 @@ describe "split screen functionality" do
|
||||
@split_screen = @app.open_split_screen @master_screen, @child_screen
|
||||
end
|
||||
|
||||
it "should have created a split screen" do
|
||||
@split_screen.should != nil
|
||||
@split_screen.is_a?(UISplitViewController).should == true
|
||||
end
|
||||
|
||||
it "should have two viewControllers" do
|
||||
@split_screen.viewControllers.length.should == 2
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user