Skip to content

Commit

Permalink
refactor: functions
Browse files Browse the repository at this point in the history
  • Loading branch information
avrcoelho committed Jun 16, 2022
1 parent 12ebf2c commit 2661dd2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 80 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-hook-notification",
"version": "2.2.2",
"version": "2.2.3",
"license": "MIT",
"main": "dist/main/index.js",
"typings": "dist/main/index.d.ts",
Expand Down
120 changes: 52 additions & 68 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useRef } from 'react';
import { useRef } from 'react';
import { NotificationStore } from '../presentation/store/NotificationStore';
import {
CustomNotificationParams,
Expand All @@ -22,78 +22,62 @@ export {
const notificationStore = NotificationStore.getInstance();

export const useNotification: UseNotificationHook = (hookParams = {}) => {
const info = useCallback(
(notificationParams: NotificationParams) => {
const notification = {
...hookParams,
...notificationParams,
type: 'info' as NotificationType,
};
notificationStore.add(notification);
},
[hookParams],
);
const info = (notificationParams: NotificationParams): void => {
const notification = {
...hookParams,
...notificationParams,
type: 'info' as NotificationType,
};
notificationStore.add(notification);
};

const success = useCallback(
(notificationParams: NotificationParams) => {
const notification = {
...hookParams,
...notificationParams,
type: 'success' as NotificationType,
};
notificationStore.add(notification);
},
[hookParams],
);
const success = (notificationParams: NotificationParams): void => {
const notification = {
...hookParams,
...notificationParams,
type: 'success' as NotificationType,
};
notificationStore.add(notification);
};

const error = useCallback(
(notificationParams: NotificationParams) => {
const notification = {
...hookParams,
...notificationParams,
type: 'error' as NotificationType,
};
notificationStore.add(notification);
},
[hookParams],
);
const error = (notificationParams: NotificationParams): void => {
const notification = {
...hookParams,
...notificationParams,
type: 'error' as NotificationType,
};
notificationStore.add(notification);
};

const warning = useCallback(
(notificationParams: NotificationParams) => {
const notification = {
...hookParams,
...notificationParams,
type: 'warning' as NotificationType,
};
notificationStore.add(notification);
},
[hookParams],
);
const warning = (notificationParams: NotificationParams): void => {
const notification = {
...hookParams,
...notificationParams,
type: 'warning' as NotificationType,
};
notificationStore.add(notification);
};

const defaultNotification = useCallback(
(notificationParams: NotificationParams) => {
const notification = {
...hookParams,
...notificationParams,
type: 'default' as NotificationType,
};
notificationStore.add(notification);
},
[hookParams],
);
const defaultNotification = (
notificationParams: NotificationParams,
): void => {
const notification = {
...hookParams,
...notificationParams,
type: 'default' as NotificationType,
};
notificationStore.add(notification);
};

const custom = useCallback(
(notificationParams: CustomNotificationParams) => {
const notification = {
...hookParams,
...notificationParams,
theme: 'custom' as NotificationTheme,
type: 'custom' as NotificationType,
};
notificationStore.add(notification);
},
[hookParams],
);
const custom = (notificationParams: CustomNotificationParams): void => {
const notification = {
...hookParams,
...notificationParams,
theme: 'custom' as NotificationTheme,
type: 'custom' as NotificationType,
};
notificationStore.add(notification);
};

return useRef({
info,
Expand Down
19 changes: 8 additions & 11 deletions src/presentation/components/Notification/useController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,13 @@ export const useController: UseControllerHook = ({
: {};
}, [animationEnteringFinish, transitionDirection, limitToRemove]);

const onFinishAnimation = useCallback(
(isFinished: boolean): void => {
'worklet';
const onFinishAnimation = (isFinished: boolean): void => {
'worklet';

if (isFinished) {
runOnJS(toggleAnimationEnteringFinish)();
}
},
[toggleAnimationEnteringFinish],
);
if (isFinished) {
runOnJS(toggleAnimationEnteringFinish)();
}
};

const delayDecrement = useRef(delay / DELAY);
const timerRef = useRef<NodeJS.Timeout>();
Expand All @@ -244,12 +241,12 @@ export const useController: UseControllerHook = ({
return () => clearInterval(timerRef.current as NodeJS.Timeout);
}, [autoClose, isPaused, onExecuteTimer]);

const onPressNotification = useCallback((): void => {
const onPressNotification = (): void => {
onPress?.();
if (closeOnPress) {
onRemove();
}
}, [closeOnPress, onPress, onRemove]);
};

const animation = getAnimation({ position, transition });

Expand Down

0 comments on commit 2661dd2

Please sign in to comment.