Skip to content

Commit 2f8595d

Browse files
committed
Rename to SpineTo
1 parent f87115b commit 2f8595d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

packages/component/src/ScrollToBottom/Composer.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33

44
import Context from './Context';
55
import EventSpy from '../EventSpy';
6-
import ScrollTo from '../ScrollTo';
6+
import SpineTo from '../SpineTo';
77

88
function isBottom(current, threshold) {
99
const { offsetHeight, scrollHeight, scrollTop } = current;
@@ -25,6 +25,7 @@ export default class ScrollToBottomComposer extends React.Component {
2525
bottom: true,
2626
scrollTop: this.state.target && this.state.target.current && (this.state.target.current.scrollHeight - this.state.target.current.offsetHeight)
2727
})),
28+
scrollTop: null,
2829
setTarget: target => this.setState(() => ({ target })),
2930
target: null
3031
};
@@ -52,10 +53,11 @@ export default class ScrollToBottomComposer extends React.Component {
5253
target={ this.state.target }
5354
/>
5455
{ typeof this.state.scrollTop === 'number' &&
55-
<ScrollTo
56+
<SpineTo
57+
name="scrollTop"
5658
onEnd={ this.handleScrollEnd }
57-
scrollTop={ this.state.scrollTop }
5859
target={ this.state.target }
60+
value={ this.state.scrollTop }
5961
/>
6062
}
6163
</Context.Provider>

packages/component/src/ScrollTo.js renamed to packages/component/src/SpineTo.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ export default class ScrollTo extends React.Component {
3131
}
3232

3333
componentDidMount() {
34-
const { current } = this.props.target;
34+
const { name, target } = this.props;
35+
const { current } = target || {};
3536

3637
if (current) {
3738
this.addEventListeners(current);
38-
this.animate('scrollTop', current.scrollTop, this.props.scrollTop, 1);
39+
this.animate(name, current[name], this.props.value, 1);
3940
}
4041
}
4142

@@ -44,7 +45,7 @@ export default class ScrollTo extends React.Component {
4445
const { target } = this.props;
4546
const { current: prevCurrent } = prevTarget || {};
4647
const { current } = target || {};
47-
const scrollChanged = prevProps.scrollTop !== this.props.scrollTop;
48+
const scrollChanged = prevProps.value !== this.props.value;
4849
const targetChanged = prevCurrent !== current;
4950

5051
if (targetChanged) {
@@ -53,7 +54,9 @@ export default class ScrollTo extends React.Component {
5354
}
5455

5556
if ((scrollChanged || targetChanged) && current) {
56-
this.animate('scrollTop', current.scrollTop, this.props.scrollTop, 1);
57+
const { name } = this.props;
58+
59+
this.animate(name, current[name], this.props.value, 1);
5760
}
5861
}
5962

@@ -107,7 +110,8 @@ export default class ScrollTo extends React.Component {
107110
}
108111

109112
ScrollTo.propTypes = {
113+
name: PropTypes.string.isRequired,
110114
onEnd: PropTypes.func,
111-
scrollTop: PropTypes.number,
112-
target: PropTypes.any
115+
target: PropTypes.any.isRequired,
116+
value: PropTypes.number.isRequired
113117
};

0 commit comments

Comments
 (0)