Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA][TS migration] Migrate 'withToggleVisibilityView.js' HOC to TypeScript #29559

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module.exports = {
},
{
selector: ['parameter', 'method'],
format: ['camelCase'],
format: ['camelCase', 'PascalCase'],
},
],
'@typescript-eslint/ban-types': [
Expand Down
47 changes: 0 additions & 47 deletions src/components/withToggleVisibilityView.js

This file was deleted.

27 changes: 27 additions & 0 deletions src/components/withToggleVisibilityView.tsx
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, {ComponentType, ForwardedRef, RefAttributes} from 'react';
import {View} from 'react-native';
import styles from '../styles/styles';
import getComponentDisplayName from '../libs/getComponentDisplayName';

type ToggleVisibilityViewPropTypes = {
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
/** Whether the content is visible. */
isVisible: boolean;
};

export default function withToggleVisibilityView<TProps extends ToggleVisibilityViewPropTypes, TRef>(WrappedComponent: ComponentType<TProps & RefAttributes<TRef>>): ComponentType<TProps> {
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
function WithToggleVisibilityView(props: Omit<TProps, keyof ToggleVisibilityViewPropTypes>, ref: ForwardedRef<TRef>) {
return (
<View style={!((props as TProps)?.isVisible ?? false) && styles.visuallyHidden}>
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...(props as TProps)}
ref={ref}
isVisible={(props as TProps).isVisible ?? false}
/>
</View>
);
}
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved

WithToggleVisibilityView.displayName = `WithToggleVisibilityView(${getComponentDisplayName(WrappedComponent)})`;
return React.forwardRef(WithToggleVisibilityView);
}
2 changes: 1 addition & 1 deletion src/libs/getComponentDisplayName.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ComponentType} from 'react';

/** Returns the display name of a component */
export default function getComponentDisplayName(component: ComponentType): string {
export default function getComponentDisplayName<TProps>(component: ComponentType<TProps>): string {
return component.displayName ?? component.name ?? 'Component';
}
6 changes: 3 additions & 3 deletions src/pages/signin/LoginForm/BaseLoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import withLocalize, {withLocalizePropTypes} from '../../../components/withLocal
import TextInput from '../../../components/TextInput';
import * as ValidationUtils from '../../../libs/ValidationUtils';
import * as LoginUtils from '../../../libs/LoginUtils';
import withToggleVisibilityView, {toggleVisibilityViewPropTypes} from '../../../components/withToggleVisibilityView';
import withToggleVisibilityView from '../../../components/withToggleVisibilityView';
import FormAlertWithSubmitButton from '../../../components/FormAlertWithSubmitButton';
import {withNetwork} from '../../../components/OnyxProvider';
import networkPropTypes from '../../../components/networkPropTypes';
Expand Down Expand Up @@ -66,12 +66,12 @@ const propTypes = {
/** Whether or not the sign in page is being rendered in the RHP modal */
isInModal: PropTypes.bool,

isVisible: PropTypes.bool.isRequired,

...windowDimensionsPropTypes,

...withLocalizePropTypes,

...toggleVisibilityViewPropTypes,

...withNavigationFocusPropTypes,
};

Expand Down
Loading