Skip to content

Commit

Permalink
Merge branch 'version-2.3' of github.com:clearsightstudio/ProMotion i…
Browse files Browse the repository at this point in the history
…nto version-2.3

* 'version-2.3' of github.com:clearsightstudio/ProMotion:
  Version 2.2.1
  snake case variables for consistency.
  added tests
  Fixes issue with auto-detected links not opening.
  implemented workaround for image autorotate crash jamonholmgren#562
  Write spec to ensure on_init is not used in the future
  Cleanup screen_setup
  Disabled another Travis test
  Disabled another test. This is getting monotonous
  More Travis skipped tests
  Use Travis env variables instead
  Disable failing test for Travis
  Fix: wrong cell detection problem in search_result_table of longpressable TableScreen.
  No version bump yet
  Specs updated for iOS 7 and iOS 8
  Resolving iOS 7 errors
  Updated splitview to iOS 8 compatibility
  • Loading branch information
ryanlntn committed Jan 23, 2015
2 parents 7f49202 + af9977a commit 7958589
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ before_install:
- (ruby --version)
- sudo chown -R travis ~/Library/RubyMotion
- mkdir -p ~/Library/RubyMotion/build
- sudo motion update --cache-version=2.38
- sudo motion update --cache-version=3.2
gemfile:
- Gemfile
script:
Expand Down
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
RM_VERSION = "2.38" # Update .travis.yml too
RM_VERSION = "3.2" # Update .travis.yml too
unless File.exist?("/Library/RubyMotion#{RM_VERSION}/lib")
abort "Couldn't find RubyMotion #{RM_VERSION}. Run `sudo motion update --cache-version=#{RM_VERSION}`."
end
Expand All @@ -14,6 +14,7 @@ Motion::Project::App.setup do |app|
app.device_family = [ :ipad ] # so we can test split screen capability
app.detect_dependencies = false
app.info_plist["UIViewControllerBasedStatusBarAppearance"] = false
app.deployment_target = "7.1"

# Adding file dependencies for tests
# Not too many dependencies necessary
Expand Down
34 changes: 17 additions & 17 deletions app/test_screens/test_table_screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ def table_data
action: :increment_counter_by,
arguments: { number: 10 }
}]
},{
title: "Moveable Tests",
cells: [{
title: 'Cell 1',
moveable: :section
},{
title: 'Cell 2',
moveable: true
},{
title: 'Cell 3'
},{
title: "Moveable Tests",
cells: [{
title: 'Cell 1',
moveable: :section
},{
title: 'Cell 2',
moveable: true
},{
title: 'Cell 3'
},{
title: 'Cell 4',
moveable: true
},{
title: 'Cell 5',
moveable: false
}]
}]
title: 'Cell 4',
moveable: true
},{
title: 'Cell 5',
moveable: false
}]
}]
end

def edit_profile(args={})
Expand Down
8 changes: 8 additions & 0 deletions app/test_screens/test_web_screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ class TestWebScreen < PM::WebScreen
# accesor for wait_change method which is testing helper
attr_accessor :is_load_started, :is_load_finished, :is_load_failed, :is_load_failed_error

def on_init
@on_init_available = true
end

def on_init_available?
@on_init_available
end

def content
nil
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ProMotion/cocoatouch/navigation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def popViewControllerAnimated(animated)
end

def shouldAutorotate
visibleViewController.shouldAutorotate
visibleViewController.shouldAutorotate if visibleViewController
end

def supportedInterfaceOrientations
Expand Down
24 changes: 22 additions & 2 deletions lib/ProMotion/ipad/split_screen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,35 @@ def create_split_screen(master, detail, args={})

# UISplitViewControllerDelegate methods

def splitViewController(svc, willHideViewController: vc, withBarButtonItem: button, forPopoverController: pc)
# iOS 7 and below
def splitViewController(svc, willHideViewController: vc, withBarButtonItem: button, forPopoverController: _)
button ||= self.displayModeButtonItem if self.respond_to?(:displayModeButtonItem)
return unless button
button.title = @pm_split_screen_button_title || vc.title
svc.detail_screen.navigationItem.leftBarButtonItem = button
end

