mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Adds UIActivityIndicatorView stylers and actions
With tests!
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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|
|
||||
|
||||
51
spec/stylers/ui_activity_indicator_view_styler.rb
Normal file
51
spec/stylers/ui_activity_indicator_view_styler.rb
Normal 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
|
||||
Reference in New Issue
Block a user