SlideShare une entreprise Scribd logo
1  sur  31
Kill the Controllers
Kill the Controllers
A terrible great way refactor large applications.
Yes, there are models, fetched and
created by the controller
Yes, views, too. The controller makes
em!
API Queries, UI, animations,
network availability, login status, UI
events,
ticket purchasing, Facebook login, caching,
scrolling updates, image downloading and processing,
search filters, recommendations, notifications, sharing…
State
API
Models
Views
Layout
Storage
Controller
API
Models
Views
Controller
MVC?
MVC?❌
MQVLCS
Storage
Controller
Layout
View
Query
Model
wat
credit: LimeCoconutShake from www.skyblock.net
The benefits are many!
• Classes focus on one task
• Controllers don’t “do it all”
• Less code bloat all around
• Testable controllers
• Easier to add new features
• Easier to read and understand
– Colin T.A. Gray
“Don’t quote me on any of that.”
• Layout?
• Storage? WTF is that?
• Models & Queries?It’s your call.
Again, up to you.
There’s a gem for that. ;-)
credit: Gant Laborde
• Animations
• Events
• Styles
• Imagine a controller and a view
got together and had an adorable
love child
• Move your UI code out of your
controller:
• Support for iOS and OS X
• Support for CALayer, NSMenu
• Frame and AutoLayout DSLs
• Add your own helpers just by
defining a class
class LoginLayout < MK::Layout # or < MK::WindowLayout
# or < MK::MenuLayout
view :username_field
view :submit_button # @layout.submit_button
def layout
background_color UIColor.blackColor
add UILabel, :login_label
add UIView, :login_container do
add UITextField, :username_field
add UIButton, :submit_button
end
end
end
def login_label_style
initial do # only apply when views are created
text 'Login'
backgroundColor UIColor.clearColor
font UIFont.boldSystemFontOfSize(40)
textAlignment UITextAlignmentCenter
layer do
shadowRadius 20
shadowOpacity 0.5
masksToBounds false
end
constraints do
width('100%')
center_x.equals(:superview)
end
end
end
# separate method to work with controller.topLayoutGuide
def add_constraints(controller)
constraints(self.view) do
origin [0, 0]
width.equals(:superview)
height.equals(:superview)
end
constraints(:login_label) do
below(controller.topLayoutGuide).plus(50)
# define top_margin: 50
# below(controller.topLayoutGuide).plus(:top_margin)
end
end
MotionKit Extensions
def label_style
frame from_top(:container, width: 200)
frame below(:button)
frame left_of(:other_label)
x 0
y 0
right 320
bottom '100% - 8'
end
Frames
MotionKit Extensions
Constraints
def label_style
constraints do
left.equals(:superview, :left).plus(8)
right.equals(:button, :left).minus(8)
top_left.equals(:superview)
height.is <= 100
end
end
MotionKit Extensions
NSMenu
class MainMenu < MK::Menu
def layout
add 'File' do
add 'Open', action: 'open:', key: 'o'
add 'Close', action: 'close:', key: 'w'
add 'Foo', :foo_menu
add 'Bar', :bar_menu do
add 'Baz'
end
end
end
end
MotionKit Extensions
def label_style
autoresizing_mask :pin_to_top
layer do
backgroundColor UIColor.blackColor.CGColor
end
title 'Send'
title 'Done', state: UIControlStateDisabled
portrait do
frame [[0, 0], [100, 100]]
end
landscape do
frame [[20, 0], [140, 100]]
end
end
shadow_color UIColor.colorWithRed(0.133, green: 0.133, blue: 0.133)
text_color UIColor.colorWithRed(0.6, green: 0.6, blue: 0.6)
font UIFont.fontWithName(‘Avenir-Medium’, size: 20)
line_break_mode UILineBreakModeWordWrap
text_alignment NSTextAlignmentCenter
baseline_adjustment UIBaselineAdjustmentNone
SweetKit
Uses SugarCube methods to turn this…
shadow_color '#222222'
text_color '#999999'
font 'Avenir-Medium', size: 20
line_break_mode :word_wrap
text_alignment :center
baseline_adjustment :none
SweetKit
…into this!
MotionKit::Events
Decouple your UI events
class LoginLayout < MK::Layout
def login_button_style
target.on :touch do
trigger(:login, username_field.text.to_s,
@password_field.text.to_s)
end
end
end
class LoginController < UIViewController
def viewDidLoad
super
@layout = LoginLayout.new(root: self.view)
@layout.on :login do |username, password|
handle_login(username, password)
end
end
end
Roadmap
• View Layout helpers
• Spec helpers
• Layouts (e.g. Linear flow)
• Tutorials
• Screencasts
• Documentation
– Colin T.A. Gray
“Oh yeah, Jamon I forgot to tell you.”
class LoginLayout < MK::Layout
view :username_field
view :submit_button
def layout
add Android::Widget::LinearLayout, :login_container do
orientation VERTICAL
add Android::View::TextView, :username_field
add Android::View::Button, :submit_button
end
end
def submit_button_style
text 'Login'
end
end
MotionKit on Android
Kill the Controllers!
• Controllers should do the minimum
amount of “paper pushing”
• UI and animations → Layout
• Talking to the API → Storage
• etc. (Misc Task → Misc Class)
DEMO
Example of a LoginController written with
Storage and Layout classes.
You can see some similar code here:
github.com/rubymotion/motion-kit-events
Colin T.A. Gray
Community Manager at HipByte
Engineer at Jukely
github.com/colinta
github.com/rubymotion/motion-kit
gem install motion-kit
github.com/colinta/motion-xray
gem install motion-xray

