Coder Social home page Coder Social logo

alandickinson / framer-view-stack Goto Github PK

View Code? Open in Web Editor NEW
25.0 2.0 0.0 945 KB

A Framer module for creating views that stack on top of each other.

License: MIT License

CoffeeScript 66.19% JavaScript 29.83% CSS 1.81% HTML 2.17%
framer prototyping framerjs

framer-view-stack's Introduction

Framer ViewStack Module

This is a module for the prototyping tool Framer. It helps you create and control views that stack on top of each other. You can swipe to dismiss them, or fan out the stack and select one to bring forward.

Swipe to dismiss Tap to fan out Scroll

Installation

  • Download the project from Github
  • Copy viewstack.coffee into the modules folder of your Framer project.
  • Import the module into your project by adding this line: ViewStack = require "viewstack"

Usage

Setup

Create the view stack, and then add a view to it using the addView method.

stack = new ViewStack.Manager

myview = stack.addView
  contents: myLayer

contents is required and can be a layer or an array of layers. These will get added to the view's ScrollView in the order they appear in the array, so list the elements from bottom to top. The ScrollView allows vertical scrolling, and its content layer is sized to fit the content you pass into it.

The view gets added but is kept off screen. To display it, use the presentView method.

All addView Options

myview = stack.addView
  contents: myLayer
  title: "My View"    # default: no title
  tintColor: "#fff"   # defualt: "#000"
  arrowColor: "#000"  # default: "rgba(0,0,0,0.4)"

Presenting Views

Use the presentView method to display a view on screen.

stack.presentView(myview)

When more than one view has been presented, they will stack.

Example

# create content layers
one = new Layer
  frame: Screen.frame
  backgroundColor: "rgba(0,128,255,1)"
two = new Layer
  frame: Screen.frame
  backgroundColor: "rgba(255,128,0,1)"

# create stack manager
ViewStack = require "viewstack"
stack = new ViewStack.Manager

# add views to the stack, passing in sketch layers with the contents parameter
view_one = stack.addView
	contents: one
	title: "One"
	tintColor: "#000"
view_two = stack.addView
	contents: two
	title: "Two"
	tintColor: "#000"

# add tap events to present views
one.on Events.Tap, ->
	stack.presentView(view_two)

# present first view
stack.presentView(view_one)

Fanning Out

When views are stacked onscreen tapping the top area will fan all of them out and let you select one. This is enabled by default, but you can turn it off by setting the fanOut parameter to false when you create the view stack.

stack = new ViewStack.Manager
  fanOut: false

You can also fan out the current stack of views programmatically with stack.fanOut() -- If there's more than one view on screen and the feature hasn't been disabled.

Managing Views

Changing Views

  • stack.dismissViews([views]) takes an array of views and will dismiss all of them.
  • stack.dismissCurrentView dismisses the view that's currently on top.
  • stack.switchToView(view) rearranges the stack to move a specific view to the front. This will dismiss any views that are above the view you pass in.

Helpers

Views have helper methods you can use to get access to specific layers.

  • myview.getScrollView() returns the ScrollComponent.
  • myview.getViewCover() returns the cover layer used to dim the view when its behind others.
  • myview.getHideBtn() returns the hide button.

To do

  • Fix a bug in the fanned out touch events
  • Add some error handling
  • Add more event hooks
  • Maybe just subclass Layer?
  • Make things more customizable -- animation curves, card styling, dismiss button, stack offset, etc.
  • Adjust the stacking offsets for different screen ratios (currently works best with iPhone 6 ratio)

framer-view-stack's People

Contributors

alandickinson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

framer-view-stack's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.