def splitViewController(svc, willShowViewController: vc, invalidatingBarButtonItem: barButtonItem)
def splitViewController(svc, willShowViewController: _, invalidatingBarButtonItem: _)
svc.detail_screen.navigationItem.leftBarButtonItem = nil
end

# iOS 8 and above
def splitViewController(svc, willChangeToDisplayMode: display_mode)
vc = svc.viewControllers.first
vc = vc.topViewController if vc.respond_to?(:topViewController)
case display_mode
# when UISplitViewControllerDisplayModeAutomatic then do_something?
when UISplitViewControllerDisplayModePrimaryHidden
self.splitViewController(svc, willHideViewController: vc, withBarButtonItem: nil, forPopoverController: nil)
# TODO: Add `self.master_screen.try(:will_hide_split_screen)` or similar?
when UISplitViewControllerDisplayModeAllVisible
self.splitViewController(svc, willShowViewController: vc, invalidatingBarButtonItem: nil)
# TODO: Add `self.master_screen.try(:will_show_split_screen)` or similar?
# when UISplitViewControllerDisplayModePrimaryOverlay
# TODO: Add `self.master_screen.try(:will_show_split_screen_overlay)` or similar?
end
end

private

def split_screen_controller(master, detail)
Expand Down
4 changes: 4 additions & 0 deletions lib/ProMotion/screen/screen_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ def frame
return self.view_or_self.frame
end

def try(method, *args)
send(method, *args) if respond_to?(method)
end

private

def apply_properties(args)
Expand Down
11 changes: 9 additions & 2 deletions lib/ProMotion/table/extensions/longpressable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@ def make_longpressable(params={})

def on_long_press(gesture)
return unless gesture.state == UIGestureRecognizerStateBegan
gesture_point = gesture.locationInView(table_view)
index_path = table_view.indexPathForRowAtPoint(gesture_point)
gesture_point = gesture.locationInView(pressed_table_view)
index_path = pressed_table_view.indexPathForRowAtPoint(gesture_point)
return unless index_path
data_cell = self.promotion_table_data.cell(index_path: index_path)
return unless data_cell
trigger_action(data_cell[:long_press_action], data_cell[:arguments], index_path) if data_cell[:long_press_action]
end

private

def pressed_table_view
searching? ? @table_search_display_controller.searchResultsTableView : table_view
end

end
end
end
15 changes: 10 additions & 5 deletions lib/ProMotion/table/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ def accessory_toggled_switch(switch)

def delete_row(index_paths, animation = nil)
deletable_index_paths = []
index_paths = [index_paths] if index_paths.kind_of?(NSIndexPath)
index_paths.each do |index_path|
Array(index_paths).each do |index_path|
delete_cell = false
delete_cell = send(:on_cell_deleted, self.promotion_table_data.cell(index_path: index_path)) if self.respond_to?("on_cell_deleted:")
unless delete_cell == false
Expand All @@ -145,8 +144,7 @@ def create_table_cell(data_cell)
end

def update_table_data(args = {})
# Try and detect if the args param is a NSIndexPath or an array of them
args = { index_paths: args } if args.is_a?(NSIndexPath) || (args.is_a?(Array) && array_all_members_of?(args, NSIndexPath))
args = { index_paths: args } unless args.is_a?(Hash)

self.update_table_view_data(self.table_data, args)
self.promotion_table_data.search(search_string) if searching?
Expand Down Expand Up @@ -336,7 +334,14 @@ def table_style
end