Contenu connexe

Similaire à Kill the Controllers, and an introduction to MotionKit

How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabScilab
 
Lhy tutorial gui(1)
Lhy tutorial gui(1)Lhy tutorial gui(1)
Lhy tutorial gui(1)Brijesh Naik
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentanistar sung
 
RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014Henry Van Styn
 
What's new in Xamarin.Forms
What's new in Xamarin.FormsWhat's new in Xamarin.Forms
What's new in Xamarin.FormsRui Marinho
 
Optimizing Flex Applications
Optimizing Flex ApplicationsOptimizing Flex Applications
Optimizing Flex Applicationsdcoletta
 
The EffiChange XPager Suite: Understanding XPages Scaffolding
The EffiChange XPager Suite: Understanding XPages ScaffoldingThe EffiChange XPager Suite: Understanding XPages Scaffolding
The EffiChange XPager Suite: Understanding XPages ScaffoldingEffiChange LLC
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyUna Daly
 
Oracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptxOracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptxLuc Bors
 
A Guide to Creating a Great Custom Tailwind Sidebar
A Guide to Creating a Great Custom Tailwind SidebarA Guide to Creating a Great Custom Tailwind Sidebar
A Guide to Creating a Great Custom Tailwind SidebarRonDosh
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnukeNguyễn Anh
 
Invalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your CraniumInvalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your Craniumsakrirosenstrom
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementationdavejohnson
 
Just the Facets Ma'am ... MWLUG August 23, 2013, Indianapoilis, IN
Just the Facets Ma'am ... MWLUG August 23, 2013, Indianapoilis, INJust the Facets Ma'am ... MWLUG August 23, 2013, Indianapoilis, IN
Just the Facets Ma'am ... MWLUG August 23, 2013, Indianapoilis, INPaul Della-Nebbia
 
Just the Facets Ma'am - MWLUG 2013
Just the Facets Ma'am - MWLUG 2013Just the Facets Ma'am - MWLUG 2013
Just the Facets Ma'am - MWLUG 2013balassaitis
 
Google Chrome Developer Tools
Google Chrome Developer ToolsGoogle Chrome Developer Tools
Google Chrome Developer Toolstbmallf2e
 
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Joke Puts
 

Similaire à Kill the Controllers, and an introduction to MotionKit (20)

How to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in ScilabHow to develop a Graphical User Interface (GUI) in Scilab
How to develop a Graphical User Interface (GUI) in Scilab
 
Lhy tutorial gui(1)
Lhy tutorial gui(1)Lhy tutorial gui(1)
Lhy tutorial gui(1)
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
 
RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014RapidApp - YAPC::NA 2014
RapidApp - YAPC::NA 2014
 
What's new in Xamarin.Forms
What's new in Xamarin.FormsWhat's new in Xamarin.Forms
What's new in Xamarin.Forms
 
Web-First Design Patterns
Web-First Design PatternsWeb-First Design Patterns
Web-First Design Patterns
 
Optimizing Flex Applications
Optimizing Flex ApplicationsOptimizing Flex Applications
Optimizing Flex Applications
 
