Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpolate: Extrapolate left/right #1255

Closed
mrousavy opened this issue Sep 20, 2020 · 0 comments · Fixed by #1549
Closed

interpolate: Extrapolate left/right #1255

mrousavy opened this issue Sep 20, 2020 · 0 comments · Fixed by #1549

Comments

@mrousavy
Copy link
Contributor

Description

I'd like to see extrapolating for both sides, just like in v1.

Motivation

Currently we can only extrapolate left and right at the same time, but if I wanted to clamp left and extend identity for the right value, that wouldn't be possible. I'd have to use a workaround: Use no extrapolation and then use Math.min or Math.max for "clamping".

Code example

A solution for this would be:

const x = interpolate(scrollX, [0, HEADER_HEIGHT, contentSize.x], [0, 0, contentSize.x + HEADER_HEIGHT], { extrapolateLeft: 'clamp', extrapolateRight: 'identity' })

To make it backwards compatible (and also cleaner if you don't need different extrapolations) the interpolate function could take both types:

type ExtrapolateParameter = Extrapolate | { extrapolateLeft?: Extrapolate, extrapolateRight?: Extrapolate } | undefined 
karol-bisztyga pushed a commit that referenced this issue Jan 13, 2021
Co-authored-by: Jakub <jakub.gonet@swmansion.com>
Co-authored-by: Rostyslav Broslavskyi <r.broslavskyi@omo.systems>
Co-authored-by: karol-bisztyga <59833830+karol-bisztyga@users.noreply.github.com>

## Wix Goodness Squad Event

Motivation: to see extrapolating for both sides, just like in v1.

Fixes #1255

## Changes

- Added ts types for extrapolation
- Added ExtrapolationExample
- Added Error handling for invalid config or invalid interpolation value 


## Live example

IDK which example is better currently 2 in this PR

https://user-images.githubusercontent.com/32239452/102691648-a03d0780-4216-11eb-90e7-7ef8a5f1590a.mov

---
https://user-images.githubusercontent.com/32239452/102694608-df755380-422a-11eb-839c-8872d1427807.mov


## Checklist

- [x] Included code example that can be used to test this change
- [x] Updated TS types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant