Adds UIActivityIndicatorView stylers and actions

With tests!
This commit is contained in:
Mark Rickert
2015-03-02 19:05:37 -06:00
parent c9223c1d9a
commit cba4d0dd34
5 changed files with 141 additions and 18 deletions

View File

@@ -155,5 +155,21 @@ module RubyMotionQuery
self
end
# For UIActivityIndicatorViews
def start_animating
selected.each do |view|
view.startAnimating if view.respond_to?(:startAnimating)
end
self
end
# For UIActivityIndicatorViews
def stop_animating
selected.each do |view|
view.stopAnimating if view.respond_to?(:startAnimating)
end
self
end
end
end

View File

@@ -0,0 +1,50 @@
module RubyMotionQuery
module Stylers
class UIActivityIndicatorViewStyler < UIViewStyler
UI_ACTIVITY_INDICATOR_VIEW_STYLES = {
large: UIActivityIndicatorViewStyleWhiteLarge,
white_large: UIActivityIndicatorViewStyleWhiteLarge,
default: UIActivityIndicatorViewStyleWhite,
white: UIActivityIndicatorViewStyleWhite,
gray: UIActivityIndicatorViewStyleGray
}
def start_animating
@view.startAnimating
end
alias :start :start_animating
def stop_animating
@view.stopAnimating
end
alias :stop :stop_animating
def is_animating?
@view.isAnimating
end
alias :animating? :is_animating?
def hides_when_stopped=(value)
@view.hidesWhenStopped = value
end
def hides_when_stopped
@view.hidesWhenStopped
end
def activity_indicator_style=(value)
@view.activityIndicatorViewStyle = UI_ACTIVITY_INDICATOR_VIEW_STYLES[value] || value
end
def activity_indicator_style
@view.activityIndicatorViewStyle
end
def color=(value)
@view.color = value
end
def color
@view.color
end
end
end
end

View File

@@ -97,24 +97,25 @@ module RubyMotionQuery
# memoize this, however if you do that, make sure the dev doesn't retain them in a var
custom_stylers(view) || begin
case view
when UILabel then Stylers::UILabelStyler.new(view)
when UIButton then Stylers::UIButtonStyler.new(view)
when UIImageView then Stylers::UIImageViewStyler.new(view)
when UITableView then Stylers::UITableViewStyler.new(view)
when UISwitch then Stylers::UISwitchStyler.new(view)
when UIDatePicker then Stylers::UIDatePickerStyler.new(view)
when UISegmentedControl then Stylers::UISegmentedControlStyler.new(view)
when UIRefreshControl then Stylers::UIRefreshControlStyler.new(view)
when UIPageControl then Stylers::UIPageControlStyler.new(view)
when UIProgressView then Stylers::UIProgressViewStyler.new(view)
when UISlider then Stylers::UISliderStyler.new(view)
when UIStepper then Stylers::UIStepperStyler.new(view)
when UITabBar then Stylers::UITabBarStyler.new(view)
when UITableViewCell then Stylers::UITableViewCellStyler.new(view)
when UITextView then Stylers::UITextViewStyler.new(view)
when UITextField then Stylers::UITextFieldStyler.new(view)
when UINavigationBar then Stylers::UINavigationBarStyler.new(view)
when UIScrollView then Stylers::UIScrollViewStyler.new(view)
when UILabel then Stylers::UILabelStyler.new(view)
when UIButton then Stylers::UIButtonStyler.new(view)
when UIActivityIndicatorView then Stylers::UIActivityIndicatorViewStyler.new(view)
when UIImageView then Stylers::UIImageViewStyler.new(view)
when UITableView then Stylers::UITableViewStyler.new(view)
when UISwitch then Stylers::UISwitchStyler.new(view)
when UIDatePicker then Stylers::UIDatePickerStyler.new(view)
when UISegmentedControl then Stylers::UISegmentedControlStyler.new(view)
when UIRefreshControl then Stylers::UIRefreshControlStyler.new(view)
when UIPageControl then Stylers::UIPageControlStyler.new(view)
when UIProgressView then Stylers::UIProgressViewStyler.new(view)
when UISlider then Stylers::UISliderStyler.new(view)
when UIStepper then Stylers::UIStepperStyler.new(view)
when UITabBar then Stylers::UITabBarStyler.new(view)
when UITableViewCell then Stylers::UITableViewCellStyler.new(view)
when UITextView then Stylers::UITextViewStyler.new(view)
when UITextField then Stylers::UITextFieldStyler.new(view)
when UINavigationBar then Stylers::UINavigationBarStyler.new(view)
when UIScrollView then Stylers::UIScrollViewStyler.new(view)
# TODO, all the controls are done, but missing some views, add
else
if view.respond_to?(:rmq_styler)

View File

@@ -199,6 +199,11 @@ module RubyMotionQuery
#o.setTitle('Ok', forState: UIControlStateNormal)
o.opaque = true
end
elsif (klass == UIActivityIndicatorView) || klass < UIActivityIndicatorView
klass.alloc.initWithActivityIndicatorStyle(UIActivityIndicatorViewStyleWhite).tap do |o|
o.hidden = false
o.opaque = true
end
elsif reuse_identifier = opts[:reuse_identifier]
style = opts[:cell_style] || UITableViewCellStyleDefault
klass.alloc.initWithStyle(style, reuseIdentifier: reuse_identifier).tap do |o|

View File

@@ -0,0 +1,51 @@
class StyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet
def ui_activity_indicator_view_kitchen_sink(st)
st.hides_when_stopped = true
st.activity_indicator_style = :gray
st.color = color.blue
end
end
describe 'stylers/ui_activity_indicator_view' do
before do
@vc = UIViewController.alloc.init
@vc.rmq.stylesheet = StyleSheetForUIViewStylerTests
@view_klass = UIActivityIndicatorView
end
behaves_like "styler"
it 'should apply a style with every UIImageViewStyler wrapper method' do
view = @vc.rmq.append(@view_klass, :ui_activity_indicator_view_kitchen_sink).get
view.hidesWhenStopped.should == true
view.activityIndicatorViewStyle.should == UIActivityIndicatorViewStyleGray
view.color.should == rmq.color.blue
end
it 'should start and stop animations from the styler' do
view = @vc.rmq.append(@view_klass, :ui_activity_indicator_view_kitchen_sink)
view.style do |st|
st.is_animating?.should == false
st.start_animating
st.is_animating?.should == true
st.stop_animating
st.is_animating?.should == false
end
end
it 'should start and stop animations from a direct action' do
view = @vc.rmq.append(@view_klass, :ui_activity_indicator_view_kitchen_sink)
view.get.isAnimating.should == false
view.start_animating
view.get.isAnimating.should == true
view.stop_animating
view.get.isAnimating.should == false
end
end