mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-06-10 07:20:43 +08:00
Merge branch 'ft_storyboard_support' of https://github.com/marcisme/RubyMotion into marcisme-ft_storyboard_support
This commit is contained in:
@@ -169,6 +169,12 @@ module Bacon
|
||||
# * :tab => true
|
||||
def tests(controller_class, options = {})
|
||||
@controller_class = controller_class
|
||||
@options = {
|
||||
# name of storyboard file in resources directory
|
||||
:storyboard_name => 'MainStoryboard',
|
||||
# id of controller as assigned in Xcode
|
||||
:id => nil
|
||||
}.merge(options)
|
||||
extend Bacon::Functional::API
|
||||
extend Bacon::Functional::ContextExt
|
||||
end
|
||||
@@ -213,7 +219,15 @@ module Bacon
|
||||
attr_accessor :controller
|
||||
|
||||
def controller
|
||||
@controller ||= @controller_class.alloc.init
|
||||
@controller ||= if @options[:id]
|
||||
storyboard.instantiateViewControllerWithIdentifier(@options[:id])
|
||||
else
|
||||
@controller_class.alloc.init
|
||||
end
|
||||
end
|
||||
|
||||
def storyboard
|
||||
@storyboard ||= UIStoryboard.storyboardWithName(@options[:storyboard_name], bundle:nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
39
test/bacon-ui/resources/AlternateStoryboard.storyboard
Normal file
39
test/bacon-ui/resources/AlternateStoryboard.storyboard
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="1.1" toolsVersion="2182" systemVersion="11E53" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="iYx-M1-K9o">
|
||||
<dependencies>
|
||||
<deployment defaultVersion="1296" identifier="iOS"/>
|
||||
<development defaultVersion="4200" identifier="xcode"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1181"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Storyboard View Controller-->
|
||||
<scene sceneID="5s5-nQ-T1a">
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="jox-Vj-je2" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
<viewController storyboardIdentifier="alternate" id="iYx-M1-K9o" customClass="StoryboardViewController" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="U9S-io-QG2">
|
||||
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Hello, RubyMotion" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="10" id="agt-qQ-mcA">
|
||||
<rect key="frame" x="90" y="114" width="141" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Storyboard"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="226" y="274"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<simulatedMetricsContainer key="defaultSimulatedMetrics">
|
||||
<simulatedStatusBarMetrics key="statusBar"/>
|
||||
<simulatedOrientationMetrics key="orientation"/>
|
||||
<simulatedScreenMetrics key="destination"/>
|
||||
</simulatedMetricsContainer>
|
||||
</document>
|
||||
39
test/bacon-ui/resources/MainStoryboard.storyboard
Normal file
39
test/bacon-ui/resources/MainStoryboard.storyboard
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="1.1" toolsVersion="2182" systemVersion="11E53" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="u8W-eB-1Im">
|
||||
<dependencies>
|
||||
<deployment defaultVersion="1296" identifier="iOS"/>
|
||||
<development defaultVersion="4200" identifier="xcode"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1181"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Storyboard View Controller-->
|
||||
<scene sceneID="sGE-Qg-P86">
|
||||
<objects>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="8id-87-1zh" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
<viewController storyboardIdentifier="main" id="u8W-eB-1Im" customClass="StoryboardViewController" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="4Ux-gU-aMu">
|
||||
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<subviews>
|
||||
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Hello, RubyMotion" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="10" id="aBC-K1-IOr">
|
||||
<rect key="frame" x="90" y="84" width="141" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Storyboard"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
|
||||
</view>
|
||||
</viewController>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="322" y="374"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<simulatedMetricsContainer key="defaultSimulatedMetrics">
|
||||
<simulatedStatusBarMetrics key="statusBar"/>
|
||||
<simulatedOrientationMetrics key="orientation"/>
|
||||
<simulatedScreenMetrics key="destination"/>
|
||||
</simulatedMetricsContainer>
|
||||
</document>
|
||||
@@ -38,6 +38,7 @@ end
|
||||
describe "Bacon::Functional::API, concerning continuous gestures" do
|
||||
tests ScrollViewController
|
||||
|
||||
# TODO this spec fails if the Accessibility Inspector is on
|
||||
it "creates 'pinch open' and 'pinch close' gesture events" do
|
||||
before = controller.scrollView.zoomScale
|
||||
pinch_open 'Scroll view'
|
||||
@@ -67,6 +68,7 @@ describe "Bacon::Functional::API, concerning continuous gestures" do
|
||||
pinch_open 'Scroll view'
|
||||
end
|
||||
|
||||
# TODO this spec fails if the Accessibility Inspector is on
|
||||
it "drags from point A to point B" do
|
||||
before = controller.scrollView.contentOffset
|
||||
drag 'Scroll view', :from => CGPointMake(310, 100), :to => CGPointMake(5, 150)
|
||||
@@ -74,6 +76,7 @@ describe "Bacon::Functional::API, concerning continuous gestures" do
|
||||
controller.scrollView.contentOffset.y.should < before.y
|
||||
end
|
||||
|
||||
# TODO this spec fails if the Accessibility Inspector is on
|
||||
it "drags along the specified list of points" do
|
||||
view = controller.scrollView
|
||||
before = view.contentOffset
|
||||
|
||||
47
test/bacon-ui/spec/storyboard_spec.rb
Normal file
47
test/bacon-ui/spec/storyboard_spec.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
class StoryboardViewController < UIViewController
|
||||
|
||||
# The view associated with this controller in the storyboard has a single
|
||||
# UILabel with an accessibility label of 'Storyboard' and a text value of
|
||||
# 'Hello, Rubymotion'
|
||||
|
||||
def viewDidLoad
|
||||
label = UILabel.alloc.init
|
||||
label.text = 'Code'
|
||||
view.addSubview(label)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "Storyboard support when not used" do
|
||||
tests StoryboardViewController
|
||||
|
||||
it "does not load from storyboard without an id" do
|
||||
labels = views(UILabel)
|
||||
labels.count.should == 1
|
||||
labels.first.text.should == 'Code'
|
||||
end
|
||||
end
|
||||
|
||||
shared "a controller from a storyboard" do
|
||||
it "has the label defined in the storyboard" do
|
||||
labels = views(UILabel)
|
||||
labels.count.should == 2
|
||||
view('Storyboard').text.should == 'Hello, RubyMotion'
|
||||
end
|
||||
end
|
||||
|
||||
describe "Storyboard support defaults" do
|
||||
tests StoryboardViewController, :id => 'main'
|
||||
|
||||
it "uses MainStoryboard if no name is provided" do
|
||||
@options[:storyboard_name].should == 'MainStoryboard'
|
||||
end
|
||||
|
||||
behaves_like "a controller from a storyboard"
|
||||
end
|
||||
|
||||
describe "Storyboard support with named storyboard" do
|
||||
tests StoryboardViewController, :storyboard_name => 'AlternateStoryboard', :id => 'alternate'
|
||||
|
||||
behaves_like "a controller from a storyboard"
|
||||
end
|
||||
Reference in New Issue
Block a user