motion-kit 0.18.0 → 1.0.0

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -1
  3. data/lib/motion-kit-tvos/deprecated.rb +31 -0
  4. data/lib/motion-kit-tvos/dummy.rb +93 -0
  5. data/lib/motion-kit-tvos/helpers/constraints_helpers.rb +24 -0
  6. data/lib/motion-kit-tvos/helpers/layout_device.rb +36 -0
  7. data/lib/motion-kit-tvos/helpers/layout_orientation.rb +54 -0
  8. data/lib/motion-kit-tvos/helpers/uibutton_helpers.rb +52 -0
  9. data/lib/motion-kit-tvos/helpers/uiview_autoresizing_helpers.rb +79 -0
  10. data/lib/motion-kit-tvos/helpers/uiview_constraints_helpers.rb +36 -0
  11. data/lib/motion-kit-tvos/helpers/uiview_frame_helpers.rb +316 -0
  12. data/lib/motion-kit-tvos/helpers/uiview_gradient_helpers.rb +22 -0
  13. data/lib/motion-kit-tvos/helpers/uiview_helpers.rb +28 -0
  14. data/lib/motion-kit-tvos/ios_util.rb +24 -0
  15. data/lib/motion-kit.rb +2 -0
  16. data/lib/motion-kit/version.rb +1 -1
  17. data/spec/tvos/apply_styles_spec.rb +37 -0
  18. data/spec/tvos/autoresizing_helper_spec.rb +240 -0
  19. data/spec/tvos/calayer_spec.rb +23 -0
  20. data/spec/tvos/calculate_spec.rb +322 -0
  21. data/spec/tvos/calculator_spec.rb +31 -0
  22. data/spec/tvos/child_layouts_spec.rb +65 -0
  23. data/spec/tvos/constraints_helpers/active_constraints_spec.rb +25 -0
  24. data/spec/tvos/constraints_helpers/attribute_lookup_spec.rb +27 -0
  25. data/spec/tvos/constraints_helpers/axis_lookup_spec.rb +13 -0
  26. data/spec/tvos/constraints_helpers/center_constraints_spec.rb +421 -0
  27. data/spec/tvos/constraints_helpers/constraint_placeholder_spec.rb +72 -0
  28. data/spec/tvos/constraints_helpers/priority_lookup_spec.rb +19 -0
  29. data/spec/tvos/constraints_helpers/relationship_lookup_spec.rb +27 -0
  30. data/spec/tvos/constraints_helpers/relative_corners_spec.rb +276 -0
  31. data/spec/tvos/constraints_helpers/relative_location_spec.rb +113 -0
  32. data/spec/tvos/constraints_helpers/scale_constraints_spec.rb +62 -0
  33. data/spec/tvos/constraints_helpers/simple_constraints_spec.rb +2755 -0
  34. data/spec/tvos/constraints_helpers/size_constraints_spec.rb +423 -0
  35. data/spec/tvos/constraints_helpers/view_lookup_constraints_spec.rb +95 -0
  36. data/spec/tvos/create_layout_spec.rb +40 -0
  37. data/spec/tvos/custom_layout_spec.rb +13 -0
  38. data/spec/tvos/custom_root_layout_spec.rb +57 -0
  39. data/spec/tvos/deferred_spec.rb +89 -0
  40. data/spec/tvos/device_helpers_spec.rb +58 -0
  41. data/spec/tvos/frame_helper_spec.rb +1160 -0
  42. data/spec/tvos/layer_layout_spec.rb +36 -0
  43. data/spec/tvos/layout_extensions_spec.rb +70 -0
  44. data/spec/tvos/layout_spec.rb +57 -0
  45. data/spec/tvos/layout_state_spec.rb +27 -0
  46. data/spec/tvos/memory_leak_spec.rb +74 -0
  47. data/spec/tvos/motion_kit_id_spec.rb +15 -0
  48. data/spec/tvos/motionkit_util_spec.rb +15 -0
  49. data/spec/tvos/nearest_spec.rb +80 -0
  50. data/spec/tvos/objc_selectors_spec.rb +10 -0
  51. data/spec/tvos/orientation_helper_specs.rb +67 -0
  52. data/spec/tvos/parent_layout_spec.rb +19 -0
  53. data/spec/tvos/parent_spec.rb +45 -0
  54. data/spec/tvos/prev_next_spec.rb +153 -0
  55. data/spec/tvos/reapply_frame.rb +64 -0
  56. data/spec/tvos/relative_layout.spec.rb +31 -0
  57. data/spec/tvos/remove_layout_spec.rb +28 -0
  58. data/spec/tvos/root_layout_spec.rb +53 -0
  59. data/spec/tvos/setters_spec.rb +63 -0
  60. data/spec/tvos/uibutton_layout_spec.rb +37 -0
  61. data/spec/tvos/uitextfield_spec.rb +14 -0
  62. data/spec/tvos/view_attr_spec.rb +32 -0
  63. metadata +118 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35471767d3b359768976d596f1c8c6e97231c02b
