motion-browser 0.1.0

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: 7bfe9164b268d69122382ca6766fc50419a520f2
4
+ data.tar.gz: 8b10d400ac247e30fec7d6bc74a94ba4ba265275
5
+ SHA512:
6
+ metadata.gz: caa66367d11b1649b5a81ba0cd55dd6e73ccf4a6af45c3a3a47a9212bb93f1eddabc3fe51591d6235bc1ed4570de1b09996895862da09a5e658352f21f72123a
7
+ data.tar.gz: 831771278079e825616e3cdbff18bf95344f4eeae17f3754ef6d351518aff5e6701afd6032368f938bbe4f2446b6f0b144eb2c1a813397a368448e50aa58b0e8
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # motion-browser
2
+
3
+ If you have content in your application that needs to open up a webpage, you might not want that opened in Safari, so instead drop this in and use the easy solution.
4
+
5
+ It includes the common back, forward, and share buttons.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'motion-browser'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install motion-browser
20
+
21
+ ## Usage
22
+
23
+ As a drop in browser, I wanted to make it extremely easy to use. All you have to do is create the controller, push it to your navigation controller or present it as a modal view controller.
24
+
25
+ You can create the controller by simply doing this:
26
+
27
+ ```ruby
28
+ MIM::MotionBrowserController.alloc.initWithURL('https://motioninmotion.tv/')
29
+ ```
30
+
31
+ Then simply, push it or present it.
32
+
33
+ ```ruby
34
+ # push it to your navigation stack
35
+ navigation_controller.pushViewController(@browser, animated: true)
36
+
37
+ # present it modally
38
+ UIWindow.keyWindow.rootViewController.presentViewController(@browser, animated: true, completion: -> {
39
+ # do something after it has been shown
40
+ })
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create new Pull Request
@@ -0,0 +1,15 @@
1
+ module MIM
2
+ class MotionBrowserConfig
3
+ def self.shared
4
+ Dispatch.once { @shared = new }
5
+ @shared
6
+ end
7
+
8
+ attr_accessor :back_button_text, :forward_button_text
9
+
10
+ def initialize
11
+ @back_button_text = 'Back'
12
+ @forward_button_text = 'Forward'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ module MIM
2
+ class MotionBrowserToolbarDelegate
3
+ def initialize(webview)
4
+ @webview = webview
5
+ end
6
+
7
+ def shareButtonPressed(shared_button)
8
+ vc = UIActivityViewController.alloc.initWithActivityItems([{'url' => @webview.request.URL.absoluteString}], applicationActivities: nil)
9
+ UIWindow.keyWindow.rootViewController.presentViewController(vc, animated: true, completion: nil)
10
+ end
11
+
12
+ def backButtonPressed(back_button)
13
+ if @webview.canGoBack
14
+ @webview.goBack
15
+ end
16
+ end
17
+
18
+ def forwardButtonPressed(forward_button)
19
+ if @webview.canGoForward
20
+ @webview.goForward
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
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, "uikit/**/*.rb")))
10
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "delegates/**/*.rb")))
11
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "config/**/*.rb")))
12
+ end
@@ -0,0 +1,13 @@
1
+ module MIM
2
+ class BackBarButtonItem < UIBarButtonItem
3
+ def self.create
4
+ self.alloc.initWithTitle(MotionBrowserConfig.shared.back_button_text, style: UIBarButtonItemStylePlain, target: nil, action: nil)
5
+ end
6
+
7
+ def delegate=(delegate)
8
+ @delegate = WeakRef.new(delegate)
9
+ self.target = @delegate
10
+ self.action = 'backButtonPressed:'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module MIM
2
+ class ForwardBarButtonItem < UIBarButtonItem
3
+ def self.create
4
+ self.alloc.initWithTitle(MotionBrowserConfig.shared.forward_button_text, style: UIBarButtonItemStylePlain, target: nil, action: nil)
5
+ end
6
+
7
+ def delegate=(delegate)
8
+ @delegate = WeakRef.new(delegate)
9
+ self.target = @delegate
10
+ self.action = 'forwardButtonPressed:'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module MIM
2
+ class ShareBarButtonItem < UIBarButtonItem
3
+ attr_reader :delegate
4
+
5
+ def self.create
6
+ self.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemAction, target: nil, action: nil)
7
+ end
8
+
9
+ def delegate=(delegate)
10
+ @delegate = WeakRef.new(delegate)
11
+ self.target = @delegate
12
+ self.action = 'shareButtonPressed:'
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,111 @@
1
+ module MIM
2
+ class MotionBrowser < UIView
3
+ attr_reader :webview
4
+
5
+ def init
6
+ super
7
+
8
+ setBackgroundColor UIColor.whiteColor
9
+
10
+ addSubview(@webview = UIWebView.new)
11
+ addSubview(@toolbar = MotionBrowserToolbar.new)
12
+ @delegate = @toolbar.delegate = MotionBrowserToolbarDelegate.new(@webview)
13
+
14
+ @webview.translatesAutoresizingMaskIntoConstraints = false
15
+ @toolbar.translatesAutoresizingMaskIntoConstraints = false
16
+
17
+ attributes = []
18
+ attributes << NSLayoutConstraint.constraintWithItem(
19
+ @webview,
20
+ attribute: NSLayoutAttributeTop,
21
+ relatedBy: NSLayoutRelationEqual,
22
+ toItem: self,
23
+ attribute: NSLayoutAttributeTop,
24
+ multiplier: 1,
25
+ constant: 0
26
+ )
27
+
28
+ attributes << NSLayoutConstraint.constraintWithItem(
29
+ @webview,
30
+ attribute: NSLayoutAttributeBottom,
31
+ relatedBy: NSLayoutRelationEqual,
32
+ toItem: self,
33
+ attribute: NSLayoutAttributeBottom,
34
+ multiplier: 1,
35
+ constant: 0
36
+ )
37
+
38
+ attributes << NSLayoutConstraint.constraintWithItem(
39
+ @webview,
40
+ attribute: NSLayoutAttributeLeft,
41
+ relatedBy: NSLayoutRelationEqual,
42
+ toItem: self,
43
+ attribute: NSLayoutAttributeLeft,
44
+ multiplier: 1,
45
+ constant: 0
46
+ )
47
+
48
+ attributes << NSLayoutConstraint.constraintWithItem(
49
+ @webview,
50
+ attribute: NSLayoutAttributeRight,
51
+ relatedBy: NSLayoutRelationEqual,
52
+ toItem: self,
53
+ attribute: NSLayoutAttributeRight,
54
+ multiplier: 1,
55
+ constant: 0
56
+ )
57
+
58
+ attributes << NSLayoutConstraint.constraintWithItem(
59
+ @toolbar,
60
+ attribute: NSLayoutAttributeHeight,
61
+ relatedBy: NSLayoutRelationEqual,
62
+ toItem: nil,
63
+ attribute: NSLayoutAttributeNotAnAttribute,
64
+ multiplier: 1,
65
+ constant: 50
66
+ )
67
+
68
+ attributes << NSLayoutConstraint.constraintWithItem(
69
+ @toolbar,
70
+ attribute: NSLayoutAttributeBottom,
71
+ relatedBy: NSLayoutRelationEqual,
72
+ toItem: self,
73
+ attribute: NSLayoutAttributeBottom,
74
+ multiplier: 1,
75
+ constant: 0
76
+ )
77
+
78
+ attributes << NSLayoutConstraint.constraintWithItem(
79
+ @toolbar,
80
+ attribute: NSLayoutAttributeLeft,
81
+ relatedBy: NSLayoutRelationEqual,
82
+ toItem: self,
83
+ attribute: NSLayoutAttributeLeft,
84
+ multiplier: 1,
85
+ constant: 0
86
+ )
87
+
88
+ attributes << NSLayoutConstraint.constraintWithItem(
89
+ @toolbar,
90
+ attribute: NSLayoutAttributeRight,
91
+ relatedBy: NSLayoutRelationEqual,
92
+ toItem: self,
93
+ attribute: NSLayoutAttributeRight,
94
+ multiplier: 1,
95
+ constant: 0
96
+ )
97
+ addConstraints(attributes)
98
+
99
+ self
100
+ end
101
+
102
+ def load(url)
103
+ unless url.is_a? NSURL
104
+ url = NSURL.URLWithString(url)
105
+ end
106
+
107
+ request = NSURLRequest.requestWithURL(url)
108
+ @webview.loadRequest(request)
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,28 @@
1
+ module MIM
2
+ class MotionBrowserController < UIViewController
3
+ def initWithURL(url)
4
+ self.init
5
+ @url = url
6
+ setTitle @url
7
+ self
8
+ end
9
+
10
+ def loadView
11
+ self.view = MotionBrowser.new
12
+ view.webview.delegate = self
13
+ end
14
+
15
+ def viewDidAppear(animated)
16
+ super
17
+ view.load(@url)
18
+ end
19
+
20
+ def webViewDidStartLoad(webview)
21
+ UIApplication.sharedApplication.networkActivityIndicatorVisible = true
22
+ end
23
+
24
+ def webViewDidFinishLoad(webview)
25
+ UIApplication.sharedApplication.networkActivityIndicatorVisible = false
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ module MIM
2
+ class MotionBrowserToolbar < UIToolbar
3
+ def init
4
+ super
5
+
6
+ @back = BackBarButtonItem.create
7
+ @forward = ForwardBarButtonItem.create
8
+ @share = ShareBarButtonItem.create
9
+ @space = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemFlexibleSpace, target: nil, action: nil)
10
+ setItems([@share, @space, @back, @forward], animated: false)
11
+
12
+ self
13
+ end
14
+
15
+ def delegate=(delegate)
16
+ @back.delegate = @forward.delegate = @share.delegate = delegate
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-browser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jack Dean Watson-Hamblin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-29 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
+ description: Drop in solution for an in-app browser
28
+ email:
29
+ - info@fluffyjack.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/config/motion_browser_config.rb
36
+ - lib/delegates/motion_browser_toolbar_delegate.rb
37
+ - lib/motion-browser.rb
38
+ - lib/uikit/bar_buttons/back_bar_button_item.rb
39
+ - lib/uikit/bar_buttons/forward_bar_button_item.rb
40
+ - lib/uikit/bar_buttons/share_bar_button_item.rb
41
+ - lib/uikit/motion_browser.rb
42
+ - lib/uikit/motion_browser_controller.rb
43
+ - lib/uikit/motion_browser_toolbar.rb
44
+ homepage: https://github.com/FluffyJack/motion-browser
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.2.2
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: If you have content in your application that needs to open up a webpage,
68
+ you might not want that opened in Safari, so instead drop this in and use the easy
69
+ solution
70
+ test_files: []