Files
mobile/src/screens/SideMenu/AbstractSideMenu.tsx
Radek Czemerys 6149f150df TS types (#253)
* Add TS to lib/components/styles/authentication

* Rollback prettier changes to declutter diff

* Authentication migration

526 errors

* Notes

328 errors

* Settings

172 errors

* refactor: last screens

* fix: revert setting wrong sideMenuHandler

* feature: upgrade type deps
2020-05-07 10:57:52 +02:00

39 lines
1.5 KiB
TypeScript

import { Keyboard } from 'react-native';
import Abstract, { AbstractProps, AbstractState } from '@Screens/Abstract';
export default class AbstractSideMenu<
AdditionalProps extends AbstractProps,
AdditionalState extends AbstractState
> extends Abstract<AdditionalProps, AdditionalState> {
handler: any;
shouldComponentUpdate(nextProps: Readonly<AbstractProps & AdditionalProps>) {
/*
We had some performance issues with this component rendering too many times when
navigating to unrelated routes, like pushing Compose. It would render 6 times or so,
causing slowdown. We only want to render if there's a difference in drawer related properties.
*/
const isDrawerOpen = this.props.navigation.state.isDrawerOpen;
const isDrawerGoingToBeOpen = nextProps.navigation.state.isDrawerOpen;
// When the drawer is opening, we want to be sure to dismiss the keyboard if it's up
if (!isDrawerOpen && isDrawerGoingToBeOpen) {
this.psuedo_willFocus();
}
// We only need this to render when the drawer is opening, not when closing.
return !isDrawerOpen && isDrawerGoingToBeOpen;
}
psuedo_willFocus() {
// componentWillFocus is not called for drawer components when they are about to appear
// instead, we piggyback on the logic in shouldComponentUpdate above to determine
// if navigation state is about to change, and if so, we call this.
Keyboard.dismiss();
this.handler &&
this.handler.onKeyboardDismiss &&
this.handler.onKeyboardDismiss();
}
}