motion-prime 0.5.1 → 0.5.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWVkMTljOTZkZDI3YThhODdjZGU3OWU4NWE1MzU2ZDY2ZmU1YTY2YQ==
4
+ YzJhZGY0OTNiNDY5YmZmOWQ0NDZhNGEzOWY4MjM3ZDU3YjUzODVkOQ==
5
5
  data.tar.gz: !binary |-
6
- ZjExNDBjZmEwZWQ4MWU3NmE5MGJhNmVkNDVmMWUyYmNkN2E3M2JmMg==
6
+ ZDcyYmRiYWM3MWQyYmI5OTA0M2U2YzcyYTlmZGFkNjBjZWIzMWJlMw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YWE1ZDk0YjZhZTZmYTA0ODg5NzIwYTBjZmU5NzA5OWM4YzVmMzZhOGQzODI1
10
- ZDkwNGRhYmE0YjA3NmYyMjBiMzYzZThlMjQyYjVhZGQ4YzAwN2QzOTZiZmE3
11
- MTJhMjIwYzBjMDYzOTRkNWIzYmE4YWRhNmI3ZTAwNWY2NmEzNWQ=
9
+ NzAwYWU2NDlmYjUyZGVhZjkxMzcyZGE0ZTBiNmYyN2EwZmEyNGMzYjJmNTcz
10
+ N2IyZmRkNWVjZjU0ZDVmNGQxYmYxZGJkOTE0YTdkZTBjMDc3MmMwZDU2NjJk
11
+ NWUyYWRjN2E4NDg4YWEwY2U0N2MyMDhlMzI2OTY0MDJmNjRiZGE=
12
12
  data.tar.gz: !binary |-
13
- ZTgzMDY0MjA4MGJjYmYxMTA4NDYzOGQ2NTI1MTgzOGNiZTNiMmFkMTA4NWQ5
14
- MTkyYzQ1OTIwMGM2ODliZTkwZTYwMTNiZjJkYTE3NzliZDhiNzQwZTM2MjFk
15
- NjQ4NTA0YTExMmVhYjNiNGNhNjY2MmM2OTllMGEwMWE1Y2QxNTQ=
13
+ MmYyY2I4MTQ5ZTA4OGIxZjYzOWFhOTc1NDk5NWI5YWMwZjJmN2Q0NGU1Y2Jm
14
+ MTQwZGU3ZDlmNTgwMThkZGQ2OTBmMjU5NTY3OTY3OGQ5NzA3NjQxODYwZThj
15
+ MThjMjgxMmQ0YzU0MTYyZDljZGY1NTI0NzllZGExYzRkZjMxYmU=
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.5.2
2
+ * fix bugs.
3
+
1
4
  === 0.5.1
2
5
  * configurations and style definitions runs in correct order.
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- motion-prime (0.5.1)
4
+ motion-prime (0.5.2)
5
5
  bubble-wrap
6
6
  cocoapods
7
7
  methadone
data/files/Gemfile CHANGED
@@ -5,7 +5,7 @@ gem 'motion-support', '~> 0.2.4'
5
5
  gem 'sugarcube', '~> 1.3.7', require: 'sugarcube-classic'
6
6
  gem 'bubble-wrap', '~> 1.3.0'
7
7
 
8
- gem 'motion-prime', '~> 0.5.0', path: '../'
8
+ gem 'motion-prime', '~> 0.5.1'
9
9
 
10
10
  # add reside menu for sidebar support
11
11
  gem 'prime_reside_menu', '~> 0.1.3'
data/files/Gemfile.lock CHANGED
@@ -1,15 +1,3 @@
1
- PATH
2
- remote: ../
3
- specs:
4
- motion-prime (0.5.0)
5
- bubble-wrap
6
- cocoapods
7
- methadone
8
- motion-cocoapods
9
- motion-require
10
- motion-support
11
- sugarcube
12
-
13
1
  GEM
14
2
  remote: http://rubygems.org/
15
3
  specs:
@@ -44,6 +32,14 @@ GEM
44
32
  bundler
45
33
  motion-cocoapods (1.4.0)
46
34
  cocoapods (>= 0.26.2)
35
+ motion-prime (0.5.1)
36
+ bubble-wrap
37
+ cocoapods
38
+ methadone
39
+ motion-cocoapods
40
+ motion-require
41
+ motion-support
42
+ sugarcube
47
43
  motion-require (0.0.7)
48
44
  motion-support (0.2.5)
