hardwareBackKey is not working for the connected components like using HOC connect
When we use connect react-redux component in stack navigator the back key not triggering function. import { connect } from "react-redux"; The below condition not matching event if i implement handleHardwareBackPress function in my connected component. if (this.refs.component.handleHardwareBackPress) { backAndroid.onHardwareBackPress(this.refs.component.handleHardwareBackPress) }
What is the order of connect and hardwareBackPress?
in case of hardwareBackPress at last it is not working becase the ref of component is coming as connect component so check fails.
if i do hardwareBackPress first and then return hoc pass to.connect it works.
https://github.com/reactjs/react-redux/issues/475 https://github.com/reactjs/react-redux/blob/master/docs/api.md#arguments-1
Try connect(mapStateToProps, null, null, { withRef: true })
Looks like we should add getWrappedInstance to this.refs.component
Maybe something like:
if (this.refs.component.handleHardwareBackPress) {
backAndroid.onHardwareBackPress(this.refs.component.handleHardwareBackPress)
} else if (this.refs.component.getWrappedInstance) {
backAndroid.onHardwareBackPress(this.refs.component.getWrappedInstance().refs['component'].handleHardwareBackPress)
}