ref(video): remove deprecated lifecycle methods from gesture handler

This commit is contained in:
Leonard Kim 2018-11-29 19:11:34 -08:00 committed by Zoltan Bettenbuk
parent 10163274d3
commit 7614ceda68
1 changed files with 33 additions and 31 deletions

View File

@ -152,7 +152,8 @@ class VideoTransform extends Component<Props, State> {
this.state = { this.state = {
layout: null, layout: null,
transform: DEFAULT_TRANSFORM transform:
this._getSavedTransform(props.streamId) || DEFAULT_TRANSFORM
}; };
this._didMove = this._didMove.bind(this); this._didMove = this._didMove.bind(this);
@ -166,14 +167,7 @@ class VideoTransform extends Component<Props, State> {
this._onPanResponderRelease = this._onPanResponderRelease.bind(this); this._onPanResponderRelease = this._onPanResponderRelease.bind(this);
this._onStartShouldSetPanResponder this._onStartShouldSetPanResponder
= this._onStartShouldSetPanResponder.bind(this); = this._onStartShouldSetPanResponder.bind(this);
}
/**
* Implements React Component's componentWillMount.
*
* @inheritdoc
*/
componentWillMount() {
// The move threshold should be adaptive to the pixel ratio of the // The move threshold should be adaptive to the pixel ratio of the
// screen to avoid making it too sensitive or difficult to handle on // screen to avoid making it too sensitive or difficult to handle on
// different pixel ratio screens. // different pixel ratio screens.
@ -189,21 +183,17 @@ class VideoTransform extends Component<Props, State> {
onShouldBlockNativeResponder: () => false, onShouldBlockNativeResponder: () => false,
onStartShouldSetPanResponder: this._onStartShouldSetPanResponder onStartShouldSetPanResponder: this._onStartShouldSetPanResponder
}); });
const { streamId } = this.props;
this._restoreTransform(streamId);
} }
/** /**
* Implements React Component's componentWillReceiveProps. * Implements React Component's componentDidUpdate.
* *
* @inheritdoc * @inheritdoc
*/ */
componentWillReceiveProps({ streamId: newStreamId }) { componentDidUpdate(prevProps, prevState) {
if (this.props.streamId !== newStreamId) { if (prevProps.streamId !== this.props.streamId) {
this._storeTransform(); this._storeTransform(prevProps.streamId, prevState.transform);
this._restoreTransform(newStreamId); this._restoreTransform(this.props.streamId);
} }
} }
@ -213,7 +203,7 @@ class VideoTransform extends Component<Props, State> {
* @inheritdoc * @inheritdoc
*/ */
componentWillUnmount() { componentWillUnmount() {
this._storeTransform(); this._storeTransform(this.props.streamId, this.state.transform);
} }
/** /**
@ -293,6 +283,20 @@ class VideoTransform extends Component<Props, State> {
|| Math.abs(dy) > this.moveThreshold; || Math.abs(dy) > this.moveThreshold;
} }
/**
* Returns the stored transform a stream should display with initially.
*
* @param {string} streamId - The id of the stream to match with a stored
* transform.
* @private
* @returns {Object | null}
*/
_getSavedTransform(streamId) {
const { enabled, _transforms } = this.props;
return (enabled && _transforms[streamId]) || null;
}
_getTouchDistance: Object => number; _getTouchDistance: Object => number;
/** /**
@ -647,31 +651,29 @@ class VideoTransform extends Component<Props, State> {
* @returns {void} * @returns {void}
*/ */
_restoreTransform(streamId) { _restoreTransform(streamId) {
const { enabled, _transforms } = this.props; const savedTransform = this._getSavedTransform(streamId);
if (enabled) { if (savedTransform) {
const initialTransform = _transforms[streamId]; this.setState({
transform: savedTransform
if (initialTransform) { });
this.setState({
transform: initialTransform
});
}
} }
} }
/** /**
* Stores/saves the current transform when the component is destroyed, or a * Stores/saves the a transform when the component is destroyed, or a
* new stream is about to be rendered. * new stream is about to be rendered.
* *
* @param {string} streamId - The stream id associated with the transform.
* @param {Object} transform - The {@Transform} to save.
* @private * @private
* @returns {void} * @returns {void}
*/ */
_storeTransform() { _storeTransform(streamId, transform) {
const { _onUnmount, enabled, streamId } = this.props; const { _onUnmount, enabled } = this.props;
if (enabled) { if (enabled) {
_onUnmount(streamId, this.state.transform); _onUnmount(streamId, transform);
} }
} }
} }