Skip to content

Commit

Permalink
Merge pull request clayallsopp#114 from rheoli/new_row_types
Browse files Browse the repository at this point in the history
Some new row types
  • Loading branch information
clayallsopp committed Jun 15, 2013
2 parents 7f92b67 + 9a99afc commit 9663e41
Show file tree
Hide file tree
Showing 6 changed files with 477 additions and 3 deletions.
64 changes: 62 additions & 2 deletions LIST_OF_ROW_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
[Phone](#phone)<br/>
[Number](#number)<br/>
[Currency](#currency)<br/>
[Date](#date)
[Date](#date)<br/>
[Object](#object)<br/>

**Other**<br/>
[Static](#static)<br/>
Expand All @@ -16,7 +17,10 @@
[Option](#option)<br/>
[Picker](#picker)<br/>
[Subform](#subform)<br/>
[Template](#template)
[Template](#template)<br/>
[Mapview](#mapview)<br/>
[Webview](#webview)<br/>
[Pagedimage](#pagedimage)<br/>

**Buttons**<br/>
[Button](#button)<br/>
Expand Down Expand Up @@ -214,6 +218,21 @@ Note: If you use `:date_time` or `:time` for the type, `:minute_interval` will b
the default is the Apple default of 1.


### <a name="object"></a> Object row

```ruby
{
title: "My Data",
type: :object,
value: object # an object
}
```

Same as StringRow with the difference that it would not change the row.value to string.
The object needs a to_s method.



## Other

### <a name="static"></a> Static row
Expand Down Expand Up @@ -406,6 +425,47 @@ Use a `:display_key` to show the value of the subform in the row:
}
```


### <a name="mapview"></a> Mapview row
![Mapview row](https://github.com/rheoli/formotion/wiki/row-types/Mapview.png)
```ruby
{
title: "Map",
type: :mapview,
value: coordinates, # of type CLLocationCoordinate2D
row_height: 200 # for better viewing
}
```

Shows a map with a pin at the coordinates from value.


### <a name="webview"></a> Webview row
![Webview row](https://github.com/rheoli/formotion/wiki/row-types/Webview.png)
```ruby
{
title: "Page",
type: :webview,
value: html, # HTML code to be shown
row_height: 200 # for better viewing
}
```


### <a name="pagedimage"></a> Pagedimage row
![Pagedimage row](https://github.com/rheoli/formotion/wiki/row-types/Pagedimage.png)
```ruby
{
title: "Photos",
type: :pagedimage,
value: images, # array of UIImage's
row_height: 200 # for better viewing
}
```
Same functionality as ImageRow but ypu can scroll through many photos.



## Buttons

### <a name="button"></a> Button row
Expand Down
7 changes: 6 additions & 1 deletion lib/formotion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@

require 'motion-require'

Motion::Require.all(Dir.glob(File.expand_path('../formotion/**/*.rb', __FILE__)))
Motion::Require.all(Dir.glob(File.expand_path('../formotion/**/*.rb', __FILE__)))

Motion::Project::App.setup do |app|
app.frameworks<<'CoreLocation' unless app.frameworks.include?('CoreLocation')
app.frameworks<<'MapKit' unless app.frameworks.include?('MapKit')
end
79 changes: 79 additions & 0 deletions lib/formotion/row_type/map_row.rb
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
30 changes: 30 additions & 0 deletions lib/formotion/row_type/object_row.rb
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
Loading

0 comments on commit 9663e41

Please sign in to comment.