size: PropTypes.object,
onOpenMedia: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
+ defaultWidth: PropTypes.number,
+ cacheWidth: PropTypes.func,
};
static defaultProps = {
state = {
visible: this.props.revealed === undefined ? (displayMedia !== 'hide_all' && !this.props.sensitive || displayMedia === 'show_all') : this.props.revealed,
+ width: this.props.defaultWidth,
};
componentWillReceiveProps (nextProps) {
handleRef = (node) => {
this.node = node;
if (node && node.offsetWidth && node.offsetWidth != this.state.width) {
+ if (this.props.cacheWidth) this.props.cacheWidth(node.offsetWidth);
this.setState({
width: node.offsetWidth,
});
}
render () {
- const { media, intl, sensitive, letterbox, fullwidth } = this.props;
- const { width, visible } = this.state;
+ const { media, intl, sensitive, letterbox, fullwidth, defaultWidth } = this.props;
+ const { visible } = this.state;
const size = media.take(4).size;
+ const width = this.state.width || defaultWidth;
+
let children;
const style = {};
state = {
fullscreen: null,
+ cachedMediaWidth: 300,
};
intersectionObserverWrapper = new IntersectionObserverWrapper();
this.setScrollTop(newScrollTop);
}
+ cacheMediaWidth = (width) => {
+ if (width && this.state.cachedMediaWidth != width) this.setState({ cachedMediaWidth: width });
+ }
+
getSnapshotBeforeUpdate (prevProps, prevState) {
const someItemInserted = React.Children.count(prevProps.children) > 0 &&
React.Children.count(prevProps.children) < React.Children.count(this.props.children) &&
intersectionObserverWrapper={this.intersectionObserverWrapper}
saveHeightKey={trackScroll ? `${this.context.router.route.location.key}:${scrollKey}` : null}
>
- {React.cloneElement(child, {getScrollPosition: this.getScrollPosition, updateScrollBottom: this.updateScrollBottom})}
+ {React.cloneElement(child, {
+ getScrollPosition: this.getScrollPosition,
+ updateScrollBottom: this.updateScrollBottom,
+ cachedMediaWidth: this.state.cachedMediaWidth,
+ cacheMediaWidth: this.cacheMediaWidth,
+ })}
</IntersectionObserverArticleContainer>
))}
updateScrollBottom: PropTypes.func,
expanded: PropTypes.bool,
intl: PropTypes.object.isRequired,
+ cacheMediaWidth: PropTypes.func,
+ cachedMediaWidth: PropTypes.number,
};
state = {
fullwidth={settings.getIn(['media', 'fullwidth'])}
preventPlayback={isCollapsed || !isExpanded}
onOpenVideo={this.handleOpenVideo}
+ width={this.props.cachedMediaWidth}
+ cacheWidth={this.props.cacheMediaWidth}
/>)}
</Bundle>
);
fullwidth={settings.getIn(['media', 'fullwidth'])}
hidden={isCollapsed || !isExpanded}
onOpenMedia={this.props.onOpenMedia}
+ cacheWidth={this.props.cacheMediaWidth}
+ defaultWidth={this.props.cachedMediaWidth}
/>
)}
</Bundle>
onOpenMedia={this.props.onOpenMedia}
card={status.get('card')}
compact
+ cacheWidth={this.props.cacheMediaWidth}
+ defaultWidth={this.props.cachedMediaWidth}
/>
);
mediaIcon = 'link';
onMention: PropTypes.func.isRequired,
getScrollPosition: PropTypes.func,
updateScrollBottom: PropTypes.func,
+ cacheMediaWidth: PropTypes.func,
+ cachedMediaWidth: PropTypes.number,
+ onUnmount: PropTypes.func,
};
render () {
contextType='notifications'
getScrollPosition={getScrollPosition}
updateScrollBottom={updateScrollBottom}
+ cachedMediaWidth={this.props.cachedMediaWidth}
+ cacheMediaWidth={this.props.cacheMediaWidth}
+ onUnmount={this.props.onUnmount}
withDismiss
/>
);
onMention={onMention}
getScrollPosition={getScrollPosition}
updateScrollBottom={updateScrollBottom}
+ cachedMediaWidth={this.props.cachedMediaWidth}
+ cacheMediaWidth={this.props.cacheMediaWidth}
+ onUnmount={this.props.onUnmount}
withDismiss
/>
);
onMention={onMention}
getScrollPosition={getScrollPosition}
updateScrollBottom={updateScrollBottom}
+ cachedMediaWidth={this.props.cachedMediaWidth}
+ cacheMediaWidth={this.props.cacheMediaWidth}
+ onUnmount={this.props.onUnmount}
withDismiss
/>
);
maxDescription: PropTypes.number,
onOpenMedia: PropTypes.func.isRequired,
compact: PropTypes.bool,
+ defaultWidth: PropTypes.number,
+ cacheWidth: PropTypes.func,
};
static defaultProps = {
};
state = {
- width: 280,
+ width: this.props.defaultWidth || 280,
embedded: false,
};
setRef = c => {
if (c) {
+ if (this.props.cacheWidth) this.props.cacheWidth(c.offsetWidth);
this.setState({ width: c.offsetWidth });
}
}
}
render () {
- const { card, maxDescription, compact } = this.props;
+ const { card, maxDescription, compact, defaultWidth } = this.props;
const { width, embedded } = this.state;
if (card === null) {
inline: PropTypes.bool,
preventPlayback: PropTypes.bool,
intl: PropTypes.object.isRequired,
+ cacheWidth: PropTypes.func,
};
state = {
volume: 0.5,
paused: true,
dragging: false,
- containerWidth: false,
+ containerWidth: this.props.width,
fullscreen: false,
hovered: false,
muted: false,
this.player = c;
if (c && c.offsetWidth && c.offsetWidth != this.state.containerWidth) {
+ if (this.props.cacheWidth) this.props.cacheWidth(this.player.offsetWidth);
this.setState({
containerWidth: c.offsetWidth,
});
componentDidUpdate (prevProps) {
if (this.player && this.player.offsetWidth && this.player.offsetWidth != this.state.containerWidth && !this.state.fullscreen) {
+ if (this.props.cacheWidth) this.props.cacheWidth(this.player.offsetWidth);
this.setState({
containerWidth: this.player.offsetWidth,
});