Skip to content

Commit

Permalink
Merge pull request #32942 from software-mansion-labs/ts-migration/gro…
Browse files Browse the repository at this point in the history
…wl-notification

[TS migration] Migrate 'GrowlNotification' component to TypeScript
  • Loading branch information
Hayata Suenaga authored Mar 12, 2024
2 parents 46f1f1e + 1d65728 commit bca0505
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 86 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ module.exports = {
{
selector: ['parameter', 'method'],
format: ['camelCase', 'PascalCase'],
leadingUnderscore: 'allow',
},
],
'@typescript-eslint/ban-types': [
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import {Animated} from 'react-native';
import useSafeAreaInsets from '@hooks/useSafeAreaInsets';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import type GrowlNotificationContainerProps from './types';

function GrowlNotificationContainer({children, translateY}: GrowlNotificationContainerProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const insets = useSafeAreaInsets();

return <Animated.View style={[StyleUtils.getSafeAreaPadding(insets), styles.growlNotificationContainer, styles.growlNotificationTranslateY(translateY)]}>{children}</Animated.View>;
}

GrowlNotificationContainer.displayName = 'GrowlNotificationContainer';

export default GrowlNotificationContainer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import {Animated} from 'react-native';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import type GrowlNotificationContainerProps from './types';

function GrowlNotificationContainer({children, translateY}: GrowlNotificationContainerProps) {
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();

return (
<Animated.View
style={[styles.growlNotificationContainer, styles.growlNotificationDesktopContainer, styles.growlNotificationTranslateY(translateY), isSmallScreenWidth && styles.mwn]}
>
{children}
</Animated.View>
);
}

GrowlNotificationContainer.displayName = 'GrowlNotificationContainer';

export default GrowlNotificationContainer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {Animated} from 'react-native';
import type ChildrenProps from '@src/types/utils/ChildrenProps';

type GrowlNotificationContainerProps = ChildrenProps & {
translateY: Animated.Value;
};

export default GrowlNotificationContainerProps;
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type {ForwardedRef} from 'react';
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
import {Animated, View} from 'react-native';
import {Directions, Gesture, GestureDetector} from 'react-native-gesture-handler';
import type {SvgProps} from 'react-native-svg';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Pressables from '@components/Pressable';
import Text from '@components/Text';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Growl from '@libs/Growl';
import type {GrowlRef} from '@libs/Growl';
import useNativeDriver from '@libs/useNativeDriver';
import CONST from '@src/CONST';
import GrowlNotificationContainer from './GrowlNotificationContainer';
Expand All @@ -16,15 +19,29 @@ const INACTIVE_POSITION_Y = -255;

const PressableWithoutFeedback = Pressables.PressableWithoutFeedback;

function GrowlNotification(_, ref) {
function GrowlNotification(_: unknown, ref: ForwardedRef<GrowlRef>) {
const translateY = useRef(new Animated.Value(INACTIVE_POSITION_Y)).current;
const [bodyText, setBodyText] = useState('');
const [type, setType] = useState('success');
const [duration, setDuration] = useState();
const [duration, setDuration] = useState<number>();
const theme = useTheme();
const styles = useThemeStyles();

const types = {
type GrowlIconTypes = Record<
/** String representing the growl type, all type strings
* for growl notifications are stored in CONST.GROWL
*/
string,
{
/** Expensicon for the page */
icon: React.FC<SvgProps>;

/** Color for the icon (should be from theme) */
iconColor: string;
}
>;

const types: GrowlIconTypes = {
[CONST.GROWL.SUCCESS]: {
icon: Expensicons.Checkmark,
iconColor: theme.success,
Expand All @@ -46,7 +63,7 @@ function GrowlNotification(_, ref) {
* @param {String} type
* @param {Number} duration
*/
const show = useCallback((text, growlType, growlDuration) => {
const show = useCallback((text: string, growlType: string, growlDuration: number) => {
setBodyText(text);
setType(growlType);
setDuration(growlDuration);
Expand All @@ -61,7 +78,6 @@ function GrowlNotification(_, ref) {
(val = INACTIVE_POSITION_Y) => {
Animated.spring(translateY, {
toValue: val,
duration: 80,
useNativeDriver,
}).start();
},
Expand Down
1 change: 0 additions & 1 deletion src/components/MultiGestureCanvas/usePinchGesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ const usePinchGesture = ({
const pinchGesture = Gesture.Pinch()
.enabled(pinchEnabled)
// The first argument is not used, but must be defined
// eslint-disable-next-line @typescript-eslint/naming-convention
.onTouchesDown((_evt, state) => {
// We don't want to activate pinch gesture when we are swiping in the pager
if (!shouldDisableTransformationGestures.value) {
Expand Down
2 changes: 0 additions & 2 deletions src/components/MultiGestureCanvas/useTapGestures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const useTapGestures = ({

const doubleTapGesture = Gesture.Tap()
// The first argument is not used, but must be defined
// eslint-disable-next-line @typescript-eslint/naming-convention
.onTouchesDown((_evt, state) => {
if (!shouldDisableTransformationGestures.value) {
return;
Expand Down Expand Up @@ -156,7 +155,6 @@ const useTapGestures = ({
.onBegin(() => {
stopAnimation();
})
// eslint-disable-next-line @typescript-eslint/naming-convention
.onFinalize((_evt, success) => {
if (!success || onTap === undefined) {
return;
Expand Down
1 change: 0 additions & 1 deletion src/components/OptionsList/BaseOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ function BaseOptionsList(
*
* [{header}, {sectionHeader}, {item}, {item}, {sectionHeader}, {item}, {item}, {footer}]
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
const getItemLayout = (_data: OptionsListData[] | null, flatDataArrayIndex: number) => {
if (!flattenedData.current[flatDataArrayIndex]) {
flattenedData.current = buildFlatSectionArray();
Expand Down
2 changes: 0 additions & 2 deletions src/components/ScreenWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,13 @@ function ScreenWrapper(

const panResponder = useRef(
PanResponder.create({
// eslint-disable-next-line @typescript-eslint/naming-convention
onStartShouldSetPanResponderCapture: (_e, gestureState) => gestureState.numberActiveTouches === CONST.TEST_TOOL.NUMBER_OF_TAPS,
onPanResponderRelease: toggleTestToolsModal,
}),
).current;

const keyboardDissmissPanResponder = useRef(
PanResponder.create({
// eslint-disable-next-line @typescript-eslint/naming-convention
onMoveShouldSetPanResponderCapture: (_e, gestureState) => {
const isHorizontalSwipe = Math.abs(gestureState.dx) > Math.abs(gestureState.dy);
const shouldDismissKeyboard = shouldDismissKeyboardBeforeClose && isKeyboardShown && Browser.isMobile();
Expand Down
1 change: 0 additions & 1 deletion src/components/SwipeableView/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ function SwipeableView({children, onSwipeDown}: SwipeableViewProps) {
const panResponder = useRef(
PanResponder.create({
// The PanResponder gets focus only when the y-axis movement is over minimumPixelDistance & swipe direction is downwards
// eslint-disable-next-line @typescript-eslint/naming-convention
onMoveShouldSetPanResponderCapture: (_event, gestureState) => {
if (gestureState.dy - oldYRef.current > 0 && gestureState.dy > minimumPixelDistance) {
return true;
Expand Down
2 changes: 2 additions & 0 deletions src/libs/Growl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ export default {
success,
};

export type {GrowlRef};

export {growlRef, setIsReady};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ function extractPointerEvent(event: GestureResponderEvent | MouseEvent): MouseEv
return event;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function PopoverReportActionContextMenu(_props: unknown, ref: ForwardedRef<ReportActionContextMenu>) {
const {translate} = useLocalize();
const reportIDRef = useRef('0');
Expand Down
1 change: 0 additions & 1 deletion src/pages/settings/Wallet/WalletPage/WalletPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ function WalletPage({bankAccountList = {}, cardList = {}, fundList = {}, isLoadi
)}

<KYCWall
// eslint-disable-next-line @typescript-eslint/naming-convention
onSuccessfulKYC={(_iouPaymentType?: PaymentMethodType, source?: Source) => navigateToWalletOrTransferBalancePage(source)}
onSelectPaymentMethod={(selectedPaymentMethod: string) => {
if (hasActivatedWallet || selectedPaymentMethod !== CONST.PAYMENT_METHODS.PERSONAL_BANK_ACCOUNT) {
Expand Down
1 change: 0 additions & 1 deletion src/styles/utils/addOutlineWidth/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
import type AddOutlineWidth from './types';

// eslint-disable-next-line @typescript-eslint/naming-convention
const addOutlineWidth: AddOutlineWidth = (_theme, obj) => obj;

export default addOutlineWidth;
1 change: 0 additions & 1 deletion src/utils/times.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function times<TReturnType>(n: number, func: (index: number) => TReturnType = (i) => i as TReturnType): TReturnType[] {
// eslint-disable-next-line @typescript-eslint/naming-convention
return Array.from({length: n}).map((_, i) => func(i));
}

Expand Down

0 comments on commit bca0505

Please sign in to comment.