49
45
  motion-require (>= 0.0.6)
@@ -67,7 +63,7 @@ PLATFORMS
67
63
  DEPENDENCIES
68
64
  bubble-wrap (~> 1.3.0)
69
65
  motion-cocoapods (~> 1.4.0)
70
- motion-prime (~> 0.5.0)!
66
+ motion-prime (~> 0.5.1)
71
67
  motion-support (~> 0.2.4)
72
68
  prime_reside_menu (~> 0.1.3)
73
69
  sugarcube (~> 1.3.7)
@@ -1,5 +1,5 @@
1
1
  class ApplicationScreen < Prime::Screen
2
- before_load :setup_navigation
2
+ before_render :setup_navigation
3
3
 
4
4
  def setup_navigation
5
5
  set_navigation_left_button 'menu', image: 'images/menu_button.png', action: :toggle_sidebar
@@ -11,6 +11,10 @@ class Kernel
11
11
  WeakRef.new(self)
12
12
  end
13
13
 
14
+ def strong_ref
15
+ self
16
+ end
17
+
14
18
  def clear_instance_variables(options = {})
15
19
  ivars = self.instance_variables.clone
16
20
  ivars.each do |ivar|
@@ -21,7 +21,8 @@ module MotionPrime
21
21
  options = {
22
22
  text: content_text,
23
23
  font: content_font,
24
- line_spacing: computed_options[:line_spacing]
24
+ line_spacing: computed_options[:line_spacing],
25
+ line_height: computed_options[:line_height]
25
26
  }
26
27
  computed_options[:html].present? ? html_string(options) : attributed_string(options)
27
28
  end
@@ -13,7 +13,7 @@ module MotionPrime
13
13
  def html_string(options)
14
14
  styles = []
15
15
  styles << "color: #{options[:text_color].hex};" if options[:text_color]
16
- styles << "line-height: #{options[:line_spacing].to_f + options[:font].pointSize}px;"
16
+ styles << "line-height: #{options.fetch(:line_height, options[:line_spacing].to_f + options[:font].pointSize)}px;"
17
17
  styles << "font-family: '#{options[:font].familyName}';"
18
18
  styles << "font-size: #{options[:font].pointSize}px;"
19
19
  styles << "text-align: #{options[:text_alignment_name]};" if options[:text_alignment_name]
@@ -28,13 +28,17 @@ module MotionPrime
28
28
  # DTCoreTextFontDescriptor.setOverrideFontName(Prime::Config.font.bold_italic, forFontFamily: 'Calibri', bold: true, italic: true)
29
29
 
30
30
  text = "#{options[:text]}<style>* { #{styles.join} }</style>"
31
- NSAttributedString.alloc.initWithData(text.dataUsingEncoding(NSString.defaultCStringEncoding), options: html_options, documentAttributes: nil, error: nil)
31
+ NSAttributedString.alloc.initWithData(text.dataUsingEncoding(NSUTF8StringEncoding), options: html_options, documentAttributes: nil, error: nil)
32
32
  end
33
33
 
34
34
  def attributed_string(options)
35
35
  paragrahStyle = NSMutableParagraphStyle.alloc.init
36
36
 
37
- paragrahStyle.setLineSpacing(options[:line_spacing]) if options[:line_spacing]
37
+ if options[:line_height]
38
+ paragrahStyle.setMinimumLineHeight(options[:line_height])
39
+ elsif options[:line_spacing]
40
+ paragrahStyle.setLineSpacing(options[:line_spacing])
41
+ end
38
42
  paragrahStyle.setAlignment(options[:text_alignment]) if options[:text_alignment]
39
43
  paragrahStyle.setLineBreakMode(options[:line_break_mode]) if options[:line_break_mode]
40
44
  attributes = {}
@@ -65,18 +65,23 @@ module MotionPrime
65
65
  end
66
66
 
67
67
  def hide
68
+ return if computed_options[:hidden]
68
69
  computed_options[:hidden] = true
70
+ section.cached_draw_image = nil
69
71
  view.setNeedsDisplay
70
72
  end
71
73
 
72
74
  def show
75
+ return if !computed_options[:hidden]
73
76
  computed_options[:hidden] = false
77
+ section.cached_draw_image = nil
74
78
  view.setNeedsDisplay
75
79
  end
76
80
 
77
81
  def update_with_options(new_options = {})
78
82
  options.merge!(new_options)
79
83
  compute_options!
