motion-kit 0.10.9 → 0.10.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 348196a56892ff0ad347266474498ae0a19760d6
4
- data.tar.gz: c66ff3d7c8d21a761f01229ffea31e2b41f352ad
3
+ metadata.gz: bc88d9d5ae26923a6a1537869a7decb22435fa71
4
+ data.tar.gz: 232df310d55a46eb997ddb1c343edf58aa8c193c
5
5
  SHA512:
6
- metadata.gz: cc85df6f4dc0746984ef77eadecf14e4d3f56169824cc0f9da78b80f77e458f45cc311872eb6fe1875f8f5ca1578e156f6548ad39ed17b9a17710e33d2ce2898
7
- data.tar.gz: 6e01ee6d4b90b0fd2c2652f131047c5f45d06409e8559fcc98c0bfad6faae1c344abdf72dd2be96e4f54fea8aa2f951348150714fe476e0cb7cb06eca2b354bd
6
+ metadata.gz: 9115565f3d88b37e5ea4f637bf1d67f5641133a12f42504072db87a3306373efbd6231abf018faae85e79889b1519314ef8a7799fa3715afd7d0fd5ed49bbecf
7
+ data.tar.gz: bde50f100e9705156cb5ec8897ac683466679a478b1f48202ac97e18a566d3960c64363e1663e95fd27b9eaabc342792f02f35b1c46b413995009f390997a6ab
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # MotionKit
2
2
 
