diff --git a/motion/ruby_motion_query/actions.rb b/motion/ruby_motion_query/actions.rb index 21cd824..df86cce 100644 --- a/motion/ruby_motion_query/actions.rb +++ b/motion/ruby_motion_query/actions.rb @@ -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 diff --git a/motion/ruby_motion_query/stylers/ui_activity_indicator_view.rb b/motion/ruby_motion_query/stylers/ui_activity_indicator_view.rb new file mode 100644 index 0000000..c452ed2 --- /dev/null +++ b/motion/ruby_motion_query/stylers/ui_activity_indicator_view.rb @@ -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 diff --git a/motion/ruby_motion_query/stylesheet.rb b/motion/ruby_motion_query/stylesheet.rb index 9ea6cc5..9e57f46 100644 --- a/motion/ruby_motion_query/stylesheet.rb +++ b/motion/ruby_motion_query/stylesheet.rb @@ -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) diff --git a/motion/ruby_motion_query/subviews.rb b/motion/ruby_motion_query/subviews.rb index 0362f52..ccbf4df 100644 --- a/motion/ruby_motion_query/subviews.rb +++ b/motion/ruby_motion_query/subviews.rb @@ -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| diff --git a/motion/ruby_motion_query/validation.rb b/motion/ruby_motion_query/validation.rb index ee2a941..bdbd073 100644 --- a/motion/ruby_motion_query/validation.rb +++ b/motion/ruby_motion_query/validation.rb @@ -134,6 +134,8 @@ module RubyMotionQuery UKZIP = Regexp.new('^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) ?[0-9][ABD-HJLNP-UW-Z]{2})$') # 7 or 10 digit number, delimiters are spaces, dashes, or periods USPHONE = Regexp.new('^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]‌​)\s*)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-‌​9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})$') + # International Phone numbers + INTLPHONE = Regexp.new('^(\(?\+?[0-9]*\)?)?[0-9_\- \(\)]*$') # Strong password (at least [8 chars, 1 upper, 1 lower, 1 number]) STRONGPW = Regexp.new('^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{8,}$') # Has at least 1 uppercase letter @@ -154,6 +156,7 @@ module RubyMotionQuery :uszip => lambda { |value, opts| Validation.regex_match?(value, USZIP)}, :ukzip => lambda { |value, opts| Validation.regex_match?(value.upcase, UKZIP)}, :usphone => lambda { |value, opts| Validation.regex_match?(value, USPHONE)}, + :intlphone => lambda { |value, opts| Validation.regex_match?(value, INTLPHONE)}, :strong_password => lambda { |value, opts| Validation.regex_match?(value, STRONGPW)}, :has_upper => lambda { |value, opts| Validation.regex_match?(value, HASUPPER)}, :has_lower => lambda { |value, opts| Validation.regex_match?(value, HASLOWER)}, diff --git a/spec/stylers/ui_activity_indicator_view_styler.rb b/spec/stylers/ui_activity_indicator_view_styler.rb new file mode 100644 index 0000000..517c3ce --- /dev/null +++ b/spec/stylers/ui_activity_indicator_view_styler.rb @@ -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 diff --git a/spec/stylers/ui_image_view_styler.rb b/spec/stylers/ui_image_view_styler.rb index 88556b3..7598962 100644 --- a/spec/stylers/ui_image_view_styler.rb +++ b/spec/stylers/ui_image_view_styler.rb @@ -1,6 +1,6 @@ class StyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet - def u_image_view_kitchen_sink(st) + def ui_image_view_kitchen_sink(st) st.image = image.resource('logo') end @@ -10,13 +10,13 @@ describe 'stylers/ui_image_view' do before do @vc = UIViewController.alloc.init @vc.rmq.stylesheet = StyleSheetForUIViewStylerTests - @view_klass = UIImageView + @view_klass = UIImageView end behaves_like "styler" it 'should apply a style with every UIImageViewStyler wrapper method' do - view = @vc.rmq.append(@view_klass, :u_image_view_kitchen_sink).get + view = @vc.rmq.append(@view_klass, :ui_image_view_kitchen_sink).get view.image.should == @vc.rmq.image.resource('logo') end diff --git a/spec/validation.rb b/spec/validation.rb index 643361c..b896d2f 100644 --- a/spec/validation.rb +++ b/spec/validation.rb @@ -96,6 +96,20 @@ describe 'validation' do @rmq.validation.valid?('test', :usphone).should == false end + it 'can validate intlphone' do + @rmq.validation.valid?('(+44)(0)20-12341234', :intlphone).should == true + @rmq.validation.valid?('02012341234', :intlphone).should == true + @rmq.validation.valid?('+44 (0) 1234-1234', :intlphone).should == true + @rmq.validation.valid?('+44 0 1234-1234', :intlphone).should == true + @rmq.validation.valid?('+44012341234', :intlphone).should == true + @rmq.validation.valid?('+44 7890 123 456', :intlphone).should == true + @rmq.validation.valid?('447890123456', :intlphone).should == true + @rmq.validation.valid?('44 0 1234 1234', :intlphone).should == true + @rmq.validation.valid?('(44+)020-12341234', :intlphone).should == false + @rmq.validation.valid?('12341234(+020)', :intlphone).should == false + @rmq.validation.valid?('test', :intlphone).should == false + end + it 'can validate at least 1 uppercase US character' do @rmq.validation.valid?('test', :has_upper).should == false @rmq.validation.valid?('Test', :has_upper).should == true