84
+ section.cached_draw_image = nil
80
85
  view.setNeedsDisplay
81
86
  end
82
87
 
@@ -4,11 +4,6 @@ module MotionPrime
4
4
  include DrawBackgroundMixin
5
5
  attr_accessor :image_data
6
6
 
7
- def dealloc
8
- @break_async_block = true
9
- super
10
- end
11
-
12
7
  def draw_options
13
8
  image = image_data || computed_options[:image]
14
9
  image ||= computed_options[:default] if computed_options[:url]
@@ -73,11 +68,17 @@ module MotionPrime
73
68
  return if image_data || !computed_options[:url]
74
69
  BW::Reactor.schedule do
75
70
  manager = SDWebImageManager.sharedManager
71
+ @screen_ref = screen.strong_ref
72
+ @section_ref = section.strong_ref
76
73
  manager.downloadWithURL(computed_options[:url],
77
74
  options: 0,
78
75
  progress: lambda{ |r_size, e_size| },
79
76
  completed: lambda{ |image, error, type, finished|
80
- break if @break_async_block || !image
77
+ if !image || screen.retainCount == 1 || section.retainCount == 1
78
+ @screen_ref = @section_ref = nil
79
+ return
80
+ end
81
+
81
82
  self.image_data = image
82
83
 
83
84
  section.cached_draw_image = nil
@@ -86,6 +87,7 @@ module MotionPrime
86
87
  else
87
88
  self.view.performSelectorOnMainThread :setNeedsDisplay, withObject: nil, waitUntilDone: false
88
89
  end
90
+ @screen_ref = @section_ref = nil
89
91
  }
90
92
  )
91
93
  end
@@ -30,6 +30,7 @@ module MotionPrime
30
30
  line_break_mode_name: line_break_mode_name,
31
31
  line_break_mode: line_break_mode,
32
32
  line_spacing: options[:line_spacing],
33
+ line_height: options[:line_height],
33
34
  underline: options[:underline],
34
35
  top_left_corner: top_left_corner,
35
36
  inner_rect: inner_rect
@@ -49,7 +50,7 @@ module MotionPrime
49
50
 
50
51
  UIGraphicsPushContext(context)
51
52
  options = draw_options
52
- if options[:is_html] || options[:line_spacing] || options[:underline]
53
+ if options[:is_html] || options[:line_spacing] || options[:line_height] || options[:underline]
53
54
  prepared_text = options[:is_html] ? html_string(options) : attributed_string(options)
54
55
 
55
56
  if options[:inner_rect]
data/motion-prime/env.rb CHANGED
@@ -14,6 +14,10 @@ module MotionPrime
14
14
  env
15
15
  end
16
16
 
17
+ def ==(obj)
18
+ env == obj
19
+ end
20
+
17
21
  def method_missing(name, *args, &block)
18
22
  if /(.+)?$/.match(name.to_s)
19
23
  env == name.to_s.gsub('?', '')
@@ -28,7 +28,5 @@ module MotionPrime
28
28
  end
29
29
 
30
30
  def on_rotate; end;
31
-
32
- def on_load; end
33
31
  end
34
32
  end
@@ -13,20 +13,10 @@ module MotionPrime
13
13
  attr_accessor :parent_screen, :modal, :params, :main_section, :options, :tab_bar
14
14
  class_attribute :current_screen
15
15
 
16
- included do
17
- define_callbacks :load
18
- end
19
-
20
16
  def app_delegate
21
17
  UIApplication.sharedApplication.delegate
22
18
  end
23
19
 
24
- def on_screen_load
25
- run_callbacks :load do
26
- on_load
27
- end
28
- end
29
-
30
20
  # Setup the screen, this method will be called when you run MPViewController.new
31
21
  # @param options [hash] Options passed to setup
32
22
  # @return [MotionPrime::Screen] Ready to use screen
@@ -74,11 +64,11 @@ module MotionPrime
74
64
  t ? @title = t : @title ||= self.to_s
75
65
  end
76
66
  end
77
- def before_load(method_name)
78
- set_callback :load, :before, method_name
67
+ def before_render(method_name)
68
+ set_callback :render, :before, method_name
79
69
  end
80
- def after_load(method_name)
81
- set_callback :load, :after, method_name
70
+ def after_render(method_name)
71
+ set_callback :render, :after, method_name
82
72
  end
83
73
  def create_with_options(screen, navigation = true, options = {})
84
74
  if screen.is_a?(Symbol)