The EffiChange XPager Suite: Understanding XPages Scaffolding
The EffiChange XPager Suite: Understanding XPages ScaffoldingThe EffiChange XPager Suite: Understanding XPages Scaffolding
The EffiChange XPager Suite: Understanding XPages Scaffolding
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
Code camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una DalyCode camp 2011 Getting Started with IOS, Una Daly
Code camp 2011 Getting Started with IOS, Una Daly
 
Oracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptxOracle MAF real life OOW.pptx
Oracle MAF real life OOW.pptx
 
A Guide to Creating a Great Custom Tailwind Sidebar
A Guide to Creating a Great Custom Tailwind SidebarA Guide to Creating a Great Custom Tailwind Sidebar
A Guide to Creating a Great Custom Tailwind Sidebar
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnuke
 
Invalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your CraniumInvalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your Cranium
 
JavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern ImplementationJavaScript and DOM Pattern Implementation
JavaScript and DOM Pattern Implementation
 
Just the Facets Ma'am ... MWLUG August 23, 2013, Indianapoilis, IN
Just the Facets Ma'am ... MWLUG August 23, 2013, Indianapoilis, INJust the Facets Ma'am ... MWLUG August 23, 2013, Indianapoilis, IN
Just the Facets Ma'am ... MWLUG August 23, 2013, Indianapoilis, IN
 
Just the Facets Ma'am - MWLUG 2013
Just the Facets Ma'am - MWLUG 2013Just the Facets Ma'am - MWLUG 2013
Just the Facets Ma'am - MWLUG 2013
 
Google Chrome Developer Tools
Google Chrome Developer ToolsGoogle Chrome Developer Tools
Google Chrome Developer Tools
 
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
Introduction to Magento 2 module development - PHP Antwerp Meetup 2017
 
Test
TestTest
Test
 

Dernier

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 

Dernier (20)

Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 

