Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
PATH
remote: .
specs:
RedAlert (1.1)
RedAlert (1.1.1)
ruby_motion_query (>= 1.3.4)

GEM
remote: https://rubygems.org/
specs:
rake (10.4.2)
ruby_motion_query (1.3.5)
ruby_motion_query (1.5.0)

PLATFORMS
ruby
Expand Down
16 changes: 15 additions & 1 deletion lib/project/alert_controller_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def build(actions, opts={})

# convert the callback
handler = lambda do |action|
alert_action.handler.call(alert_action.tag) unless alert_action.handler.nil?
if !@opts[:textfields] && !alert_action.handler.nil?
alert_action.handler.call(alert_action.tag)
elsif @opts[:textfields] && !alert_action.handler.nil?
alert_action.handler.call(alert_action.tag, @alert_controller.textFields.map {|t| t.text})
end
end if alert_action.handler

# create teh action
Expand All @@ -32,6 +36,16 @@ def build(actions, opts={})
@alert_controller.addAction action
end

textfields = @opts[:textfields]
if(textfields)
textfields.each do |t|
@alert_controller.addTextFieldWithConfigurationHandler -> (textField) {
textField.placeholder = t[:placeholder] || "Enter some text"
textField.secureTextEntry = t[:secure] || false
}
end
end

self
end

Expand Down
31 changes: 30 additions & 1 deletion lib/project/alert_view_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@ def build(actions, opts={})
# mark where our special buttons are
@alert_view.cancelButtonIndex = @actions_in_display_order.length-1 if cancel_action

# add text field if any
textfields = @opts[:textfields]
if(textfields)
textfield_style = case @opts[:textfield_style]
when :secure
UIAlertViewStyleSecureTextInput
when :login
UIAlertViewStyleLoginAndPasswordInput
else
UIAlertViewStylePlainTextInput
end
@alert_view.alertViewStyle = textfield_style
textfields.each_with_index do |t, i|
@alert_view.textFieldAtIndex(i).placeholder = t[:placeholder] if t[:placeholder]
end
end


self
end

Expand All @@ -41,7 +59,18 @@ def show
def alertView(alertView, didDismissWithButtonIndex:buttonIndex)
@view_controller.dismissViewControllerAnimated @opts[:animated], completion: nil
action = @actions_in_display_order[buttonIndex]
action.handler.call(action.tag) if action.handler
textfields = @opts[:textfields]
if action.handler && !textfields
action.handler.call(action.tag)
elsif action.handler && textfields
textfields_text_array = case @opts[:textfield_style]
when :login
[alertView.textFieldAtIndex(0).text, alertView.textFieldAtIndex(1).text]
else
alertView.textFieldAtIndex(0).text
end
action.handler.call(action.tag, textfields_text_array)
end
@view_controller = nil # forget the reference
end

Expand Down
2 changes: 1 addition & 1 deletion red_alert.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
VERSION = "1.1"
VERSION = "1.1.1"

Gem::Specification.new do |spec|
spec.name = "RedAlert"
Expand Down
11 changes: 11 additions & 0 deletions spec/alert_controller_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@
Proc.new { @p.build([]) }.should.raise(ArgumentError)
end

describe "alert controller with 1 text field" do

before do
@p.build [@ok], title: "hi", style: :alert, textfields: [placeholder: "hi"]
end

it "should have one text field" do
@p.alert_controller.textFields.size.should == 1
end
end

describe "alert controller with ok button" do

before do
Expand Down
25 changes: 24 additions & 1 deletion spec/alert_view_provider_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
describe "RubyMotionQuery" do
describe "AlertViewProvider" do

before do
@p = RubyMotionQuery::AlertViewProvider.new
@ok = RubyMotionQuery::AlertAction.new(title: "OK", tag: :ok, style: :default)
Expand All @@ -16,6 +15,30 @@
Proc.new { @p.build([]) }.should.raise(ArgumentError)
end

describe "alert view with one text field" do

before do
@p.build [@ok], title: "hi", style: :alert, textfields: [placeholder: "hi"]
end

it "should have one text field" do
@p.alert_view.textFieldAtIndex(0).should != nil
end

end

describe "alert view with two text field" do

before do
@p.build [@ok], title: "hi", style: :alert, textfields: [placeholder: "hi"]
end

it "should have one text field" do
@p.alert_view.textFieldAtIndex(0).should != nil
end

end

describe "alert view with ok button" do

before do
Expand Down
6 changes: 6 additions & 0 deletions spec/red_alert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@
@provider.alert_controller.message.should == "hello"
end

# it "gets the text back if a textfield is sent..." do
# rmq.app.alert(message: "hello", textfields: [placeholder: "insert text"]) do |action, text|
# ???
# end
# end

end

describe "UIActionSheet Hosted" do
Expand Down