@@ -20,6 +20,8 @@ module MotionPrime
20
20
 
21
21
  extend HasClassFactory
22
22
 
23
+ define_callbacks :render
24
+
23
25
  def render
24
26
  end
25
27
 
@@ -30,15 +32,14 @@ module MotionPrime
30
32
  def will_appear
31
33
  unless @on_appear_happened
32
34
  setup view, styles: default_styles do
33
- render
35
+ run_callbacks :render { render }
34
36
  end
35
37
  end
36
38
  @on_appear_happened = true
37
39
  end
38
40
 
39
41
  def dealloc
40
- pp 'Deallocating Screen'
41
- @main_section.instance_variable_set(:"@break_preload", true) # TODO: find a better option
42
+ pp self.object_id, 'Deallocating Screen', self.retainCount
42
43
  # FIXME: calling instance_eval in title method (_base_screen_mixin) instance variables need to be cleared manually
43
44
  # clear_instance_variables cause BAD_ACCESS errors too
44
45
  @main_section = nil
@@ -37,7 +37,7 @@ module MotionPrime
37
37
  end
38
38
 
39
39
  def dealloc
40
- # pp 'deallocating section', self.name, self.elements.try(:count), self.to_s, self.object_id
40
+ pp 'deallocating section', self.name, self.elements.try(:count), self.to_s, self.object_id
41
41
  NSNotificationCenter.defaultCenter.removeObserver self # unbinding events created in bind_keyboard_events
42
42
  super
43
43
  end
@@ -72,7 +72,6 @@ module MotionPrime
72
72
  @section_loading = true
73
73
  create_elements
74
74
  @section_loading = false
75
-
76
75
  return @section_loaded = true
77
76
  end
78
77
 
@@ -15,12 +15,6 @@ module MotionPrime
15
15
  after_render :init_pull_to_refresh
16
16
  delegate :init_pull_to_refresh, to: :table_delegate
17
17
 
18
- def dealloc
19
- cancel_block = proc { :cancelled }.weak!
20
- @preloader_queue.map!(&cancel_block) if @preloader_queue.present?
21
- super
22
- end
23
-
24
18
  def table_data
25
19
  []
26
20
  end
@@ -55,14 +49,6 @@ module MotionPrime
55
49
  @preloader_cancelled = false
56
50
  @data_stamp = nil
57
51
  @preloader_queue[-1] = :cancelled if @preloader_queue.present?
58
- # @ids.each do |id|
59
- # table_view.dequeueReusableCellWithIdentifier(id)
60
- # end if @ids
61
- # table_view.valueForKey('_reusableTableCells').removeAllObjects
62
-
63
- # releasing table_delegate
64
- # @table_delegate = nil
65
- # table_view.delegate = table_delegate
66
52
  end
67
53
 
68
54
  def table_styles
@@ -379,22 +365,36 @@ module MotionPrime
379
365
  load_count = [left_to_load, limit].compact.min
380
366
  @preloader_cancelled = false
381
367
  @preloader_queue ||= []
368
+ @strong_refs ||= []
382
369
 
383
370
  # TODO: do not release parent_objcets unless finished
384
371
  BW::Reactor.schedule(@preloader_queue.count) do |queue_id|
385
372
  @preloader_queue[queue_id] = :in_progress
373
+ @strong_refs[queue_id] = screen.strong_ref
386
374
 
387
375
  result = load_count.times do |offset|
388
- break if @break_preload || @preloader_queue[queue_id] == :cancelled
376
+ if @preloader_queue[queue_id] == :cancelled
377
+ @strong_refs[queue_id] = nil
378
+ break
379
+ end
380
+
381
+ if screen.retainCount == 1
382
+ @strong_refs[queue_id] = nil
383
+ @preloader_queue[queue_id] = :dealloc
384
+ break
385
+ end
386
+
389
387
  load_cell_by_index(index, preload: true)
390
388
  unless offset == load_count - 1
391
389
  index = service.sum_index(index, 1)
392
390
  end
393
391
  end
392
+
394
393
  if result
395
394
  on_async_data_preloaded(index)
396
395
  @preloader_queue[queue_id] = :completed
397
396
  end
397
+ @strong_refs[queue_id] = nil
398
398
  end
399
399
  load_count
400
400
  end
@@ -22,6 +22,16 @@ module MotionPrime
22
22
  end
23
23
 
24
24
  def tableView(table, cellForRowAtIndexPath: index)
