Mon*_*ton 5 javascript events triggers dispatch react-native
借助 DOM,您可以轻松地使用 Javascript 创建触发自定义事件,如下所示:
var event = new Event('build');
// Listen for the event.
elem.addEventListener('build', function (e) { /* ... */ }, false);
// Dispatch the event.
elem.dispatchEvent(event);
Run Code Online (Sandbox Code Playgroud)
有没有办法用 React-Native 做到这一点?
Mon*_*ton -2
对于我的情况,实际上有两种解决方案:
import React, { Component } from 'react';
import { View } from 'react-native';
import { withNavigation } from 'react-navigation';
class TabScreen extends Component {
componentDidMount() {
const { navigation } = this.props;
this.focusListener = navigation.addListener('didFocus', () => {
// The screen is focused
// Call any action
});
}
componentWillUnmount() {
// Remove the event listener
this.focusListener.remove();
}
render() {
return <View />;
}
}
export default withNavigation(TabScreen);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6084 次 |
| 最近记录: |