3
+ [![Build Status](https://travis-ci.org/motion-kit/motion-kit.svg?branch=master)](https://travis-ci.org/motion-kit/motion-kit)
4
+ [![Version](https://badge.fury.io/rb/motion-kit.svg)](https://rubygems.org/gems/motion-kit)
5
+
3
6
  *The RubyMotion layout and styling gem.*
4
7
 
5
8
  1. Crossplatform compatibility: iOS, OSX, and planned support for Android
@@ -18,7 +18,7 @@ module MotionKit
18
18
 
19
19
  def initialize(args={})
20
20
  # @layout is the object we look in for style methods
21
- @layout = self
21
+ @layout = nil
22
22
  # the Layout object that implements custom style methods. Leave this as nil
23
23
  # in the initializer.
24
24
  @layout_delegate = nil
@@ -27,22 +27,30 @@ module MotionKit
27
27
  # Explicit roots will not have a strong reference from
28
28
  # MotionKit, so retain one yourself from your controller
29
29
  # or other view to prevent deallocation.
30
- @preset_root = WeakRef.new(args[:root])
30
+ @preset_root = args[:root]
31
31
  end
32
32
 
33
33
  def set_layout(layout)
34
34
  @layout = WeakRef.new(layout)
35
35
  end
36
36
 
37
+ def parent_layout
38
+ @layout || self
39
+ end
40
+
41
+ def is_parent_layout?
42
+ @layout.nil? || @layout == self
43
+ end
44
+
37
45
  def target
38
- if @layout.nil? || @layout == self
46
+ if is_parent_layout?
39
47
  # only the "root layout" instance is allowed to change the context.
40
48
  # if there isn't a context set, try and create a root instance; this
41
49
  # will fail if we're not in a state that allows the root to be created
42
50
  @context ||= create_default_root_context
43
51
  else
44
52
  # child layouts get the context from the root layout
45
- @layout.target
53
+ parent_layout.target
46
54
  end
47
55
  end
48
56
  def v ; target ; end
@@ -76,7 +84,7 @@ module MotionKit
76
84
  return target unless block
77
85
  # this little line is incredibly important; the context is only set on
78
86
  # the top-level Layout object.
79
- return @layout.context(target, &block) if @layout != self
87
+ return parent_layout.context(target, &block) unless is_parent_layout?
80
88
 
81
89
  if target.is_a?(Symbol)
82
90
  target = self.get(target)
@@ -92,7 +100,7 @@ module MotionKit
92
100
  end
93
101
  @parent = MK::Parent.new(context_was)
94
102
  @context = target
95
- @context.motion_kit_meta[:delegate] ||= Layout.layout_for(@layout, @context.class)
103
+ @context.motion_kit_meta[:delegate] ||= Layout.layout_for(parent_layout, @context.class)
96
104
  @layout_delegate = @context.motion_kit_meta[:delegate]
97
105
  yield
98
106
  @layout_delegate, @context, @parent = delegate_was, context_was, parent_was
@@ -108,7 +116,7 @@ module MotionKit
108
116
  # after a call to Layout#layout.
109
117
  def deferred(context=nil, &block)
110
118
  context ||= @context
111
- return @layout.add_deferred_block(context, &block)
119
+ return parent_layout.add_deferred_block(context, &block)
112
120
  end
113
121
 
114
122
  # Only intended for private use
@@ -201,7 +209,7 @@ module MotionKit
201
209
  objc_method_name, objc_method_args = objc_version(method_name, args)
202
210
  ruby_method_name = ruby_version(method_name)
203
211
 
204
- @layout_delegate ||= Layout.layout_for(@layout, target.class)
212
+ @layout_delegate ||= Layout.layout_for(parent_layout, target.class)
205
213
  if objc_method_name && @layout_delegate.respond_to?(objc_method_name)
206
214
  return @layout_delegate.send(objc_method_name, *objc_method_args, &block)
207
215
  elsif @layout_delegate.respond_to?(ruby_method_name)
@@ -269,8 +277,6 @@ module MotionKit
269
277
  end
270
278
  end
271
279
 
272
- public
273
-
274
280
  class << self
275
281
 
276
282
  # Prevents infinite loops when methods that are defined on Object/Kernel
@@ -295,6 +301,13 @@ module MotionKit
295
301
 
296
302
  end
297
303
 
304
+ protected
305
+
306
+ def preset_root
307
+ # Set in the initializer
308
+ # TreeLayout.new(root: some_view)
309
+ @preset_root
310
+ end
298
311
 
299
312
  end
300
313
 
@@ -50,8 +50,8 @@ module MotionKit
50
50
 
51
51
  # The main view. This method builds the layout and returns the root view.
52
52
  def view
53
- if @layout != self
54
- return @layout.view
53
+ unless is_parent_layout?
54
+ return parent_layout.view
55
55
  end
56
56
  @view ||= build_view
57
57
  end
@@ -142,9 +142,9 @@ module MotionKit
142
142
 
143
143
  def call_style_method(element, element_id)
144
144
  style_method = "#{element_id}_style"
145
- if @layout.respond_to?(style_method)
146
- @layout.context(element) do
147
- @layout.send(style_method)
145
+ if parent_layout.respond_to?(style_method)
146
+ parent_layout.context(element) do
147
+ parent_layout.send(style_method)
148
148
  end
149
149
  end
150
150
  return element
@@ -214,8 +214,8 @@ module MotionKit
214
214
  # with this element_id in the tree, where *first* means the view closest to
215
215
  # the root view. Aliased to `first` to distinguish it from `last`.
216
216
  def get(element_id)
217
- if @layout != self
218
- return @layout.get(element_id)
217
+ unless is_parent_layout?
218
+ return parent_layout.get(element_id)
219
219
  end
220
220
  self.get(element_id, in: self._root)
221
221
  end
@@ -231,8 +231,8 @@ module MotionKit
231
231
  # with this element_id, where last means the view deepest and furthest from
232
232
  # the root view.
233
233
  def last(element_id)
234
- if @layout != self
235
- return @layout.last(element_id)
234
+ unless is_parent_layout?
235
+ return parent_layout.last(element_id)
236
236
  end
237
237
  self.last(element_id, in: self._root)
238
238
  end
@@ -244,8 +244,8 @@ module MotionKit
244
244
 
245
245
  # Returns all the elements with a given element_id in the view tree.
246
246
  def all(element_id)
247
- if @layout != self
248
- return @layout.all(element_id)
247
+ unless is_parent_layout?
248
+ return parent_layout.all(element_id)
249
249
  end
250
250
  self.all(element_id, in: self._root)
251
251
  end
@@ -268,8 +268,8 @@ module MotionKit
268
268
  # Removes a view (or several with the same name) from the hierarchy
269
269
  # and forgets it entirely. Returns the views that were removed.
270
270
  def remove(element_id)
271
- if @layout != self
272
- return @layout.remove(element_id)
271
+ unless is_parent_layout?
272
+ return parent_layout.remove(element_id)
273
273
  end
274
274
  self.remove(element_id, from: self._root)
275
275
  end
@@ -297,12 +297,6 @@ module MotionKit
297
297
 
298
298
  protected
299
299
 
300
- def preset_root
301
- # Set in the initializer
302
- # TreeLayout.new(root: some_view)
303
- @preset_root
304
- end
305
-
306
300
  # This method builds the layout and returns the root view.
307
301
  def build_view
308
302
  # Only in the 'layout' method will we allow default container to be
@@ -314,6 +308,7 @@ module MotionKit
314
308
  unless @view
315
309
  if @assign_root
316
310
  create_default_root_context
311
+ @view = @context
317
312
  else
318
313
  NSLog('Warning! No root view was set in TreeLayout#layout. Did you mean to call `root`?')
319
314
  end
@@ -326,6 +321,11 @@ module MotionKit
326
321
  # it's previous value
327
322
  @context = nil
328
323
 
324
+ if @preset_root
325
+ @view = WeakRef.new(@view)
326
+ @preset_root = nil
327
+ end
328
+
329
329
  @view
330
330
  end
331
331
 
@@ -350,7 +350,7 @@ module MotionKit
350
350
  # `ViewLayout`, which returns the root view.
351
351
  def initialize_element(elem)
352
352
  if elem.is_a?(Class) && elem < TreeLayout
353
- elem = elem.new_child(@layout).view
353
+ elem = elem.new_child(parent_layout).view
354
354
  elsif elem.is_a?(Class)
355
355
  elem = elem.new
356
356
  elsif elem.is_a?(TreeLayout)
@@ -1,3 +1,3 @@
1
1
  module MotionKit
2
- VERSION = '0.10.9'
2
+ VERSION = '0.10.10'
3
3
  end
@@ -0,0 +1,74 @@
1
+ describe 'MemoryLeaks' do
2
+
3
+ before do
4
+ window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
5
+ @controller = UINavigationController.new
6
+ @controller.viewControllers = [UIViewController.new, TestMemoryLeakController.new]
7
+ window.rootViewController = @controller
8
+ window.makeKeyAndVisible
9
+
10
+ @did_dealloc_controller = false
11
+ @did_dealloc_layout = false
12
+ @did_dealloc_cell = false
13
+ @did_dealloc_cell_layout = false
14
+
15
+ @observe_controller = NSNotificationCenter.defaultCenter.addObserverForName('TestMemoryLeakController dealloc', object: nil, queue: nil, usingBlock: -> notification do
16
+ @did_dealloc_controller = true
17
+ end)
18
+ @observe_layout = NSNotificationCenter.defaultCenter.addObserverForName('TestMemoryLeakLayout dealloc', object: nil, queue: nil, usingBlock: -> notification do
19
+ @did_dealloc_layout = true
20
+ end)
21
+ @observe_cell = NSNotificationCenter.defaultCenter.addObserverForName('TestMemoryLeakCell dealloc', object: nil, queue: nil, usingBlock: -> notification do
22
+ @did_dealloc_cell = true
23
+ end)
24
+ @observe_cell_layout = NSNotificationCenter.defaultCenter.addObserverForName('TestMemoryLeakCellLayout dealloc', object: nil, queue: nil, usingBlock: -> notification do
25
+ @did_dealloc_cell_layout = true
26
+ end)
27
+ end
28
+
29
+ after do
30
+ NSNotificationCenter.defaultCenter.removeObserver(@observe_controller)
31
+ NSNotificationCenter.defaultCenter.removeObserver(@observe_layout)
32
+ NSNotificationCenter.defaultCenter.removeObserver(@observe_cell)
33
+ NSNotificationCenter.defaultCenter.removeObserver(@observe_cell_layout)
34
+ end
35
+
36
+ describe 'When popping a controller' do
37
+
38
+ before do
39
+ wait 0.1 do
40
+ @controller.popViewControllerAnimated(false)
41
+
42
+ # window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
43
+ # window.rootViewController = @controller
44
+ # window.makeKeyAndVisible
45
+ end
46
+ end
47
+
48
+ it 'should release the TestMemoryLeakController' do
49
+ wait 0.1 do
50
+ @did_dealloc_controller.should == true
51
+ end
52
+ end
53
+
54
+ it 'should release the TestMemoryLeakLayout' do
55
+ wait 0.1 do
56
+ @did_dealloc_layout.should == true
57
+ end
58
+ end
59
+
60
+ it 'should release the TestMemoryLeakCell' do
61
+ wait 0.1 do
62
+ @did_dealloc_cell.should == true
63
+ end
64
+ end
65
+
66
+ it 'should release the TestMemoryLeakCellLayout' do
67
+ wait 0.1 do
68
+ @did_dealloc_cell_layout.should == true
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.9
4
+ version: 0.10.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Colin T.A. Gray
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-07 00:00:00.000000000 Z
12
+ date: 2014-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dbt
@@ -109,6 +109,7 @@ files:
109
109
  - spec/ios/layout_extensions_spec.rb
110
110
  - spec/ios/layout_spec.rb
111
111
  - spec/ios/layout_state_spec.rb
112
+ - spec/ios/memory_leak_spec.rb
112
113
  - spec/ios/motionkit_util_spec.rb
113
114
  - spec/ios/objc_selectors_spec.rb
114
115
  - spec/ios/orientation_helper_specs.rb
@@ -187,6 +188,7 @@ test_files:
187
188
  - spec/ios/layout_extensions_spec.rb
188
189
  - spec/ios/layout_spec.rb
189
190
  - spec/ios/layout_state_spec.rb
191
+ - spec/ios/memory_leak_spec.rb
190
192
  - spec/ios/motionkit_util_spec.rb
191
193
  - spec/ios/objc_selectors_spec.rb
192
194
  - spec/ios/orientation_helper_specs.rb