mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Added focus action
This commit is contained in:
@@ -298,6 +298,7 @@ rmq(my_view).hide
|
||||
rmq(my_view).show
|
||||
rmq(my_view).toggle
|
||||
rmq(my_view).toggle_enabled
|
||||
rmq(my_text_field).focus # or .become_first_responder
|
||||
```
|
||||
|
||||
### Subviews
|
||||
|
||||
@@ -20,6 +20,18 @@ module RubyMotionQuery
|
||||
self
|
||||
end
|
||||
|
||||
# Sets the last selected view as the first responder
|
||||
#
|
||||
# @example
|
||||
# rmq(my_view).next(UITextField).focus
|
||||
def focus
|
||||
unless RMQ.is_blank?(selected)
|
||||
selected.last.becomeFirstResponder
|
||||
end
|
||||
self
|
||||
end
|
||||
alias :become_first_responder :focus
|
||||
|
||||
def hide
|
||||
selected.each { |view| view.hidden = true }
|
||||
self
|
||||
|
||||
@@ -2,7 +2,7 @@ describe 'actions' do
|
||||
before do
|
||||
@vc = UIViewController.alloc.init
|
||||
@viewq = @vc.rmq.append(UIView)
|
||||
@sub_viewq = @vc.rmq(@viewq).append(UIView)
|
||||
@sub_viewq = @viewq.append(UIView)
|
||||
end
|
||||
|
||||
it 'should hide, show, and toggle a view' do
|
||||
@@ -52,6 +52,41 @@ describe 'actions' do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'focus' do
|
||||
before do
|
||||
window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
||||
@vc = UIViewController.alloc.initWithNibName(nil, bundle: nil)
|
||||
window.rootViewController = @vc
|
||||
window.makeKeyAndVisible
|
||||
|
||||
@tf_0 = @vc.rmq.append(UITextField).style do |st|
|
||||
st.frame = {l: 10, t: 10, w: 100, h: 30}
|
||||
end.get
|
||||
@tf_1 = @vc.rmq.append(UITextField).style do |st|
|
||||
st.frame = {l: 10, t: 50, w: 100, h: 30}
|
||||
end.get
|
||||
end
|
||||
|
||||
it 'should set focus to a selected view' do
|
||||
@tf_1.becomeFirstResponder.should == true
|
||||
@tf_1.isFirstResponder.should == true
|
||||
@tf_0.isFirstResponder.should == false
|
||||
|
||||
@vc.rmq(@tf_0).focus.is_a?(RubyMotionQuery::RMQ).should == true
|
||||
@tf_1.isFirstResponder.should == false
|
||||
@tf_0.isFirstResponder.should == true
|
||||
end
|
||||
|
||||
it 'should focus only the last selected view, if many views are selected' do
|
||||
@tf_0.becomeFirstResponder.should == true
|
||||
@tf_1.isFirstResponder.should == false
|
||||
@tf_0.isFirstResponder.should == true
|
||||
@vc.rmq(@tf_0, @tf_1).become_first_responder
|
||||
@tf_1.isFirstResponder.should == true
|
||||
@tf_0.isFirstResponder.should == false
|
||||
end
|
||||
end
|
||||
|
||||
it 'should set attributes on a view' do
|
||||
1.should == 1
|
||||
# TODO
|
||||
|
||||
Reference in New Issue
Block a user