Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI date picker styler #231

Merged
merged 2 commits into from Mar 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 19 additions & 2 deletions motion/ruby_motion_query/stylers/ui_date_picker_styler.rb
@@ -1,8 +1,25 @@
module RubyMotionQuery
module Stylers

class UIDatePickerStyler < UIControlStyler
class UIDatePickerStyler < UIControlStyler

DATE_PICKER_MODES = {
time: UIDatePickerModeTime,
date: UIDatePickerModeDate,
date_and_time: UIDatePickerModeDateAndTime,
date_time: UIDatePickerModeDateAndTime,
count_down: UIDatePickerModeCountDownTimer,
count_down_timer: UIDatePickerModeCountDownTimer,
}

def date_picker_mode=(value)
@view.datePickerMode = DATE_PICKER_MODES[value] || value
end

def date_picker_mode
@view.datePickerMode
end
end

end
end
end
4 changes: 3 additions & 1 deletion spec/stylers/_ui_view_styler.rb
Expand Up @@ -92,6 +92,8 @@ def ui_view_content_mode_symbol(st)
@vc.rmq.styler_for(view).view_has_been_styled?.should == true
end

# ---------------

it 'should apply a style using the apply_style method' do
view = @vc.rmq.append(@view_klass).get
@vc.rmq(view).apply_style(:my_style)
Expand Down Expand Up @@ -129,7 +131,7 @@ def ui_view_content_mode_symbol(st)
view = @vc.rmq.append!(@view_klass, :ui_view_kitchen_sink)

view.tap do |v|
view.backgroundColor.should == rmq.color.red
view.backgroundColor.should == rmq.color.red unless view.is_a? UIDatePicker # Fails for a UIDatePicker
view.isHidden.should.be.true
view.tintColor.should == rmq.color.blue
view.layer.cornerRadius.should == 5
Expand Down
88 changes: 88 additions & 0 deletions spec/stylers/ui_date_picker_styler_spec.rb
@@ -0,0 +1,88 @@
class StyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet

def ui_date_picker_kitchen_sink(st)
st.date_picker_mode = :date_and_time
end

def ui_date_picker_time(st)
st.date_picker_mode = :time
end

def ui_date_picker_date(st)
st.date_picker_mode = :date
end

def ui_date_picker_date_time_alias(st)
st.date_picker_mode = :date_time
end

def ui_date_picker_count_down_timer(st)
st.date_picker_mode = :count_down_timer
end

def ui_date_picker_countdown_alias(st)
st.date_picker_mode = :countdown
end

def ui_date_picker_count_down_alias(st)
st.date_picker_mode = :count_down
end
end

describe 'stylers/ui_date_picker' do
before do
@vc = UIViewController.alloc.init
@vc.rmq.stylesheet = StyleSheetForUIViewStylerTests
@view_klass = UIDatePicker
end

behaves_like "styler"

it 'can update picker with styler' do
view = @vc.rmq.append(@view_klass, :ui_date_picker_kitchen_sink).get

view.tap do |v|
v.datePickerMode.should == UIDatePickerModeDateAndTime
end
end

it 'can update picker with :time styler' do
view = @vc.rmq.append(@view_klass, :ui_date_picker_time).get

view.tap do |v|
v.datePickerMode.should == UIDatePickerModeTime
end
end

it 'can update picker with :date styler' do
view = @vc.rmq.append(@view_klass, :ui_date_picker_date).get

view.tap do |v|
v.datePickerMode.should == UIDatePickerModeDate
end
end

it 'uses :date_time as an alias for :date_and_time' do
view = @vc.rmq.append(@view_klass, :ui_date_picker_date_time_alias).get

view.tap do |v|
v.datePickerMode.should == UIDatePickerModeDateAndTime
end
end

it 'can update picker with :count_down_timer styler' do
view = @vc.rmq.append(@view_klass, :ui_date_picker_count_down_timer).get

view.tap do |v|
v.datePickerMode.should == UIDatePickerModeCountDownTimer
end
end

it 'uses :count_down as an alias for :count_down_timer' do
view = @vc.rmq.append(@view_klass, :ui_date_picker_count_down_alias).get

view.tap do |v|
v.datePickerMode.should == UIDatePickerModeCountDownTimer
end
end
end