4
- data.tar.gz: 0278f47cc49bf7aa77906ef06f143f36ea52faf0
3
+ metadata.gz: 2c567bd9815d3e05e231e5ad9c823bb7800ad5e7
4
+ data.tar.gz: a815960a60ed988df0a3c0b9732492dbb04359d5
5
5
  SHA512:
6
- metadata.gz: c460d3c67c1f3cb4fa50f074061ead9c34c2e9c9dacda427bd728f8f2f1e4ff354c33907b3a00c6e498d6378668e6c359776d20dd51ff881890d54874ea13fe5
7
- data.tar.gz: fc2ec0c29a6244223a7ac889d98128e8dca3ec1b6a6d61bf350669b030eb0c48cbb2ff6640a72e2c121eb9b291ef09944acb02e4c8ab7b954a307b5e459a8aee
6
+ metadata.gz: be917bdbdf07b9fe387c08d4ff4cbcdc98c81d7156180e7fae3f2f798041bba3398085c5692a2b9a5264054d342f3d7415a1b6bfdbc3fa324fc048249d12426b
7
+ data.tar.gz: 5a11a4d4ddc081d2e09f6fce3cd485d442c457019456e6e3a957dce24c03a32d54f10a57ab9a9cd4b74adad76609aa08beb7c985d6f0e2041a74e830c69cb1f8
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # MotionKit
2
2
 