Kill the Controllers, and an introduction to MotionKit

  • 2. Kill the Controllers A terrible great way refactor large applications.
  • 3. Yes, there are models, fetched and created by the controller Yes, views, too. The controller makes em! API Queries, UI, animations, network availability, login status, UI events, ticket purchasing, Facebook login, caching, scrolling updates, image downloading and processing, search filters, recommendations, notifications, sharing…
  • 10. The benefits are many! • Classes focus on one task • Controllers don’t “do it all” • Less code bloat all around • Testable controllers • Easier to add new features • Easier to read and understand
  • 11. – Colin T.A. Gray “Don’t quote me on any of that.”
  • 12. • Layout? • Storage? WTF is that? • Models & Queries?It’s your call. Again, up to you. There’s a gem for that. ;-)
  • 14. • Animations • Events • Styles • Imagine a controller and a view got together and had an adorable love child • Move your UI code out of your controller:
  • 15. • Support for iOS and OS X • Support for CALayer, NSMenu • Frame and AutoLayout DSLs • Add your own helpers just by defining a class
  • 16. class LoginLayout < MK::Layout # or < MK::WindowLayout # or < MK::MenuLayout view :username_field view :submit_button # @layout.submit_button def layout background_color UIColor.blackColor add UILabel, :login_label add UIView, :login_container do add UITextField, :username_field add UIButton, :submit_button end end end
  • 17. def login_label_style initial do # only apply when views are created text 'Login' backgroundColor UIColor.clearColor font UIFont.boldSystemFontOfSize(40) textAlignment UITextAlignmentCenter layer do shadowRadius 20 shadowOpacity 0.5 masksToBounds false end constraints do width('100%') center_x.equals(:superview) end end end
  • 18. # separate method to work with controller.topLayoutGuide def add_constraints(controller) constraints(self.view) do origin [0, 0] width.equals(:superview) height.equals(:superview) end constraints(:login_label) do below(controller.topLayoutGuide).plus(50) # define top_margin: 50 # below(controller.topLayoutGuide).plus(:top_margin) end end
  • 19. MotionKit Extensions def label_style frame from_top(:container, width: 200) frame below(:button) frame left_of(:other_label) x 0 y 0 right 320 bottom '100% - 8' end Frames
  • 20. MotionKit Extensions Constraints def label_style constraints do left.equals(:superview, :left).plus(8) right.equals(:button, :left).minus(8) top_left.equals(:superview) height.is <= 100 end end
  • 21. MotionKit Extensions NSMenu class MainMenu < MK::Menu def layout add 'File' do add 'Open', action: 'open:', key: 'o' add 'Close', action: 'close:', key: 'w' add 'Foo', :foo_menu add 'Bar', :bar_menu do add 'Baz' end end end end
  • 22. MotionKit Extensions def label_style autoresizing_mask :pin_to_top layer do backgroundColor UIColor.blackColor.CGColor end title 'Send' title 'Done', state: UIControlStateDisabled portrait do frame [[0, 0], [100, 100]] end landscape do frame [[20, 0], [140, 100]] end end
  • 23. shadow_color UIColor.colorWithRed(0.133, green: 0.133, blue: 0.133) text_color UIColor.colorWithRed(0.6, green: 0.6, blue: 0.6) font UIFont.fontWithName(‘Avenir-Medium’, size: 20) line_break_mode UILineBreakModeWordWrap text_alignment NSTextAlignmentCenter baseline_adjustment UIBaselineAdjustmentNone SweetKit Uses SugarCube methods to turn this…
  • 24. shadow_color '#222222' text_color '#999999' font 'Avenir-Medium', size: 20 line_break_mode :word_wrap text_alignment :center baseline_adjustment :none SweetKit …into this!
  • 25. MotionKit::Events Decouple your UI events class LoginLayout < MK::Layout def login_button_style target.on :touch do trigger(:login, username_field.text.to_s, @password_field.text.to_s) end end end class LoginController < UIViewController def viewDidLoad super @layout = LoginLayout.new(root: self.view) @layout.on :login do |username, password| handle_login(username, password) end end end
  • 26. Roadmap • View Layout helpers • Spec helpers • Layouts (e.g. Linear flow) • Tutorials • Screencasts • Documentation
  • 27. – Colin T.A. Gray “Oh yeah, Jamon I forgot to tell you.”
  • 28. class LoginLayout < MK::Layout view :username_field view :submit_button def layout add Android::Widget::LinearLayout, :login_container do orientation VERTICAL add Android::View::TextView, :username_field add Android::View::Button, :submit_button end end def submit_button_style text 'Login' end end MotionKit on Android
  • 29. Kill the Controllers! • Controllers should do the minimum amount of “paper pushing” • UI and animations → Layout • Talking to the API → Storage • etc. (Misc Task → Misc Class)
  • 30. DEMO Example of a LoginController written with Storage and Layout classes. You can see some similar code here: github.com/rubymotion/motion-kit-events
  • 31. Colin T.A. Gray Community Manager at HipByte Engineer at Jukely github.com/colinta github.com/rubymotion/motion-kit gem install motion-kit github.com/colinta/motion-xray gem install motion-xray

Notes de l'éditeur

  1. These ideas are used throughout programming Think of Sandi Metz’ “rules for developers” applied to a controller I was a skeptic, but came to this style working on Jukely, and it’s been great
  2. These ideas are used throughout programming Think of Sandi Metz’ “rules for developers” applied to a controller I was a skeptic, but came to this style working on Jukely, and it’s been great
  3. We used Parse for the Models and Queries UILabels and UIButtons for views So where does everything else go?
  4. Ends up looking like this After refactoring, we can get to this situation Also not, Layout between C & V, and “Storage aka Adapter” between C & M
  5. MVC doesn’t provide enough “buckets” Introducing: Meh kuh Vulcs
  6. MVC doesn’t provide enough “buckets” Introducing: Meh kuh Vulcs
  7. MVC doesn’t provide enough “buckets” Introducing: Meh kuh Vulcs
  8. MVC doesn’t provide enough “buckets” Introducing: Meh kuh Vulcs
  9. “Don’t quote me on any of that.”
  10. Layouts are not just “styling code dumping grounds”. Share knowledge with the controller Animations, events, and of course styles
  11. Multiple platform support Helpers can target any class AutoLayout DSL has been really popular Easy to add your own, or create a motion-kit-gem
  12. Extend the MK::Layout class (or menu or window). Ideally you WON’T need to create accessor methods Code inside the block acts on the “current context”
  13. Not really as much magic as you might think, other than the delegation stuff.
  14. Check the README, it’s current the best source of information, and READMORE.md for some interesting information. “Oh yeah, Jamon I forgot to tell you.”
  15. “Speaking of a team of laser guided fly swatters…”