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 5 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.

30 changes: 30 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,30 @@
import React, {ComponentType, ForwardedRef, ReactElement, RefAttributes} from 'react';
import {SetOptional} from 'type-fest';
import {View} from 'react-native';
import styles from '../styles/styles';
import getComponentDisplayName from '../libs/getComponentDisplayName';

type ToggleVisibilityViewProp = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type ToggleVisibilityViewProp = {
type ToggleVisibilityViewProps = {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjusted 👍

/** Whether the content is visible. */
isVisible: boolean;
};

export default function withToggleVisibilityView<TProps extends ToggleVisibilityViewProp, TRef>(
WrappedComponent: ComponentType<TProps & RefAttributes<TRef>>,
): (props: TProps & RefAttributes<TRef>) => ReactElement | null {
function WithToggleVisibilityView({isVisible = false, ...rest}: SetOptional<TProps, 'isVisible'>, ref: ForwardedRef<TRef>) {
return (
<View style={!isVisible && styles.visuallyHidden}>
<WrappedComponent
// eslint-disable-next-line react/jsx-props-no-spreading
{...(rest as TProps)}
ref={ref}
isVisible={isVisible}
/>
</View>
);
}

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