diff --git a/native/navigation/orientation-handler.react.js b/native/navigation/orientation-handler.react.js index 5ac6a38c1..56bdea8b9 100644 --- a/native/navigation/orientation-handler.react.js +++ b/native/navigation/orientation-handler.react.js @@ -1,64 +1,60 @@ // @flow -import PropTypes from 'prop-types'; import * as React from 'react'; import type { Orientations } from 'react-native-orientation-locker'; import Orientation from 'react-native-orientation-locker'; +import { useDispatch } from 'react-redux'; -import type { DispatchActionPayload } from 'lib/utils/action-utils'; -import { connect } from 'lib/utils/redux-utils'; +import type { Dispatch } from 'lib/types/redux-types'; import { updateDeviceOrientationActionType } from '../redux/action-types'; -import type { AppState } from '../redux/redux-setup'; +import { useSelector } from '../redux/redux-utils'; -type Props = { - // Redux state - deviceOrientation: Orientations, - // Redux dispatch functions - dispatchActionPayload: DispatchActionPayload, -}; +type Props = {| + +deviceOrientation: Orientations, + +dispatch: Dispatch, +|}; class OrientationHandler extends React.PureComponent { - static propTypes = { - deviceOrientation: PropTypes.string.isRequired, - dispatchActionPayload: PropTypes.func.isRequired, - }; - componentDidMount() { Orientation.addOrientationListener(this.updateOrientation); } componentWillUnmount() { Orientation.removeOrientationListener(this.updateOrientation); } componentDidUpdate(prevProps: Props) { if (this.props.deviceOrientation !== prevProps.deviceOrientation) { // Most of the time, this is triggered as a result of an action dispatched // by the handler attached above, so the updateOrientation call should be // a no-op. This conditional is here to correct Redux state when it is // imported from another device context. Orientation.getOrientation(this.updateOrientation); } } updateOrientation = (orientation) => { if (orientation !== this.props.deviceOrientation) { - this.props.dispatchActionPayload( - updateDeviceOrientationActionType, - orientation, - ); + this.props.dispatch({ + type: updateDeviceOrientationActionType, + payload: orientation, + }); } }; render() { return null; } } -export default connect( - (state: AppState) => ({ - deviceOrientation: state.deviceOrientation, - }), - null, - true, -)(OrientationHandler); +export default React.memo<{||}>(function ConnectedOrientationHandler() { + const deviceOrientation = useSelector((state) => state.deviceOrientation); + const dispatch = useDispatch(); + + return ( + + ); +});