def row_height(height, args={})
height = UITableViewAutomaticDimension if height == :auto
if height == :auto
if UIDevice.currentDevice.systemVersion.to_f < 8.0
height = args[:estimated] || 44.0
PM.logger.warn "Using `row_height :auto` is not supported in iOS 7 apps. Setting to #{height}."
else
height = UITableViewAutomaticDimension
end
end
args[:estimated] ||= height unless height == UITableViewAutomaticDimension
@row_height = { height: height, estimated: args[:estimated] || 44.0 }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ProMotion/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ProMotion
VERSION = "2.2.0" unless defined?(ProMotion::VERSION)
VERSION = "2.2.1" unless defined?(ProMotion::VERSION)
end
56 changes: 30 additions & 26 deletions lib/ProMotion/web/web_screen_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,33 @@ def screen_setup
self.external_links ||= false
self.scale_to_fit ||= false
self.detector_types ||= :none

web_view_setup
set_initial_content
end

def on_init
if self.detector_types.is_a? Array
detectors = UIDataDetectorTypeNone
self.detector_types.each { |dt| detectors |= map_detector_symbol(dt) }
self.detector_types = detectors
else
self.detector_types = map_detector_symbol(self.detector_types)
end
# TODO: Remove in 3.0
end

def web_view_setup
self.webview ||= add UIWebView.new, {
frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height),
delegate: self,
data_detector_types: self.detector_types
data_detector_types: data_detector_types
}
self.webview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
self.webview.scalesPageToFit = self.scale_to_fit
self.webview.scrollView.decelerationRate = UIScrollViewDecelerationRateNormal
set_initial_content
end

def web
self.webview
end

def set_initial_content
return unless self.respond_to?(:content)
current_content = content
return unless current_content
current_content.is_a?(NSURL) ? open_url(current_content) : set_content(current_content)
return unless self.respond_to?(:content) && self.content
self.content.is_a?(NSURL) ? open_url(self.content) : set_content(self.content)
end

def set_content(content)
Expand Down Expand Up @@ -104,32 +100,34 @@ def refresh; web.reload; end
def stop; web.stopLoading; end
alias :reload :refresh

def open_in_chrome(inRequest)
def open_in_chrome(in_request)
# Add pod 'OpenInChrome' to your Rakefile if you want links to open in Google Chrome for users.
# This will fall back to Safari if the user doesn't have Chrome installed.
chrome_controller = OpenInChromeController.sharedInstance
return open_in_safari(inRequest) unless chrome_controller.isChromeInstalled
chrome_controller.openInChrome(inRequest.URL)
return open_in_safari(in_request) unless chrome_controller.isChromeInstalled
chrome_controller.openInChrome(in_request.URL)
end

def open_in_safari(inRequest)
def open_in_safari(in_request)
# Open UIWebView delegate links in Safari.
UIApplication.sharedApplication.openURL(inRequest.URL)
UIApplication.sharedApplication.openURL(in_request.URL)
end

# UIWebViewDelegate Methods - Camelcase
def webView(inWeb, shouldStartLoadWithRequest:inRequest, navigationType:inType)
if self.external_links == true && inType == UIWebViewNavigationTypeLinkClicked
if defined?(OpenInChromeController)
open_in_chrome inRequest
else
open_in_safari inRequest
def webView(in_web, shouldStartLoadWithRequest:in_request, navigationType:in_type)
if %w(http https).include?(in_request.URL.scheme)
if self.external_links == true && in_type == UIWebViewNavigationTypeLinkClicked
if defined?(OpenInChromeController)
open_in_chrome in_request
else
open_in_safari in_request
end
return false # don't allow the web view to load the link.
end
return false #don't allow the web view to load the link.
end

load_request_enable = true #return true on default for local file loading.
load_request_enable = !!on_request(inRequest, inType) if self.respond_to?(:on_request)
load_request_enable = !!on_request(in_request, in_type) if self.respond_to?(:on_request)
load_request_enable
end

Expand All @@ -147,6 +145,12 @@ def webView(webView, didFailLoadWithError:error)

protected

def data_detector_types
Array(self.detector_types).reduce(UIDataDetectorTypeNone) do |detectors, dt|
detectors | map_detector_symbol(dt)
end
end

def map_detector_symbol(symbol)
{
phone: UIDataDetectorTypePhoneNumber,
Expand Down
Loading

0 comments on commit 7958589

Please sign in to comment.