From 15177207d55e818621e0b918b5c9f2ab6a4100a4 Mon Sep 17 00:00:00 2001 From: plouc Date: Sun, 21 Jun 2020 09:18:47 +0900 Subject: [PATCH] feat(core): remove SmartMotion component in favor of react-spring built-in support for various interpolators --- packages/core/package.json | 2 - packages/core/src/hocs/withMotion.js | 14 +--- packages/core/src/motion/SmartMotion.js | 102 ------------------------ packages/core/src/motion/index.js | 1 - website/src/pages/sankey/index.js | 2 +- 5 files changed, 2 insertions(+), 119 deletions(-) delete mode 100644 packages/core/src/motion/SmartMotion.js diff --git a/packages/core/package.json b/packages/core/package.json index 097a576ee..18b21aa23 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -18,14 +18,12 @@ "d3-color": "^1.2.3", "d3-format": "^1.4.4", "d3-hierarchy": "^1.1.8", - "d3-interpolate": "^1.3.2", "d3-scale": "^3.0.0", "d3-scale-chromatic": "^1.3.3", "d3-shape": "^1.3.5", "d3-time-format": "^2.1.3", "lodash": "^4.17.11", "react-measure": "^2.2.4", - "react-motion": "^0.5.2", "react-spring": "^8.0.27", "recompose": "^0.30.0" }, diff --git a/packages/core/src/hocs/withMotion.js b/packages/core/src/hocs/withMotion.js index 5f1e7789f..12b0871c6 100644 --- a/packages/core/src/hocs/withMotion.js +++ b/packages/core/src/hocs/withMotion.js @@ -6,12 +6,9 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -import partialRight from 'lodash/partialRight' import compose from 'recompose/compose' import defaultProps from 'recompose/defaultProps' -import withPropsOnChange from 'recompose/withPropsOnChange' import setPropTypes from 'recompose/setPropTypes' -import { spring } from 'react-motion' import { motionPropTypes } from '../motion' import { defaultAnimate, defaultMotionDamping, defaultMotionStiffness } from '../defaults' @@ -22,14 +19,5 @@ export default () => animate: defaultAnimate, motionDamping: defaultMotionDamping, motionStiffness: defaultMotionStiffness, - }), - withPropsOnChange( - ['motionDamping', 'motionStiffness'], - ({ motionDamping, motionStiffness }) => ({ - boundSpring: partialRight(spring, { - damping: motionDamping, - stiffness: motionStiffness, - }), - }) - ) + }) ) diff --git a/packages/core/src/motion/SmartMotion.js b/packages/core/src/motion/SmartMotion.js deleted file mode 100644 index 3ed398997..000000000 --- a/packages/core/src/motion/SmartMotion.js +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is part of the nivo project. - * - * Copyright 2016-present, Raphaƫl Benitte. - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -// credit to Tanner Linsey from this issue on react motion repository: -// https://github.com/chenglou/react-motion/issues/153 - -import React, { PureComponent } from 'react' -import { Motion, spring } from 'react-motion' -import { interpolate } from 'd3-interpolate' -import PropTypes from 'prop-types' - -const enhancedSpring = (value, config) => { - if (typeof value !== 'number') { - return { - value, - config, - interpolator: config && config.interpolator ? config.interpolator : interpolate, - } - } - return spring(value, config) -} - -export default class SmartMotion extends PureComponent { - oldValues = {} - newInters = {} - currentStepValues = {} - stepValues = {} - stepInterpolators = {} - - static propTypes = { - children: PropTypes.func.isRequired, - style: PropTypes.func.isRequired, - } - - render() { - const { style, children, ...rest } = this.props - - const resolvedStyle = style(enhancedSpring) - - for (let key in resolvedStyle) { - if ( - // If key is a non-numeric interpolation - resolvedStyle[key] && - resolvedStyle[key].interpolator - ) { - // Make sure the steps start at 0 - this.currentStepValues[key] = this.currentStepValues[key] || 0 - if ( - // And the value has changed - typeof this.newInters[key] === 'undefined' || - resolvedStyle[key].value !== this.newInters[key].value - ) { - // Save the new value - this.newInters[key] = resolvedStyle[key] - - // Increment the stepInterValue for this key by 1 - this.stepValues[key] = this.currentStepValues[key] + 1 - - // Set up the new interpolator - this.stepInterpolators[key] = this.newInters[key].interpolator( - this.oldValues[key], - this.newInters[key].value - ) - } - // Return the spring with the destination stepValue and spring config - resolvedStyle[key] = spring(this.stepValues[key], this.newInters[key].config) - // console.log(resolvedStyle[key]) - } - } - - return ( - - {values => { - const newValues = {} - for (let key in values) { - if (this.stepValues[key]) { - // Save the currentStepValue - this.currentStepValues[key] = values[key] - // Figure the percentage - const percentage = - this.currentStepValues[key] - this.stepValues[key] + 1 - // Save the current value and replace the value in the interpolated object - this.oldValues[key] = newValues[key] = this.stepInterpolators[key]( - percentage - ) - } - } - return children({ - ...values, - ...newValues, - }) - }} - - ) - } -} diff --git a/packages/core/src/motion/index.js b/packages/core/src/motion/index.js index eb4d2da13..230fc18ef 100644 --- a/packages/core/src/motion/index.js +++ b/packages/core/src/motion/index.js @@ -6,6 +6,5 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -export { default as SmartMotion } from './SmartMotion' export * from './context' export * from './hooks' diff --git a/website/src/pages/sankey/index.js b/website/src/pages/sankey/index.js index 93c324930..31394ab25 100644 --- a/website/src/pages/sankey/index.js +++ b/website/src/pages/sankey/index.js @@ -56,7 +56,7 @@ const initialProperties = { }, animate: SankeyDefaultProps.animate, - motionConfig: 'wobbly', // SankeyDefaultProps.motionConfig, + motionConfig: SankeyDefaultProps.motionConfig, isInteractive: SankeyDefaultProps.isInteractive,