mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 22:51:53 +08:00
Merge pull request #161 from infinitered/keyboard_type_symbols
Lots of cool symbol setters keyboard and text input fields
This commit is contained in:
@@ -17,16 +17,16 @@ 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
|
||||
def return_key_type=(v) ; view.setReturnKeyType(RETURN_KEY_TYPES[v] || v) ; end
|
||||
|
||||
def secure_text_entry ; view.secureTextEntry ; end
|
||||
def secure_text_entry=(v) ; view.secureTextEntry = v ; end
|
||||
|
||||
def spell_checking_type ; view.spellCheckingType ; end
|
||||
def spell_checking_type=(v) ; view.spellCheckingType = v ; end
|
||||
def spell_checking_type=(v) ; view.setSpellCheckingType(SPELL_CHECKING_TYPES[v] || v) ; end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ module RubyMotionQuery
|
||||
|
||||
# Setting the View's Background Appearance
|
||||
def border_style ; view.borderStyle ; end
|
||||
def border_style=(v) ; view.borderStyle = v ; end
|
||||
def border_style=(v) ; view.setBorderStyle(BORDER_STYLES[v] || v) ; end
|
||||
|
||||
def background ; view.background ; end
|
||||
def background=(v) ; view.background = v ; end
|
||||
|
||||
@@ -9,6 +9,50 @@ 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
|
||||
}
|
||||
|
||||
RETURN_KEY_TYPES = {
|
||||
default: UIReturnKeyDefault,
|
||||
go: UIReturnKeyGo,
|
||||
google: UIReturnKeyGoogle,
|
||||
join: UIReturnKeyJoin,
|
||||
next: UIReturnKeyNext,
|
||||
route: UIReturnKeyRoute,
|
||||
search: UIReturnKeySearch,
|
||||
send: UIReturnKeySend,
|
||||
yahoo: UIReturnKeyYahoo,
|
||||
done: UIReturnKeyDone,
|
||||
emergency_call: UIReturnKeyEmergencyCall
|
||||
}
|
||||
|
||||
SPELL_CHECKING_TYPES = {
|
||||
default: UITextSpellCheckingTypeDefault,
|
||||
no: UITextSpellCheckingTypeNo,
|
||||
yes: UITextSpellCheckingTypeYes
|
||||
}
|
||||
|
||||
BORDER_STYLES = {
|
||||
none: UITextBorderStyleNone,
|
||||
line: UITextBorderStyleLine,
|
||||
bezel: UITextBorderStyleBezel,
|
||||
rounded_rect: UITextBorderStyleRoundedRect,
|
||||
rounded: UITextBorderStyleRoundedRect
|
||||
}
|
||||
|
||||
# When you create a styler, always inherit UIViewStyler
|
||||
class UIViewStyler
|
||||
def initialize(view)
|
||||
|
||||
@@ -6,6 +6,25 @@ describe 'stylers/ui_text_field' do
|
||||
st.placeholder = "placeholder"
|
||||
st.border_style = UITextBorderStyleRoundedRect
|
||||
st.autocapitalization_type = UITextAutocapitalizationTypeWords
|
||||
st.keyboard_type = UIKeyboardTypeDefault
|
||||
st.return_key_type = UIReturnKeyNext
|
||||
st.spell_checking_type = UITextSpellCheckingTypeYes
|
||||
end
|
||||
|
||||
def ui_text_field_email(st)
|
||||
st.keyboard_type = :email_address
|
||||
end
|
||||
|
||||
def ui_text_field_google(st)
|
||||
st.return_key_type = :google
|
||||
end
|
||||
|
||||
def ui_text_field_no_spell_check(st)
|
||||
st.spell_checking_type = :no
|
||||
end
|
||||
|
||||
def ui_text_field_line_border(st)
|
||||
st.border_style = :line
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,7 +40,34 @@ describe 'stylers/ui_text_field' do
|
||||
view = @vc.rmq.append(@view_klass, :ui_text_field_kitchen_sink).get
|
||||
|
||||
view.tap do |v|
|
||||
1.should == 1
|
||||
v.text.should == 'foo'
|
||||
v.textAlignment.should == NSTextAlignmentCenter
|
||||
v.placeholder.should == "placeholder"
|
||||
v.borderStyle.should == UITextBorderStyleRoundedRect
|
||||
v.autocapitalizationType.should == UITextAutocapitalizationTypeWords
|
||||
v.keyboardType.should == UIKeyboardTypeDefault
|
||||
v.returnKeyType.should == UIReturnKeyNext
|
||||
v.spellCheckingType.should == UITextSpellCheckingTypeYes
|
||||
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
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
it 'should allow setting a spell checking type via symbol' do
|
||||
view = @vc.rmq.append(@view_klass, :ui_text_field_no_spell_check).get
|
||||
view.spellCheckingType.should == UITextSpellCheckingTypeNo
|
||||
end
|
||||
|
||||
it 'should allow setting a border style via symbol' do
|
||||
view = @vc.rmq.append(@view_klass, :ui_text_field_line_border).get
|
||||
view.borderStyle.should == UITextBorderStyleLine
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user