react-native (componentWillUpdate, componentWillReceiveProps)
刷卡功能应用程序。
警告:componentWillReceiveProps 已弃用,将在下一个主要版本中删除。请改用静态 getDerivedStateFromProps。
警告:componentWillUpdate 已弃用,将在下一个主要版本中删除。请改用 componentDidUpdate。作为临时解决方法,您可以重命名为 UNSAFE_componentWillUpdate。
YellowBox.ignoreWarnings 方法不是必需的。
我会要求你更新代码。
我该如何解决?
//git component
const renderPagination = (index, total, context) => {
return (
<View style={styles.paginationStyle}>
<Text style={{ color: 'grey' }}>
<Text style={styles.paginationText}>{index + 1}</Text>/{total}
</Text>
</View>
)
}
export default class App extends Component {
constructor(props) {
super(props);
this.onPressNext = this.onPressNext.bind(this);
this.onPressPrev = this.onPressPrev.bind(this);
this.state = {
indexPage: 0
}
}
onPressPrev = () => {
const { indexPage } = this.state;
if (indexPage > 0) {
this.refs.swiper.scrollBy(-1);
}
}
onPressNext = () => {
const { indexPage } = this.state;
if (indexPage < 4) {
this.refs.swiper.scrollBy(1);
}
}
render() {
return (
<View style={styles.container}>
<View style={{flex:0.1, backgroundColor: 'green'}}>
<Text>NAVTEX</Text>
</View>
{/* {git component} */}
<Swiper
style={styles.wrapper}
onIndexChanged={indexPage => this.setState({ indexPage })}
renderPagination={renderPagination}
showsButtons={false}
loop={false}
ref={'swiper'}
>
<View style={styles.slide}>
<Text style={styles.text}>2</Text>
</View>
<View style={styles.slide}>
<Text style={styles.text}>2</Text>
</View>
<View style={styles.slide}>
<Text style={styles.text}>3</Text>
</View>
<View style={styles.slide}>
<Text style={styles.text}>4</Text>
</View>
<View style={styles.slide}>
<Text style={styles.text}>5</Text>
</View>
</Swiper>
<View style={styles.buttoncontainer}>
<Button
style={{with:75}}
onPress={this.onPressPrev}
title="Previous">
</Button>
<Button
onPress={this.onPressNext}
title="Next">
</Button>
</View>
</View>
);
}
}