RN-261 Fix app crashing when badge is unmounted before it displays (#743)
This commit is contained in:
parent
d98eb99f82
commit
93d7697dcc
1 changed files with 17 additions and 2 deletions
|
|
@ -33,6 +33,7 @@ export default class Badge extends PureComponent {
|
|||
super(props);
|
||||
|
||||
this.width = 0;
|
||||
this.mounted = false;
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
|
|
@ -45,12 +46,26 @@ export default class Badge extends PureComponent {
|
|||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.mounted = true;
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.mounted = false;
|
||||
}
|
||||
|
||||
handlePress = () => {
|
||||
if (this.props.onPress) {
|
||||
this.props.onPress();
|
||||
}
|
||||
};
|
||||
|
||||
setNativeProps = (props) => {
|
||||
if (this.mounted && this.refs.badgeContainer) {
|
||||
this.refs.badgeContainer.setNativeProps(props);
|
||||
}
|
||||
};
|
||||
|
||||
onLayout = (e) => {
|
||||
let width;
|
||||
|
||||
|
|
@ -66,7 +81,7 @@ export default class Badge extends PureComponent {
|
|||
this.width = width;
|
||||
const height = Math.max(e.nativeEvent.layout.height, this.props.minHeight);
|
||||
const borderRadius = height / 2;
|
||||
this.refs.badgeContainer.setNativeProps({
|
||||
this.setNativeProps({
|
||||
style: {
|
||||
width,
|
||||
height,
|
||||
|
|
@ -74,7 +89,7 @@ export default class Badge extends PureComponent {
|
|||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.refs.badgeContainer.setNativeProps({
|
||||
this.setNativeProps({
|
||||
style: {
|
||||
display: 'flex'
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue