-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor: Remove Avatar platform specific code #15663
Changes from all commits
1519e28
4c53413
9bb4ac7
c4abb46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,36 +8,23 @@ import {defaultProps, imagePropTypes} from './imagePropTypes'; | |
import RESIZE_MODES from './resizeModes'; | ||
|
||
class Image extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.debouncedConfigureImageSource = _.debounce(this.configureImageSource, 220); | ||
|
||
this.state = { | ||
imageSource: undefined, | ||
}; | ||
Comment on lines
-16
to
-18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having We don't have to use state for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The (Also it's inconsistent with the There are further changes that we can add to the Image component and I can open a follow up PR:
I do both of this changes here: but the PR is on hold |
||
} | ||
|
||
componentDidMount() { | ||
this.debouncedConfigureImageSource(); | ||
this.configureOnLoad(); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (prevProps.source.uri === this.props.source.uri) { | ||
if (prevProps.source === this.props.source) { | ||
return; | ||
} | ||
|
||
this.debouncedConfigureImageSource.cancel(); | ||
this.debouncedConfigureImageSource(); | ||
this.configureOnLoad(); | ||
} | ||
|
||
/** | ||
* Check if the image source is a URL - if so the `encryptedAuthToken` is appended | ||
* to the source. The natural image dimensions can then be retrieved using this source | ||
* and as a result the `onLoad` event needs to be maunually invoked to return these dimensions | ||
* to the source. | ||
* @returns {Object} - the configured image source | ||
*/ | ||
configureImageSource() { | ||
this.props.onLoadStart(); | ||
getImageSource() { | ||
const source = this.props.source; | ||
let imageSource = source; | ||
if (this.props.isAuthTokenRequired) { | ||
|
@@ -47,25 +34,34 @@ class Image extends React.Component { | |
const authToken = lodashGet(this.props, 'session.encryptedAuthToken', null); | ||
imageSource = {uri: `${source.uri}?encryptedAuthToken=${encodeURIComponent(authToken)}`}; | ||
} | ||
this.setState({imageSource}); | ||
|
||
return imageSource; | ||
} | ||
|
||
/** | ||
* The natural image dimensions are retrieved using the updated source | ||
* and as a result the `onLoad` event needs to be manually invoked to return these dimensions | ||
*/ | ||
configureOnLoad() { | ||
// If an onLoad callback was specified then manually call it and pass | ||
// the natural image dimensions to match the native API | ||
if (this.props.onLoad == null) { | ||
return; | ||
} | ||
|
||
const imageSource = this.getImageSource(); | ||
RNImage.getSize(imageSource.uri, (width, height) => { | ||
this.props.onLoad({nativeEvent: {width, height}}); | ||
}); | ||
} | ||
|
||
render() { | ||
// eslint-disable-next-line | ||
const { source, onLoad, ...rest } = this.props; | ||
// Omit the props which the underlying RNImage won't use | ||
const forwardedProps = _.omit(this.props, ['source', 'onLoad', 'session', 'isAuthTokenRequired']); | ||
const source = this.getImageSource(); | ||
|
||
// eslint-disable-next-line | ||
return <RNImage {...rest} source={this.state.imageSource} />; | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
return <RNImage {...forwardedProps} source={source} />; | ||
} | ||
} | ||
|
||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
defaultSource
workaround is no longer needed.We just pass
source