25
+ curCallTime = Time.now.to_f
26
+ curCallOffset = table.contentOffset.y
27
+ if @prevCallTime
28
+ timeDelta = curCallTime - @prevCallTime
29
+ offsetDelta = curCallOffset - @prevCallOffset
30
+ @deceleration_speed = offsetDelta/timeDelta
31
+ end
32
+ @prevCallTime = curCallTime
33
+ @prevCallOffset = curCallOffset
34
+
25
35
  table_section.cell_for_index(table, index)
26
36
  end
27
37
 
@@ -1,3 +1,3 @@
1
1
  module MotionPrime
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -32,10 +32,11 @@ module MotionPrime
32
32
  {
33
33
  'UIView' => Proc.new {|klass, options| klass.alloc.initWithFrame CGRectZero },
34
34
  'UILabel' => Proc.new {|klass, options|
35
- if options.slice(:line_spacing, :underline, :fragment_color).any?
35
+ if options.slice(:line_spacing, :line_height, :underline, :fragment_color).any?
36
36
  options[:attributed_text_options] = {
37
37
  text: options.delete(:text),
38
38
  line_spacing: options.delete(:line_spacing),
39
+ line_height: options.delete(:line_height),
39
40
  fragment_color: options.delete(:fragment_color),
40
41
  underline: options.delete(:underline)
41
42
  }
@@ -132,11 +133,13 @@ module MotionPrime
132
133
  },
133
134
  'UIWebView' => Proc.new{|klass, options|
134
135
  web_view = klass.alloc.initWithFrame CGRectZero
136
+ if delegate = options.delete(:delegate)
137
+ web_view.delegate = delegate
138
+ end
135
139
  if url = options.delete(:url)
136
140
  request = NSURLRequest.requestWithURL url.nsurl
137
- web_view.loadRequest request
141
+ web_view.loadRequest(request)
138
142
  end
139
- web_view.delegate = options.delete(:delegate)
140
143
  web_view
141
144
  }
142
145
  }
@@ -106,9 +106,9 @@ module MotionPrime
106
106
  view.mask = mask_layer
107
107
  elsif key == 'attributed_text_options'
108
108
  attributes = {}
109
- if line_spacing = value[:line_spacing]
109
+ if line_spacing = value[:line_spacing] || line_height = value[:line_height]
110
110
  paragrahStyle = NSMutableParagraphStyle.alloc.init
111
- paragrahStyle.setLineSpacing(line_spacing)
111
+ line_height ? paragrahStyle.setMinimumLineHeight(line_height) : paragrahStyle.setLineSpacing(line_spacing)
112
112
  attributes[NSParagraphStyleAttributeName] = paragrahStyle
113
113
  end
114
114
 
data/spec/prime/env.rb ADDED
@@ -0,0 +1,20 @@
1
+ describe "Prime.env" do
2
+
3
+ before do
4
+ ENV['PRIME_ENV'] = 'staging'
5
+ end
6
+
7
+ it 'to_s should return string' do
8
+ Prime.env.to_s.is_a?(String).should.be.true
9
+ end
10
+
11
+ it 'should be comparable with string' do
12
+ (Prime.env == 'staging').should.be.true
13
+ (Prime.env == 'test').should.be.false
14
+ end
15
+
16
+ it 'should respond to question mark' do
17
+ Prime.env.staging?.should.be.true
18
+ Prime.env.test?.should.be.false
19
+ end
20
+ end
@@ -2,7 +2,6 @@ describe MotionPrime::Screen do
2
2
 
3
3
  before do
4
4
  @screen = BaseScreen.new()
5
- @screen.on_load
6
5
  @screen.will_appear
7
6
  end
8
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-prime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iskander Haziev
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-10 00:00:00.000000000 Z
12
+ date: 2014-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -325,6 +325,7 @@ files:
325
325
  - spec/models/model_spec.rb
326
326
  - spec/models/store_extension_spec.rb
327
327
  - spec/models/store_spec.rb
328
+ - spec/prime/env.rb
328
329
  - spec/screens/screen_spec.rb
329
330
  - travis.sh
330
331
  homepage: ''
@@ -366,4 +367,5 @@ test_files:
366
367
  - spec/models/model_spec.rb
367
368
  - spec/models/store_extension_spec.rb
368
369
  - spec/models/store_spec.rb
370
+ - spec/prime/env.rb
369
371
  - spec/screens/screen_spec.rb