我想使用淡入淡出过渡来显示带有加载动画的叠加层,但淡入淡出组件仅处理不透明度并且元素仍然存在。我想创建一个自定义动画,以确保在淡入之前不会将覆盖元素呈现在我的内容之上。
我尝试安装react-transition-group
自己来制作一个,但每次我尝试导入它都试图进入material-ui
节点模块并出于某种原因从那里加载它。
我怎样才能更新现有的过渡或能够从react-transition-group
组件创建我自己的
我想使用淡入淡出过渡来显示带有加载动画的叠加层,但淡入淡出组件仅处理不透明度并且元素仍然存在。我想创建一个自定义动画,以确保在淡入之前不会将覆盖元素呈现在我的内容之上。
我尝试安装react-transition-group
自己来制作一个,但每次我尝试导入它都试图进入material-ui
节点模块并出于某种原因从那里加载它。
我怎样才能更新现有的过渡或能够从react-transition-group
组件创建我自己的
试试这个 DialogAnimation.jsx:
import * as React from 'react';
import Transition from 'react-transition-group/Transition';
// default css props
const defaultStyle = {
transform: 'translate3d(0, -20px, 0)',
opacity: 0,
};
// custom css props in 4 state: entering, entered, exiting, exited
const styles = {
entered: {
opacity: 1,
transform: 'translate3d(0, 0, 0)',
},
};
class DialogAnimation extends React.Component {
static defaultProps = {
in: false,
duration: 300
};
render() {
const {
children,
style: styleProp,
duration,
...other
} = this.props;
const style = {
...styleProp,
...(React.isValidElement(children)
? (children.props).style
: {})
};
return (
<Transition timeout={duration} appear={true} {...other}>
{(state, childProps) => {
return React.cloneElement(children, {
style: {
...defaultStyle,
transition: 'all ' + duration + 'ms ease',
transitionProperty: 'transform, opacity',
willChange: 'transform, opacity',
...styles[state],
...style
},
...childProps
});
}}
</Transition>
);
}
}
export default DialogAnimation;
您可以在 Dialog TransitionComponent 属性中使用它:
function Transition(props) {
return <DialogAnimation {...props} />;
}
<Dialog
TransitionComponent={Transition}
>