Changeset View
Changeset View
Standalone View
Standalone View
native/media/multimedia.react.js
Show All 24 Lines | |||||
class Multimedia extends React.PureComponent<Props, State> { | class Multimedia extends React.PureComponent<Props, State> { | ||||
static defaultProps = { | static defaultProps = { | ||||
spinnerColor: 'black', | spinnerColor: 'black', | ||||
}; | }; | ||||
constructor(props: Props) { | constructor(props: Props) { | ||||
super(props); | super(props); | ||||
this.state = { | this.state = { | ||||
currentURI: props.mediaInfo.uri, | currentURI: | ||||
props.mediaInfo.type === 'video' | |||||
? props.mediaInfo.thumbnailURI | |||||
: props.mediaInfo.uri, | |||||
departingURI: null, | departingURI: null, | ||||
}; | }; | ||||
} | } | ||||
get inputState() { | get inputState() { | ||||
const { inputState } = this.props; | const { inputState } = this.props; | ||||
invariant(inputState, 'inputState should be set in Multimedia'); | invariant(inputState, 'inputState should be set in Multimedia'); | ||||
return inputState; | return inputState; | ||||
Show All 10 Lines | componentWillUnmount() { | ||||
if (departingURI) { | if (departingURI) { | ||||
inputState.reportURIDisplayed(departingURI, false); | inputState.reportURIDisplayed(departingURI, false); | ||||
} | } | ||||
} | } | ||||
componentDidUpdate(prevProps: Props, prevState: State) { | componentDidUpdate(prevProps: Props, prevState: State) { | ||||
const { inputState } = this; | const { inputState } = this; | ||||
const newURI = this.props.mediaInfo.uri; | const newURI = | ||||
this.props.mediaInfo.type === 'video' | |||||
? this.props.mediaInfo.thumbnailURI | |||||
: this.props.mediaInfo.uri; | |||||
const oldURI = this.state.currentURI; | const oldURI = this.state.currentURI; | ||||
if (newURI !== oldURI) { | if (newURI !== oldURI) { | ||||
inputState.reportURIDisplayed(newURI, true); | inputState.reportURIDisplayed(newURI, true); | ||||
const { departingURI } = this.state; | const { departingURI } = this.state; | ||||
if (departingURI && oldURI !== departingURI) { | if (departingURI && oldURI !== departingURI) { | ||||
// If there's currently an existing departingURI, that means that oldURI | // If there's currently an existing departingURI, that means that oldURI | ||||
// hasn't loaded yet. Since it's being replaced anyways we don't need to | // hasn't loaded yet. Since it's being replaced anyways we don't need to | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |