-
Notifications
You must be signed in to change notification settings - Fork 1
/
framer-navigation.coffee
120 lines (103 loc) · 3.43 KB
/
framer-navigation.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Framer.Defaults.Animation =
curve: "spring(400,40,0)"
Framer.Navigation =
history: []
Framer.Navigation.initialize = (layers) ->
Framer.Navigation.layers = layers
Framer.Navigation.makeLayerShortcuts()
Framer.Navigation.setupBackButtons()
Framer.Navigation.setupScreenNavigation()
Framer.Navigation.setupHamburgerMenus()
Framer.Navigation.makeLayerShortcuts = ->
for layer of Framer.Navigation.layers
window[layer] = Framer.Navigation.layers[layer]
Framer.Navigation.everyLayer = (fn, currentLayer) ->
if currentLayer
fn currentLayer
for subLayer in currentLayer.subLayers
Framer.Navigation.everyLayer fn, subLayer
else
for layerName of Framer.Navigation.layers
layer = Framer.Navigation.layers[layerName]
Framer.Navigation.everyLayer fn, layer
Framer.Navigation.setupBackButtons = ->
Framer.Navigation.everyLayer (layer) ->
layer.onClickSlideBack() if layer.name.endsWith 'Back_Button'
Framer.Navigation.setupScreenNavigation = ->
Framer.Navigation.everyLayer (layer) ->
match = layer.name.match(/Goto_(.*)/)
if match and match[1] and match[1].length isnt 0
layer.onClickSlideTo Framer.Navigation.layers[match[1]]
Framer.Navigation.setupHamburgerMenus = ->
Framer.Navigation.everyLayer (layer) ->
if layer.name.endsWith 'Hamburger'
layer.on Events.Click, showAppDrawer
String::endsWith = (suffix) ->
@indexOf(suffix, @length - suffix.length) isnt -1
# getScreen - returns the Screen layer containing this layer
Layer::getScreen = ->
superLayer = @_superLayer
if (superLayer is null)
return null
else if (superLayer.name.endsWith 'Screen')
superLayer
else
superLayer.getScreen()
Layer::slideOffLeft = ->
@animate
properties:
x: -640
Layer::slideFromRight = ->
@bringToFront()
@x = 640
@visible = true
@opacity = 1
@animate
properties:
x: 0
Layer::slideOffRight = ->
@animate
properties:
x: 640
Layer::slideFromLeft = ->
@bringToFront()
@x = -640
@visible = true
@opacity = 1
@animate
properties:
x: 0
hideAppDrawer = (event, layer) ->
Framer.Navigation.hamburgerVisible = false
layer.animate
properties:
x: 0
layer.off Events.Click, hideAppDrawer
showAppDrawer = (event, layer) ->
currentScreen = @getScreen()
unless Framer.Navigation.hamburgerVisible
Hamburger_Drawer.opacity = 1
Hamburger_Drawer.visible = true
Hamburger_Drawer.x = 0
Framer.Navigation.hamburgerVisible = true
Hamburger_Drawer.placeBehind currentScreen
currentScreen.animate
properties:
x: -540
setTimeout ( ->
currentScreen.on Events.Click, hideAppDrawer
), 100
Layer::onClickSlideTo = (newScreen) ->
@on Events.Click, ->
currentScreen = @getScreen()
if currentScreen isnt newScreen
currentScreen.slideOffLeft()
newScreen.slideFromRight()
Framer.Navigation.history.push currentScreen
Layer::onClickSlideBack = ->
@on Events.Click, ->
if history.length isnt 0
currentScreen = @getScreen()
currentScreen.slideOffRight()
backScreen = Framer.Navigation.history.pop()
backScreen.slideFromLeft()