From d938a2784045358b2aa88647b545d413ff066690 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Sat, 21 Feb 2015 14:56:44 -0600 Subject: [PATCH] Allow setting keyboard_appearance with a symbol :default :dark :light :alert --- .../stylers/protocols/ui_text_input_traits.rb | 2 +- motion/ruby_motion_query/stylers/ui_view_styler.rb | 7 +++++++ spec/stylers/ui_text_field_styler.rb | 11 +++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/motion/ruby_motion_query/stylers/protocols/ui_text_input_traits.rb b/motion/ruby_motion_query/stylers/protocols/ui_text_input_traits.rb index 5c715a2..4c6f781 100644 --- a/motion/ruby_motion_query/stylers/protocols/ui_text_input_traits.rb +++ b/motion/ruby_motion_query/stylers/protocols/ui_text_input_traits.rb @@ -14,7 +14,7 @@ module RubyMotionQuery def enables_return_key_automatically=(v) ; view.enablesReturnKeyAutomatically = v ; end def keyboard_appearance ; view.keyboardAppearance ; end - def keyboard_appearance=(v) ; view.keyboardAppearance = v ; end + def keyboard_appearance=(v) ; view.keyboardAppearance = KEYBOARD_APPEARANCES[v] || v ; end def keyboard_type ; view.keyboardType ; end def keyboard_type=(v) ; view.setKeyboardType(KEYBOARD_TYPES[v] || v) ; end diff --git a/motion/ruby_motion_query/stylers/ui_view_styler.rb b/motion/ruby_motion_query/stylers/ui_view_styler.rb index 048cf97..a95b419 100644 --- a/motion/ruby_motion_query/stylers/ui_view_styler.rb +++ b/motion/ruby_motion_query/stylers/ui_view_styler.rb @@ -26,6 +26,13 @@ module RubyMotionQuery alphabet: UIKeyboardTypeASCIICapable } + KEYBOARD_APPEARANCES = { + default: UIKeyboardAppearanceDefault, + dark: UIKeyboardAppearanceDark, + light: UIKeyboardAppearanceLight, + alert: UIKeyboardAppearanceAlert + } + RETURN_KEY_TYPES = { default: UIReturnKeyDefault, go: UIReturnKeyGo, diff --git a/spec/stylers/ui_text_field_styler.rb b/spec/stylers/ui_text_field_styler.rb index 68214d0..2f7c287 100644 --- a/spec/stylers/ui_text_field_styler.rb +++ b/spec/stylers/ui_text_field_styler.rb @@ -9,6 +9,7 @@ describe 'stylers/ui_text_field' do st.autocapitalization_type = :words st.autocorrection_type = :no st.keyboard_type = UIKeyboardTypeDefault + st.keyboard_appearance = UIKeyboardAppearanceDark st.return_key_type = UIReturnKeyNext st.spell_checking_type = UITextSpellCheckingTypeYes st.right_view_mode = :always @@ -22,6 +23,10 @@ describe 'stylers/ui_text_field' do st.keyboard_type = :email_address end + def ui_text_field_alert(st) + st.keyboard_appearance = :alert + end + def ui_text_field_google(st) st.return_key_type = :google end @@ -63,6 +68,7 @@ describe 'stylers/ui_text_field' do v.autocapitalizationType.should == UITextAutocapitalizationTypeWords v.autocorrectionType == UITextAutocorrectionTypeNo v.keyboardType.should == UIKeyboardTypeDefault + v.keyboardAppearance.should == UIKeyboardAppearanceDark v.returnKeyType.should == UIReturnKeyNext v.spellCheckingType.should == UITextSpellCheckingTypeYes v.rightViewMode == UITextFieldViewModeAlways @@ -79,6 +85,11 @@ describe 'stylers/ui_text_field' do view.keyboardType.should == UIKeyboardTypeEmailAddress end + it 'should allow setting a keyboard appearance via symbol' do + view = @vc.rmq.append(@view_klass, :ui_text_field_alert).get + view.keyboardAppearance.should == UIKeyboardAppearanceAlert + end + it 'should allow setting a return key via symbol' do view = @vc.rmq.append(@view_klass, :ui_text_field_google).get view.returnKeyType.should == UIReturnKeyGoogle