};
state = {
+ isExpanded: false,
isIntersecting: true, // assume intersecting until told otherwise
isHidden: false, // set to true in requestIdleCallback to trigger un-render
}
'muted',
]
- updateOnStates = []
+ updateOnStates = ['isExpanded']
shouldComponentUpdate (nextProps, nextState) {
if (!nextState.isIntersecting && nextState.isHidden) {
this.setState((prevState) => ({ isHidden: !prevState.isIntersecting }));
}
+ saveHeight = () => {
+ if (this.node && this.node.children.length !== 0) {
+ this.height = this.node.clientHeight;
+ }
+ }
handleRef = (node) => {
this.node = node;
- if (node && node.children.length !== 0) {
- this.height = node.clientHeight;
- }
+ this.saveHeight();
}
handleClick = () => {
}
}
+ handleExpandedToggle = () => {
+ this.setState({ isExpanded: !this.state.isExpanded });
+ };
+
render () {
let media = null;
let statusAvatar;
const { status, account, ...other } = this.props;
- const { isIntersecting, isHidden } = this.state;
+ const { isExpanded, isIntersecting, isHidden } = this.state;
if (status === null) {
return null;
</a>
</div>
- <StatusContent status={status} onClick={this.handleClick} />
+ <StatusContent status={status} onClick={this.handleClick} expanded={isExpanded} onExpandedToggle={this.handleExpandedToggle} onHeightUpdate={this.saveHeight} />
{media}
static propTypes = {
status: ImmutablePropTypes.map.isRequired,
+ expanded: PropTypes.bool,
+ onExpandedToggle: PropTypes.func,
+ onHeightUpdate: PropTypes.func,
onClick: PropTypes.func,
};
}
}
+ componentDidUpdate () {
+ if (this.props.onHeightUpdate) {
+ this.props.onHeightUpdate();
+ }
+ }
+
onMentionClick = (mention, e) => {
if (e.button === 0) {
e.preventDefault();
handleSpoilerClick = (e) => {
e.preventDefault();
- this.setState({ hidden: !this.state.hidden });
+
+ if (this.props.onExpandedToggle) {
+ // The parent manages the state
+ this.props.onExpandedToggle();
+ } else {
+ this.setState({ hidden: !this.state.hidden });
+ }
}
setRef = (c) => {
render () {
const { status } = this.props;
- const { hidden } = this.state;
+
+ const hidden = this.props.onExpandedToggle ? !this.props.expanded : this.state.hidden;
const content = { __html: emojify(status.get('content')) };
const spoilerContent = { __html: emojify(escapeTextContentForBrowser(status.get('spoiler_text', ''))) };