forked from clayallsopp/formotion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request clayallsopp#114 from rheoli/new_row_types
Some new row types
- Loading branch information
Showing
6 changed files
with
477 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
motion_require 'base' | ||
|
||
module Formotion | ||
module RowType | ||
class MapRowData | ||
|
||
attr_accessor :pin, :options | ||
#attr_accessor :title, :subtitle, :coordinate | ||
|
||
def initialize(title, subtitle, coordinate, options={}) | ||
@title=title | ||
@subtitle=subtitle | ||
@coordinate=coordinate | ||
@options=options | ||
end | ||
|
||
def title | ||
@title | ||
end | ||
|
||
def subtitle | ||
@subtitle | ||
end | ||
|
||
def coordinate | ||
@coordinate | ||
end | ||
|
||
end | ||
|
||
class MapRow < Base | ||
|
||
MAP_VIEW_TAG=1100 | ||
|
||
def build_cell(cell) | ||
cell.selectionStyle = self.row.selection_style || UITableViewCellSelectionStyleBlue | ||
|
||
@map_view = MKMapView.alloc.init | ||
@map_view.delegate = self | ||
if row.value | ||
coord = (row.value.is_a?(Array) and row.value.size==2) ? CLLocationCoordinate2D.new(row.value[0], row.value[1]) : row.value | ||
if coord.is_a?(CLLocationCoordinate2D) | ||
region = MKCoordinateRegionMakeWithDistance(coord, 400.0, 480.0) | ||
@map_view.setRegion(region, animated:true) | ||
m=MapRowData.new(nil, nil, coord) | ||
@map_view.addAnnotation(m) | ||
end | ||
end | ||
@map_view.tag = MAP_VIEW_TAG | ||
@map_view.contentMode = UIViewContentModeScaleAspectFit | ||
@map_view.backgroundColor = UIColor.clearColor | ||
cell.addSubview(@map_view) | ||
|
||
cell.swizzle(:layoutSubviews) do | ||
def layoutSubviews | ||
old_layoutSubviews | ||
|
||
# viewWithTag is terrible, but I think it's ok to use here... | ||
formotion_field = self.viewWithTag(MAP_VIEW_TAG) | ||
|
||
field_frame = formotion_field.frame | ||
field_frame.origin.y = 10 | ||
field_frame.origin.x = self.textLabel.frame.origin.x + self.textLabel.frame.size.width + Formotion::RowType::Base.field_buffer | ||
field_frame.size.width = self.frame.size.width - field_frame.origin.x - Formotion::RowType::Base.field_buffer | ||
field_frame.size.height = self.frame.size.height - Formotion::RowType::Base.field_buffer | ||
formotion_field.frame = field_frame | ||
end | ||
end | ||
end | ||
|
||
def on_select(tableView, tableViewDelegate) | ||
if !row.editable? | ||
return | ||
end | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
motion_require 'string_row' | ||
|
||
module Formotion | ||
module RowType | ||
class ObjectRow < StringRow | ||
|
||
def build_cell(cell) | ||
super.tap do |field| | ||
|
||
# "remove" the setText swizzle | ||
if UIDevice.currentDevice.systemVersion >= "6.0" and field.respond_to?("old_setText") | ||
unswizzle = Proc.new do | ||
def setText(text) | ||
old_setText(text) | ||
end | ||
end | ||
field.instance_eval unswizzle | ||
end | ||
|
||
end | ||
end | ||
|
||
# overriden in subclasses | ||
def row_value | ||
row.value | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.