3
+ [![Join the chat at https://gitter.im/motion-kit/motion-kit](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/motion-kit/motion-kit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
3
5
  [![Build Status](https://travis-ci.org/motion-kit/motion-kit.svg?branch=master)](https://travis-ci.org/motion-kit/motion-kit)
4
6
  [![Version](https://badge.fury.io/rb/motion-kit.svg)](https://rubygems.org/gems/motion-kit)
5
7
 
6
8
  *The RubyMotion layout and styling gem.*
7
9
 
8
- 1. Crossplatform compatibility: iOS, OSX, and planned support for Android
10
+ 1. Crossplatform compatibility: iOS, OSX, tvOS and planned support for Android
9
11
  2. Simple, easy to learn DSL
10
12
  3. Crossframework compatibility:
11
13
  - [UIKit][readmore-uikit]
@@ -860,6 +862,42 @@ UIView.animateWithDuration(duration, delay: 0, options: curve, animations: -> do
860
862
  end, completion: nil)
861
863
  ```
862
864
 
865
+ You can also activate/deactivate constraints selectively, and animate the
866
+ transitions between them.
867
+
868
+ ```ruby
869
+ class MyLayout < MK::Layout
870
+
871
+ def layout
872
+ add UIButton, :my_button do
873
+ constraints do
874
+ @top_constraint = top.equals(:superview, :bottom)
875
+ @bottom_constraint = bottom.equals(:superview).deactivate
876
+ left.equals(:superview)
877
+ right.equals(:superview)
878
+ height 48
879
+ end
880
+ end
881
+
882
+ def show_button
883
+ @top_constraint.deactivate
884
+ @bottom_constraint.activate
885
+ UIView.animateWithDuration(0.3, animations: -> do
886
+ self.view.layoutIfNeeded
887
+ end)
888
+ end
889
+
890
+ def hide_button
891
+ @bottom_constraint.deactivate
892
+ @top_constraint.activate
893
+ UIView.animateWithDuration(0.3, animations: -> do
894
+ self.view.layoutIfNeeded
895
+ end)
896
+ end
897
+
898
+ end
899
+ ```
900
+
863
901
  ### MotionKit::Events
864
902
 
865
903
  gem install motion-kit-events
@@ -0,0 +1,31 @@
1
+ # @requires MotionKit::UIViewHelpers
2
+ # @requires MotionKit::UIButtonHelpers
3
+ # @requires MotionKit::CALayerHelpers
4
+ # @requires MotionKit::CAGradientLayerHelpers
5
+ module MotionKit
6
+
7
+ class UIViewLayout < UIViewHelpers
8
+ def self.inherited(subclass)
9
+ NSLog("Sorry! MotionKit changed. UIViewLayout is now UIViewHelpers. Update #{subclass} to extend from UIViewHelpers.")
10
+ end
11
+ end
12
+
13
+ class UIButtonLayout < UIButtonHelpers
14
+ def self.inherited(subclass)
15
+ NSLog("Sorry! MotionKit changed. UIButtonLayout is now UIButtonHelpers. Update #{subclass} to extend from UIButtonHelpers.")
16
+ end
17
+ end
18
+
19
+ class CALayerLayout < CALayerHelpers
20
+ def self.inherited(subclass)
21
+ NSLog("Sorry! MotionKit changed. CALayerLayout is now CALayerHelpers. Update #{subclass} to extend from CALayerHelpers.")
22
+ end
23
+ end
24
+
25
+ class CAGradientLayerLayout < CAGradientLayerHelpers
26
+ def self.inherited(subclass)
27
+ NSLog("Sorry! MotionKit changed. CAGradientLayerLayout is now CAGradientLayerHelpers. Update #{subclass} to extend from CAGradientLayerHelpers.")
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,93 @@
1
+ class DummyView < UIView
2
+ private
3
+ def dummy
4
+ setFrame(nil)
5
+ setOpaque(nil)
6
+ setClipsToBounds(nil)
7
+ setUserInteractionEnabled(nil)
8
+ UIView.appearanceWhenContainedIn(UIView, nil)
9
+ UIView.appearance
10
+ end
11
+ end
12
+
13
+ class DummyTableView < UITableView
14
+ private
15
+ def dummy
16
+ setAllowSelection(value)
17
+ end
18
+ end
19
+
20
+ class DummyButton < UIButton
21
+ private
22
+ def dummy
23
+ setTitleEdgeInsets(nil)
24
+ end
25
+ end
26
+
27
+ class DummyScrollView < UIScrollView
28
+ private
29
+ def dummy
30
+ setPagingEnabled(nil)
31
+ setScrollEnabled(nil)
32
+ setShowsHorizontalScrollIndicator(nil)
33
+ setShowsVerticalScrollIndicator(nil)
34
+ end
35
+ end
36
+
37
+ class DummyActivityIndicatorView < UIActivityIndicatorView
38
+ private
39
+ def dummy
40
+ setHidesWhenStopped(nil)
41
+ end
42
+ end
43
+
44
+ class DummyLabel < UILabel
45
+ private
46
+ def dummy
47
+ setAdjustsFontSizeToFitWidth(nil)
48
+ end
49
+ end
50
+
51
+ class DummyTextField < UITextField
52
+ private
53
+ def dummy
54
+ setSecureTextEntry(nil)
55
+ setReturnKeyType(nil)
56
+ setAutocapitalizationType(nil)
57
+ setAutocorrectionType(nil)
58
+ setSpellCheckingType(nil)
59
+ end
60
+ end
61
+
62
+ class DummyPickerView < UIPickerView
63
+ private
64
+ def dummy
65
+ setShowsSelectionIndicator(nil)
66
+ end
67
+ end
68
+
69
+ class DummyLayer < CALayer
70
+ private
71
+ def dummy
72
+ setCornerRadius(nil)
73
+ setTransform(nil)
74
+ setMasksToBounds(nil)
75
+ setShadowOffset(nil)
76
+ setShadowOpacity(nil)
77
+ setShadowRadius(nil)
78
+ setShadowOffset(nil)
79
+ setShadowColor(nil)
80
+ setShadowPath(nil)
81
+ setOpaque(nil)
82
+ setTranslucent(nil)
83
+ end
84
+ end
85
+
86
+ class DummySwitch < UISwitch
87
+ private
88
+ def dummy
89
+ on?
90
+ setOn(true)
91
+ end
92
+ end
93
+
@@ -0,0 +1,24 @@
1
+ # @requires MotionKit::UIViewHelpers
2
+ module MotionKit
3
+ class UIViewHelpers
4
+
5
+ def content_compression_resistance_priority(value, for_axis: axis)
6
+ axis = Constraint.axis_lookup(axis)
7
+ target.setContentCompressionResistancePriority(value, forAxis: axis)
8
+ end
9
+
10
+ def compression_priority(value, for_axis: axis)
11
+ content_compression_resistance_priority(value, for_axis: axis)
12
+ end
13
+
14
+ def content_hugging_priority(value, for_axis: axis)
15
+ axis = Constraint.axis_lookup(axis)
16
+ target.setContentHuggingPriority(value, forAxis: axis)
17
+ end
18
+
19
+ def hugging_priority(value, for_axis: axis)
20
+ content_hugging_priority(value, for_axis: axis)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ # @requires MotionKit::BaseLayout
2
+ module MotionKit
3
+ class BaseLayout
4
+
5
+ def tv?
6
+ UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomTV
7
+ end
8
+
9
+ def iphone?
10
+ UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPhone
11
+ end
12
+
13
+ def iphone4?
14
+ iphone? && UIScreen.mainScreen.bounds.size.width == 320 && UIScreen.mainScreen.bounds.size.height == 568
15
+ end
16
+
17
+ def iphone35?
18
+ iphone? && UIScreen.mainScreen.bounds.size.width == 320 && UIScreen.mainScreen.bounds.size.height == 480
19
+ end
20
+
21
+ def ipad?
22
+ UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad
23
+ end
24
+
25
+ def retina?
26
+ UIScreen.mainScreen.respond_to?(:scale) && UIScreen.mainScreen.scale == 2
27
+ end
28
+
29
+ [:tv, :iphone, :iphone4, :iphone35, :ipad, :retina].each do |method_name|
30
+ define_method(method_name) do |&block|
31
+ block.call if self.send("#{method_name}?")
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,54 @@
1
+ # @requires MotionKit::BaseLayout
2
+ module MotionKit
3
+ class BaseLayout
4
+
5
+ # This method is used to check the orientation. On an ipad, this method
6
+ # returns true for :portrait if the device is "upside down", but it returns
7
+ # false in the same situation on an iphone.
8
+ def orientation?(value)
9
+ if target.is_a?(UIView) && target.nextResponder && target.nextResponder.is_a?(UIViewController)
10
+ interface_orientation = target.nextResponder.interfaceOrientation
11
+ else
12
+ interface_orientation = UIApplication.sharedApplication.statusBarOrientation
13
+ end
14
+
15
+ return case value
16
+ when :portrait
17
+ if ipad?
18
+ interface_orientation == UIInterfaceOrientationPortrait || interface_orientation == UIInterfaceOrientationPortraitUpsideDown
19
+ else
20
+ interface_orientation == UIInterfaceOrientationPortrait
21
+ end
22
+ when :upright, UIInterfaceOrientationPortrait
23
+ interface_orientation == UIInterfaceOrientationPortrait
24
+ when :landscape
25
+ interface_orientation == UIInterfaceOrientationLandscapeLeft || interface_orientation == UIInterfaceOrientationLandscapeRight
26
+ when :landscape_left, UIInterfaceOrientationLandscapeLeft
27
+ interface_orientation == UIInterfaceOrientationLandscapeLeft
28
+ when :landscape_right, UIInterfaceOrientationLandscapeRight
29
+ interface_orientation == UIInterfaceOrientationLandscapeRight
30
+ when :upside_down, UIInterfaceOrientationPortraitUpsideDown
31
+ interface_orientation == UIInterfaceOrientationPortraitUpsideDown
32
+ end
33
+ end
34
+
35
+ [:portrait, :upright, :upside_down, :landscape, :landscape_left, :landscape_right].each do |orientation|
36
+ define_method("#{orientation}?") do
37
+ return orientation?(orientation)
38
+ end
39
+ define_method(orientation) do |&block|
40
+ orientation_block(orientation, block)
41
+ end
42
+ end
43
+
44
+ def orientation_block(orientation, block)
45
+ block = block.weak!
46
+ always do
47
+ if orientation?(orientation)
48
+ block.call
49
+ end
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,52 @@
1
+ # @provides MotionKit::UIButtonHelpers
2
+ # @requires MotionKit::UIViewHelpers
3
+ module MotionKit
4
+ class UIButtonHelpers < UIViewHelpers
5
+ targets UIButton
6
+
7
+ def title(value)
8
+ title(value, state: UIControlStateNormal)
9
+ end
10
+
11
+ def title(value, state: state)
12
+ if value.is_a?(NSAttributedString)
13
+ target.setAttributedTitle(value, forState: state)
14
+ else
15
+ target.setTitle(value, forState: state)
16
+ end
17
+ end
18
+
19
+ def title_color(value)
20
+ title_color(value, state: UIControlStateNormal)
21
+ end
22
+
23
+ def title_color(value, state: state)
24
+ target.setTitleColor(value, forState: state)
25
+ end
26
+
27
+ def title_shadow_color(value)
28
+ title_shadow_color(value, state: UIControlStateNormal)
29
+ end
30
+
31
+ def title_shadow_color(value, state: state)
32
+ target.setTitleShadowColor(value, forState: state)
33
+ end
34
+
35
+ def background_image(value)
36
+ background_image(value, state: UIControlStateNormal)
37
+ end
38
+
39
+ def background_image(value, state: state)
40
+ target.setBackgroundImage(value, forState: state)
41
+ end
42
+
43
+ def image(value)
44
+ image(value, state: UIControlStateNormal)
45
+ end
46
+
47
+ def image(value, state: state)
48
+ target.setImage(value, forState: state)
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,79 @@
1
+ # @requires MotionKit::UIViewHelpers
2
+ module MotionKit
3
+ class UIViewHelpers
4
+
5
+ def autoresizing_mask(*values)
6
+ value = 0
7
+ values.each do |mask|
8
+ case mask
9
+ when :flexible_left
10
+ value |= UIViewAutoresizingFlexibleLeftMargin
11
+ when :flexible_width
12
+ value |= UIViewAutoresizingFlexibleWidth
13
+ when :flexible_right
14
+ value |= UIViewAutoresizingFlexibleRightMargin
15
+ when :flexible_top
16
+ value |= UIViewAutoresizingFlexibleTopMargin
17
+ when :flexible_height
18
+ value |= UIViewAutoresizingFlexibleHeight
19
+ when :flexible_bottom
20
+ value |= UIViewAutoresizingFlexibleBottomMargin
21
+
22
+ when :rigid_left
23
+ value ^= UIViewAutoresizingFlexibleLeftMargin
24
+ when :rigid_width
25
+ value ^= UIViewAutoresizingFlexibleWidth
26
+ when :rigid_right
27
+ value ^= UIViewAutoresizingFlexibleRightMargin
28
+ when :rigid_top
29
+ value ^= UIViewAutoresizingFlexibleTopMargin
30
+ when :rigid_height
31
+ value ^= UIViewAutoresizingFlexibleHeight
32
+ when :rigid_bottom
33
+ value ^= UIViewAutoresizingFlexibleBottomMargin
34
+
35
+ when :fill
36
+ value |= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
37
+ when :fill_top
38
+ value |= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin
39
+ when :fill_bottom
40
+ value |= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin
41
+ when :fill_width
42
+ value |= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin
43
+ when :fill_left
44
+ value |= UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin
45
+ when :fill_right
46
+ value |= UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin
47
+ when :fill_height
48
+ value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin
49
+
50
+ when :pin_to_top_left
51
+ value |= UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin
52
+ when :pin_to_top
53
+ value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin
54
+ when :pin_to_top_right
55
+ value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin
56
+ when :pin_to_left
57
+ value |= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin
58
+ when :pin_to_center, :pin_to_middle
59
+ value |= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
60
+ when :pin_to_right
61
+ value |= UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin
62
+ when :pin_to_bottom_left
63
+ value |= UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
64
+ when :pin_to_bottom
65
+ value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin
66
+ when :pin_to_bottom_right
67
+ value |= UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin
68
+ else
69
+ value |= mask
70
+ end
71
+ end
72
+
73
+ target.autoresizingMask = value
74
+ value
75
+ end
76
+ alias autoresizingMask autoresizing_mask
77
+
78
+ end
79
+ end