Allos a user to set keyboard_type with symbols.

This commit is contained in:
Mark Rickert
2014-12-18 11:30:26 -05:00
parent 8196608443
commit fc7dfd8d4d
3 changed files with 27 additions and 1 deletions

View File

@@ -17,7 +17,7 @@ module RubyMotionQuery
def keyboard_appearance=(v) ; view.keyboardAppearance = v ; end
def keyboard_type ; view.keyboardType ; end
def keyboard_type=(v) ; view.keyboardType = v ; end
def keyboard_type=(v) ; view.setKeyboardType(KEYBOARD_TYPES[v] || v) ; end
def return_key_type ; view.returnKeyType ; end
def return_key_type=(v) ; view.returnKeyType = v ; end

View File

@@ -9,6 +9,22 @@ module RubyMotionQuery
natural: NSTextAlignmentNatural
}
KEYBOARD_TYPES = {
default: UIKeyboardTypeDefault,
ascii: UIKeyboardTypeASCIICapable,
numbers_punctuation: UIKeyboardTypeNumbersAndPunctuation,
url: UIKeyboardTypeURL,
number_pad: UIKeyboardTypeNumberPad,
phone_pad: UIKeyboardTypePhonePad,
name_phone_pad: UIKeyboardTypeNamePhonePad,
email_address: UIKeyboardTypeEmailAddress,
email: UIKeyboardTypeEmailAddress, # Duplicate to help developers
decimal_pad: UIKeyboardTypeDecimalPad,
twitter: UIKeyboardTypeTwitter,
web_search: UIKeyboardTypeWebSearch,
alphabet: UIKeyboardTypeASCIICapable
}
# When you create a styler, always inherit UIViewStyler
class UIViewStyler
def initialize(view)

View File

@@ -6,6 +6,11 @@ describe 'stylers/ui_text_field' do
st.placeholder = "placeholder"
st.border_style = UITextBorderStyleRoundedRect
st.autocapitalization_type = UITextAutocapitalizationTypeWords
st.keyboard_type = UIKeyboardTypeDefault
end
def ui_text_field_email(st)
st.keyboard_type = :email_address
end
end
@@ -29,4 +34,9 @@ describe 'stylers/ui_text_field' do
v.keyboardType.should == UIKeyboardTypeDefault
end
end
it 'should allow setting a keyboard type via symbol' do
view = @vc.rmq.append(@view_klass, :ui_text_field_email).get
view.keyboardType.should == UIKeyboardTypeEmailAddress
end
end