View / apply constraints automatically based on hints

All constraints can now function differently if they are applied during
interaction or animation.
This commit is contained in:
jahow
2019-01-12 23:47:02 +01:00
committed by Olivier Guyot
parent d991dfa54a
commit e52fab636c
5 changed files with 55 additions and 27 deletions

View File

@@ -22,8 +22,14 @@ export function createSnapToResolutions(resolutions) {
* @param {number} direction Direction.
* @return {number|undefined} Resolution.
*/
function(resolution, delta, direction) {
function(resolution, delta, direction, opt_isMoving) {
if (resolution !== undefined) {
// during interacting or animating, allow intermediary values
if (opt_isMoving) {
// TODO: actually take delta and direction into account
return resolution;
}
let z = linearFindNearest(resolutions, resolution, direction);
z = clamp(z + delta, 0, resolutions.length - 1);
const index = Math.floor(z);
@@ -55,8 +61,14 @@ export function createSnapToPower(power, maxResolution, opt_maxLevel) {
* @param {number} direction Direction.
* @return {number|undefined} Resolution.
*/
function(resolution, delta, direction) {
function(resolution, delta, direction, opt_isMoving) {
if (resolution !== undefined) {
// during interacting or animating, allow intermediary values
if (opt_isMoving) {
// TODO: actually take delta and direction into account
return resolution;
}
const offset = -direction / 2 + 0.5;
const oldLevel = Math.floor(
Math.log(maxResolution / resolution) / Math.log(power) + offset);