How to use the react-spring.interpolate function in react-spring

To help you get started, we’ve selected a few react-spring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pylnata / livebook / src / Book.js View on Github external
//                interpolate(
              //                  [bgRad, bgPos],
              //                  (bgRad, bgPos) =>
              //                    `linear-gradient(${90+bgRad}deg, rgb(0, 0, 0, 0.3) 0%,rgba(184, 184, 184, 0) ${300-bgPos}px)`
              //                )
              WebkitClipPath: interpolate(
                [x1, y1, x2, y2, x3, y3, x4, y4, x5, y5],
                (x1, y1, x2, y2, x3, y3, x4, y4, x5, y5) => {
                  if (x5 === undefined) x5 = x4;
                  if (y5 === undefined) y5 = y4;
                  return `polygon(${x1}px ${y1}px, ${x2}px ${y2}px, ${x3}px ${y3}px, ${x4}px ${y4}px, ${x5}px ${y5}px )`;
                }
              ),

              transformOrigin: i % 2 === 0 ? pageWidth + "px 0px" : "0px 0px",
              transform: interpolate(
                [x, y, r, scaleX],
                (x, y, r, scaleX) =>
                  `translateX(${x}px) translateY(${y}px) rotate(${r}rad) scaleX(${scaleX})`
              )
            }}
            className={`page page--${i} `}
            {...bind(i)}
          >
            <div></div>
          
          {false &amp;&amp; i === index.value + 2 &amp;&amp; (
github CrowdLinker / react-pager / src / pager.tsx View on Github external
if (Array.isArray(prop)) {
      let transformProps: string[] = [];
      let transformUnits: string[] = [];

      const result = prop.map(styles => {
        const [transformProp] = Object.keys(styles);
        transformProps.push(transformProp);

        const { unit = '', ...rest } = styles[transformProp];

        transformUnits.push(unit);

        return offset.interpolate(rest);
      });

      const transformStyle = interpolate(result, (...values) =>
        values
          .map((value, index) => {
            return `${transformProps[index]}(${value}${transformUnits[index]})`;
          })
          .join(' ')
      );

      style[key] = transformStyle;
    }
    // e.g opacity: { range, output => -1 -> 0.1}
    else if (typeof prop === 'object') {
      style[key] = offset
        .interpolate(prop)
        // @ts-ignore
        .interpolate(val => `${val}`);
    }
github elixir-europe / BioHackathon-projects-2019 / projects / 29 / src / client / src / components / QuackQuinder / QuackQuinder.js View on Github external
return props.map(({x, y, rot, scale}, i) =&gt; (
         `translate3d(${x}px,${y}px,0)`)}}&gt;
            {/* This is the card itself, we're binding our gesture to it (and inject its index so we know which is which) */}
            
                
            
        
    ))
}
github aholachek / mobile-first-animation / src / PhotoGrid / ImageGrid.js View on Github external
set
    })
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [])

  return (
    <div>
       {
            const animationInProgress = x !== 0 || y !== 0
            if (isSelected) return 5
            if (zIndexQueue.slice(-1)[0] === id &amp;&amp; animationInProgress) return 5
            if (zIndexQueue.indexOf(id) &gt; -1 &amp;&amp; animationInProgress) return 2
            return 1
          }),
          transform: interpolate(
            [x, y, scaleX, scaleY],
            (x, y, scaleX, scaleY) =&gt; {
              return `translate3d(${x}px, ${y}px, 0) scaleX(${scaleX}) scaleY(${scaleY})`
            }
          )
        }}
      &gt;
        <img draggable="{false}" alt="landscape" src="{img}">
      </div>
github pylnata / livebook / src / Book.js View on Github external
rgb(230, 230, 230) 0%,
        rgb(255,255,255) ${(x2 * 65) / pageWidth}%,
        rgb(230, 230, 230) ${(x2 * 80) / pageWidth}%,
        rgb(217, 217, 217) ${(x2 * 88) / pageWidth}%,
        rgb(255,255,255) 100%
      )`;
                    })
                  : i !== index.value + 2 || true // TODO shadow move
                  ? `linear-gradient(to right, rgba(0, 0, 0, 0.3) 0%,rgba(184, 184, 184, 0) 60px)`
                  : null,
              //                interpolate(
              //                  [bgRad, bgPos],
              //                  (bgRad, bgPos) =>
              //                    `linear-gradient(${90+bgRad}deg, rgb(0, 0, 0, 0.3) 0%,rgba(184, 184, 184, 0) ${300-bgPos}px)`
              //                )
              WebkitClipPath: interpolate(
                [x1, y1, x2, y2, x3, y3, x4, y4, x5, y5],
                (x1, y1, x2, y2, x3, y3, x4, y4, x5, y5) => {
                  if (x5 === undefined) x5 = x4;
                  if (y5 === undefined) y5 = y4;
                  return `polygon(${x1}px ${y1}px, ${x2}px ${y2}px, ${x3}px ${y3}px, ${x4}px ${y4}px, ${x5}px ${y5}px )`;
                }
              ),

              transformOrigin: i % 2 === 0 ? pageWidth + "px 0px" : "0px 0px",
              transform: interpolate(
                [x, y, r, scaleX],
                (x, y, r, scaleX) =>
                  `translateX(${x}px) translateY(${y}px) rotate(${r}rad) scaleX(${scaleX})`
              )
            }}
            className={`page page--${i} `}
github aholachek / mobile-first-animation / src / PhotoGrid / ImageGrid.js View on Github external
{
            const animationInProgress = x !== 0 || y !== 0
            if (isSelected) return 5
            if (zIndexQueue.slice(-1)[0] === id &amp;&amp; animationInProgress) return 5
            if (zIndexQueue.indexOf(id) &gt; -1 &amp;&amp; animationInProgress) return 2
            return 1
          }),
          transform: interpolate(
            [x, y, scaleX, scaleY],
            (x, y, scaleX, scaleY) =&gt; {
              return `translate3d(${x}px, ${y}px, 0) scaleX(${scaleX}) scaleY(${scaleY})`
            }
          )
        }}
      &gt;
        <img draggable="{false}" alt="landscape" src="{img}">
      
    
  )
}
github bmcmahen / sancho / src / GestureSheet.tsx View on Github external
left: 0,
            pointerEvents: isOpen ? "auto" : "none",
            right: 0,
            bottom: 0,
            background: theme.colors.background.overlay
          }}
        /&gt;
         {
            e.stopPropagation();
          }}
          style={{
            transform: interpolate([x, y], (x, y) =&gt; {
              return `
                translateX(${taper(x, position)}px) 
                translateY(${taper(y, position)}px)
              `;
            })
          }}
          css={[
            {
              outline: "none",
              zIndex: theme.zIndices.modal,
              opacity: 1,
              position: "fixed"
            },
            positionsStyle[position]
          ]}
          {...props}
github react-spring / react-spring-examples / demos / hooks / scroll-parallax / index.js View on Github external
export default function App() {
  const ref = useRef(null)
  const [{ st, xy }, set] = useSpring(() => ({ st: 0, xy: [0, 0] }))
  const interpBg = xy.interpolate(
    (x, y) =>
      `perspective(400px) rotateY(${x / 40}deg) rotateX(${-y /
        40}deg) translate3d(-50%, -50%, 0)`
  )
  const interpFace = st.interpolate(o => `translate(90,${105 + o / 4})`)
  const interpEye = interpolate(
    [st, xy],
    (o, xy) =>
      `translate(${xy[0] / 20 + 157},${xy[1] / 20 + 80 + o / 2}) scale(0.8)`
  )
  const interpIris = interpolate(
    [st, xy],
    (o, xy) => `translate(${xy[0] / 20},${xy[1] / 20 + -10 + o / 8})`
  )
  const interpPupil = interpolate(
    [st, xy],
    (o, xy) => `translate(${xy[0] / 15},${xy[1] / 15 + -10 + o / 8})`
  )
  const interpSpot = interpolate(
    [st, xy],
    (o, xy) => `translate(${8 + -xy[0] / 70},${-xy[1] / 70 + -10 + o / 8})`
  )
  const interpMouth = interpolate(
    [st, xy],
    (o, xy) =>
      `translate(${xy[0] / 15 + 208},${xy[1] / 10 + 250 + o / 1.7}) scale(0.5)`
  )
github drcmda / mauerwerk / src / index.js View on Github external
cell = ({ key, object }, i) =&gt; ({ opacity, x, y, width, height }) =&gt; {
    const { lastOpen, curOpen } = this.state
    const { open } = this.props
    return (
       `translate3d(${x}px,${y}px, 0)`
          ),
        }}
        children={this.props.children(
          object,
          curOpen === key,
          open !== undefined &amp;&amp; (() =&gt; this.toggle(key))
        )}
      /&gt;
    )
  }