-
Notifications
You must be signed in to change notification settings - Fork 97
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
Create the property holdPlaceholder to keep the placeholder for some … #55
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,22 +19,25 @@ export default class ReactPlaceholder extends React.Component { | |
customPlaceholder: PropTypes.oneOfType([ | ||
PropTypes.node, | ||
PropTypes.element | ||
]) | ||
]), | ||
holdPlaceholder: PropTypes.number | ||
} | ||
|
||
static defaultProps = { | ||
delay: 0, | ||
type: 'text', | ||
color: '#CDCDCD' | ||
color: '#CDCDCD', | ||
holdPlaceholder: 0 | ||
} | ||
|
||
state = { | ||
ready: this.props.ready | ||
ready: this.props.ready, | ||
holdPlaceholder: this.props.holdPlaceholder > 0 | ||
} | ||
|
||
getFiller = () => { | ||
const { | ||
firstLaunchOnly, children, ready, className, // eslint-disable-line no-unused-vars | ||
firstLaunchOnly, children, ready, className, holdPlaceholder, // eslint-disable-line no-unused-vars | ||
type, customPlaceholder, showLoadingAnimation, ...rest | ||
} = this.props; | ||
|
||
|
@@ -80,14 +83,28 @@ export default class ReactPlaceholder extends React.Component { | |
} | ||
|
||
render() { | ||
return this.state.ready ? this.props.children : this.getFiller(); | ||
const { ready, holdPlaceholder } = this.state; | ||
return ready && !holdPlaceholder ? this.props.children : this.getFiller(); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (!this.props.firstLaunchOnly && this.state.ready && !nextProps.ready) { | ||
this.setNotReady(); | ||
if (!this.props.firstLaunchOnly && !nextProps.ready) { | ||
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. I find this new code over complicated and difficult to read... |
||
if (this.state.ready) { | ||
this.setNotReady(); | ||
} | ||
if (this.props.holdPlaceholder) { | ||
clearTimeout(this.holdPlaceholderTimeout); | ||
this.setState({ holdPlaceholder: true }); | ||
this.holdPlaceholderTimeout = setTimeout(() => this.setState({ holdPlaceholder: false }), nextProps.holdPlaceholder); | ||
} | ||
} else if (nextProps.ready) { | ||
this.setReady(); | ||
} | ||
} | ||
|
||
componentWillMount() { | ||
if (this.props.holdPlaceholder > 0) { | ||
this.holdPlaceholderTimeout = setTimeout(() => this.setState({ holdPlaceholder: false }), this.props.holdPlaceholder); | ||
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. why are you always setting a timeout? shouldn't it be added only if |
||
} | ||
} | ||
} |
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.
we already have
ready
, can't see the need for another variable that does the same thing