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

[TS migration] Migrate 'GrowlNotification' component to TypeScript #32942

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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

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 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 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 {Animated} from 'react-native';
import 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,15 @@
import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
import React, {ForwardedRef, forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
import {Animated, View} from 'react-native';
import {Directions, FlingGestureHandler, State} from 'react-native-gesture-handler';
import {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 +18,16 @@ const INACTIVE_POSITION_Y = -255;

const PressableWithoutFeedback = Pressables.PressableWithoutFeedback;

function GrowlNotification(_, ref) {
// eslint-disable-next-line @typescript-eslint/naming-convention
function GrowlNotification(_: unknown, ref: ForwardedRef<GrowlRef>) {
cdOut marked this conversation as resolved.
Show resolved Hide resolved
const translateY = useRef(new Animated.Value(INACTIVE_POSITION_Y)).current;
hayata-suenaga marked this conversation as resolved.
Show resolved Hide resolved
const [bodyText, setBodyText] = useState('');
const [type, setType] = useState('success');
const [duration, setDuration] = useState();
const [duration, setDuration] = useState<number | undefined>();
const theme = useTheme();
cdOut marked this conversation as resolved.
Show resolved Hide resolved
const styles = useThemeStyles();

const types = {
const types: Record<string, {icon: React.FC<SvgProps>; iconColor: string}> = {
[CONST.GROWL.SUCCESS]: {
cdOut marked this conversation as resolved.
Show resolved Hide resolved
icon: Expensicons.Checkmark,
iconColor: theme.success,
Expand All @@ -46,7 +49,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 @@ -58,13 +61,11 @@ function GrowlNotification(_, ref) {
* @param {Number} val
*/
const fling = useCallback(
(val = INACTIVE_POSITION_Y) => {
(val = INACTIVE_POSITION_Y) =>
Animated.spring(translateY, {
cdOut marked this conversation as resolved.
Show resolved Hide resolved
toValue: val,
duration: 80,
useNativeDriver,
cdOut marked this conversation as resolved.
Show resolved Hide resolved
}).start();
},
}).start(),
[translateY],
);

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};
Loading