Merge pull request #171 from catchonme/master

修复Carousel没有更新数据的问题
This commit is contained in:
liaoxuezhi 2019-08-16 17:38:15 +08:00 committed by GitHub
commit 390653b3e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,7 @@ import React from 'react';
import Transition, {ENTERED, ENTERING, EXITING} from 'react-transition-group/Transition';
import {Renderer, RendererProps} from '../factory';
import {resolveVariable} from '../utils/tpl-builtin';
import {autobind, createObject, isObject} from '../utils/helper';
import {autobind, createObject, isObject, isArrayChilrenModified} from '../utils/helper';
import {leftArrowIcon, rightArrowIcon} from '../components/icons';
const animationStyles: {
@ -88,6 +88,16 @@ export class Carousel extends React.Component<CarouselProps, CarouselState> {
nextAnimation: ''
};
componentWillReceiveProps(nextProps:CarouselProps) {
const currentOptions = this.state.options;
const nextOptions = nextProps.value || nextProps.options || resolveVariable(nextProps.name, nextProps.data) || [];
if (isArrayChilrenModified(currentOptions, nextOptions)) {
this.setState({
options: nextOptions
});
}
}
componentDidMount() {
this.prepareAutoSlide();
}