motion-alert 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 08192542ba3a4918ff117da677754fae35e5733b
4
+ data.tar.gz: 2cb7598d4cc0d77d53bced4f59e2c85485ccd29c
5
+ SHA512:
6
+ metadata.gz: 4beea57aa0b877af17121e40c649ba0e1d68a8a6716106b27efa7388935b5da472a0f8ff1f63724d04c91de332c21657185a0512702445d49ee8088734dcd922
7
+ data.tar.gz: 07bd448362f56df58ddfa93f8716e8ab5ef1f177c406ff38e73fa6d5dea4ac1cb62903cbc410448b6eafa01b43df1aaea386740e2854066f56792759f2a02002
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ Motion-Alert
2
+
3
+ Want to just show an alert to your no matter what version of iOS you are on?
4
+ Motion-alert is for you. Did you know `UIAlert` is deprecated in iOS 8? You
5
+ should be using `UIAlertController` but if you use that controller on a prior
6
+ iOS version, you're bound to have a bad time.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'motion-alert'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install motion-alert
21
+
22
+ ## Usage
23
+
24
+ def show_alert
25
+ Motion::Alert.new({title: "Alert!", message:"message"}).tap do |a|
26
+ a.add_action("OK", Proc.new { puts 'OK!' })
27
+ a.add_action("Cancel", Proc.new { puts 'Cancel!' })
28
+ a.show
29
+ end
30
+ end
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise "This file must be required within a RubyMotion project Rakefile."
5
+ end
6
+
7
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
8
+ Motion::Project::App.setup do |app|
9
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
10
+ end
@@ -0,0 +1,7 @@
1
+ class AppDelegate
2
+ # I have no idea why a delegate cannot be a class that i define
3
+ # so i have to piggy back on the app delegate for this..
4
+ def alertView(alert_view, clickedButtonAtIndex: index)
5
+ Motion::Alert.instance.selected(index)
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Motion
2
+ class Action
3
+ attr_accessor :title, :action
4
+
5
+ def initialize(title, action)
6
+ self.title = title
7
+ self.action = action
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,85 @@
1
+ module Motion
2
+ class Alert
3
+ attr_accessor :title
4
+ attr_accessor :message
5
+ attr_accessor :actions
6
+
7
+ def self.instance
8
+ Dispatch.once { @instance ||= alloc.init }
9
+ @instance
10
+ end
11
+
12
+ def self.new(options = {})
13
+ instance.tap do |i|
14
+ i.title = options.fetch(:title, nil)
15
+ i.message = options.fetch(:message, nil)
16
+ i.actions = []
17
+ end
18
+ end
19
+
20
+ def add_action(button_title, action_proc)
21
+ self.actions << Action.new(button_title, action_proc)
22
+ end
23
+
24
+ def show
25
+ if can_show_controller?
26
+ root_controller.presentViewController(alert_view_controller, animated: false, completion: nil)
27
+ else
28
+ alert_view.delegate = UIApplication.sharedApplication.delegate
29
+ alert_view.show
30
+ end
31
+ end
32
+
33
+ def alert_view_controller
34
+ alert_view_controller =
35
+ UIAlertController.alertControllerWithTitle(
36
+ title,
37
+ message: message,
38
+ preferredStyle: UIAlertControllerStyleAlert
39
+ )
40
+ self.actions.each do |a|
41
+ alert_action = UIAlertAction.actionWithTitle(
42
+ a.title,
43
+ style: UIAlertActionStyleDefault,
44
+ handler: ->(arg) { a.action.call }
45
+ )
46
+ alert_view_controller.addAction(alert_action)
47
+ end
48
+
49
+ alert_view_controller
50
+ end
51
+
52
+ def alert_view
53
+ unless @alert_view
54
+ @alert_view = UIAlertView.alloc.initWithTitle(
55
+ title,
56
+ message: message,
57
+ delegate: UIApplication.sharedApplication.delegate,
58
+ cancelButtonTitle: nil,
59
+ otherButtonTitles:
60
+ nil
61
+ )
62
+ self.actions.each do |a|
63
+ @alert_view.addButtonWithTitle(a.title)
64
+ end
65
+ end
66
+
67
+ @alert_view
68
+ end
69
+
70
+ def selected(index)
71
+ self.actions[index].action.call
72
+ end
73
+
74
+ private
75
+
76
+ def can_show_controller?
77
+ !!UIDevice.currentDevice.systemVersion.match("^8")
78
+ end
79
+
80
+ def root_controller
81
+ UIApplication.sharedApplication.keyWindow.rootViewController
82
+ end
83
+
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-alert
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - David Larrabee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: motion-stump
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
41
+ description: Proper iOS alerts
42
+ email:
43
+ - dave@larrabeefamily.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/motion-alert.rb
50
+ - lib/project/app_delegate.rb
51
+ - lib/project/motion_action.rb
52
+ - lib/project/motion_alert.rb
53
+ homepage: https://github.com/squidpunch/motion-alert
54
+ licenses:
55
+ - MIT
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.2.2
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Proper iOS alerts
77
+ test_files: []