Getting started
How it works
How flemo moves screens: a stack of cards, a movement written down once, a swipe your finger drives, and the pieces that stay still.
flemo moves screens the way a phone app does. Here is what happens under the hood, from the stack of screens to the swipe that takes you back.
Screens are a stack of cards
Think of every screen in your app as a card. The Router keeps the cards in a pile. push puts a new card on top of the pile, and pop takes the top card off, so the one underneath shows again.
The cards underneath are never thrown away. They stay mounted while a new one sits on top, so when you come back, a list is still scrolled where you left it and a half-filled form still has its text.
The pile is also your browser history, so the Back button pops too. See .
The movement is written down first
A transition is a short recipe: where each screen starts and where it ends. When the Router starts, flemo turns every recipe into CSS keyframes, once.
Because the browser plays the CSS, no JavaScript runs on every frame of a push or a pop. That keeps the motion smooth even when the page is busy.
Which recipe plays is decided by each move, not by the screen: the Router has a default, and a push can name another one with transitionName. See .
One push, step by step
Here is what happens when you push a screen with the cupertino transition.
- The list is on screen.
- flemo renders the new screen and waits until it has been drawn once, so you never see an empty screen slide in.
- Both screens start at the same moment. The new one slides in from the right. The list moves back a little and gets darker, which is a .
- The new screen is on top of the stack. The list stays underneath, ready for when you go back.
A pop runs the same movement in reverse, without the wait in step 2: the screen underneath never left, so it is ready at once.
Only one move runs at a time. A tap that asks for another push or pop while one is running is ignored rather than saved for later, so tapping a button twice moves once.
Your finger drives the swipe
When you start swiping back (from the left edge with cupertino), flemo prepares the pop but does not play it. Instead, the distance your finger has moved decides how far along the pop is. Move your finger back and the screens move back with it.
When you let go, flemo looks at how far you swiped and how fast you were moving. If either is enough, the pop finishes. If not, the screens slide back to where they were. Either way the rest of the movement uses the transition's own easing.
The same thing on two screens
Sometimes the same thing appears on both screens, like a photo in a list that becomes the big photo on the next screen. Wrap it in Morph on both screens with the same layoutId.
flemo measures where the photo is on the old screen and where it will be on the new one. The photo on the new screen starts in the old spot and moves to its own place, so it looks like one photo that grew. See .
What stays still and what changes
Not everything has to move. Anything outside a Slot stays still while only the inside moves, which is how a header or a sidebar stays put. And when two screens share a header, Part changes only the piece that is different, such as the title.
See and . To draw a menu above that header, use .
Stacks inside stacks
A screen can hold another Router. That inner Router has its own pile of cards and moves only inside its box, which is how a tab or a panel gets its own back button.
builds an app with all of these, one step at a time.