Skip to content

the addListener not working #2

@jsina

Description

@jsina

I've follow the react-navigation redux integration and also check your sample code but still the listener not working. here is my code ...

App.js
const App = () => (
  <Provider store={store}>
    <AppWithNavigationState />
  </Provider>
);
...
AppWithNavigationState.js

const mapStateToProps = state => ({
  nav: state.nav,
});

@connect(mapStateToProps)
export default class AppWithNavigationState extends Component {

  onBackPress = () => {
    const { dispatch, nav } = this.props;
    if (nav.index == 0) {
      return false;
    }
    dispatch(NavigationActions.back());
    return true;
  };

  render() {
    const { dispatch, nav } = this.props;
    return (
      <SafeAreaView style={{ flex: 1 }}>
        <AppNavigator
          navigation={addNavigationHelpers({
            dispatch,
            state: nav,
            addListener,
          })}
        />
      </SafeAreaView>
    );
  }
}
SearchScreen.js

const mapStateToProps = store => ({
  list: store.getList,
});
@connect(mapStateToProps)
export default class SearchScreen extends Component {
  static navigationOptions = ({ navigation }) =>
    // const { params = {} } = navigation.state;
    ({
      // header: (
      //   <FilterCalendar
      //     timeText={params.timeText}
      //     previousDateOnPress={params.previousDateOnPress}
      //     nextDateOnPress={params.nextDateOnPress}
      //   />
      // ),
      tabBarLabel: constants.SEARCH_TAB_TITLE,
    });

  state = {
    currentDate: new Date(),
    timeText: gregorianToJalai(new Date()),
    skip: this.props.list.skip,
  };

  componentDidMount() {
    this.makeRemoteRequest(false, true);
    this.updateNavigationParams();
    this.subs = [
      this.props.navigation.addListener('willFocus', () => console.log('will focus')),
      this.props.navigation.addListener('willBlur', () => console.log('will blur')),
      this.props.navigation.addListener('didFocus', () => console.log('did focus')),
      this.props.navigation.addListener('didBlur', () => console.log('did blur')),
    ];
  }

  componentWillUnmount() {
    this.subs.forEach(s => s.remove());
  }
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions