-1
我想創建一個主頁,它從哪裏開始,它在標題欄中顯示徽標,向下滾動時顯示徽標,因此我希望獲得該事件可以在標題欄中隱藏標誌,然後顯示一個用於搜索的TextInput。我如何才能在React Native中獲得主頁滾動事件
我想創建一個主頁,它從哪裏開始,它在標題欄中顯示徽標,向下滾動時顯示徽標,因此我希望獲得該事件可以在標題欄中隱藏標誌,然後顯示一個用於搜索的TextInput。我如何才能在React Native中獲得主頁滾動事件
基本上,你必須使用反應生命週期方法在組件...
var Box = React.createClass({
getInitialState: function() {
return {windowWidth: window.innerWidth};
},
handleResize: function(e) {
this.setState({windowWidth: window.innerWidth});
},
componentDidMount: function() {
window.addEventListener('resize', this.handleResize);
},
componentWillUnmount: function() {
window.removeEventListener('resize', this.handleResize);
},
render: function() {
return <div>Current window width: {this.state.windowWidth}</div>;
}
});
ReactDOM.render(<Box />, mountNode);
我覺得這個鏈接應該幫助:)
https://facebook.github.io/react/tips/dom-event-listeners.html