This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
John Marstall
Posted Sep 27 - Read on Facebook

How do you refer to a layer from within its initialization?

For example:

for layer in [1]
layer = new Layer
layer.name = "tabBar"
layer.height = 98
layer.y = Screen.height - layer.height

works,

but

tabBar = new Layer
height: 98
y: Screen.height - this.height

does not. Is there a better, supported solution?

(you'll have to imagine the correct indentation, don't know how to do that on Facebook)

6 Comments

Brian Williams

@, in functions/ constructor otherwise just the property name

Benjamin Den Boer

Hiya John Marstall, yeah, you can't reference the layer variable name or "this" from within the constructor. I often just use a variable outside of the layer constructor when I need one property to reference another, like:

size = 500

layerA = new Layer
____width: size
____height: size / 2

Jonas Treub

Framer has a built-in solution to bottom align a layer:
new Layer
y: Align.bottom

John Marstall

Thanks guys. Using "align" in the constructor is the correct answer here but I could see where more advanced calculations would be needed, say if you wanted a bottom margin. Appreciate it though.

Jonas Treub

You can add the margin as a function parameter. Like:
Align.bottom(10)

John Marstall

Ah, right! /slaps forehead

Read the entire post on Facebook