Skip to content

Commit

Permalink
chore(export): showSuccess, showWarning, showError and showCustom
Browse files Browse the repository at this point in the history
  • Loading branch information
luancurti committed Jun 7, 2023
1 parent 4227dfd commit ac3f4e8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@platformbuilders/react-native-toast",
"version": "1.1.4",
"version": "1.1.5",
"description": "",
"author": "Platform Builders <[email protected]>",
"repository": {
Expand Down
24 changes: 4 additions & 20 deletions react-native-toast.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ declare module "@platformbuilders/react-native-toast" {
showToast: (options: ToastProps) => void;
};

export class ToastManager {
showError(message: string, title?: string, duration?: number): void;
showSuccess(message: string, title?: string, duration?: number): void;
showWarning(message: string, title?: string, duration?: number): void;
showCustom(message: string, title?: string, duration?: number): void;
register(showToast: (options: ToastProps) => void): void;
}

export type PanGestureContextType = {
translateY: number;
};
Expand Down Expand Up @@ -83,16 +75,8 @@ declare module "@platformbuilders/react-native-toast" {

export function ToastProvider({ children, config }: ToastProviderProps): React.JSX.Element

interface IToastManager {
instance: ToastInstance;
register(showToast: (options: ToastProps) => void): void;
showError(message: string, title?: string, duration?: number): void;
showSuccess(message: string, title?: string, duration?: number): void;
showWarning(message: string, title?: string, duration?: number): void;
showCustom(message: string, title?: string, duration?: number): void;
}

class ToastManager implements IToastManager {}

export const ToastManagerInstance: IToastManager = new ToastManager();
export function showError(message: string, title?: string, duration?: number): void;
export function showSuccess(message: string, title?: string, duration?: number): void;
export function showWarning(message: string, title?: string, duration?: number): void;
export function showCustom(message: string, title?: string, duration?: number): void;
}
5 changes: 3 additions & 2 deletions src/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable sonarjs/cognitive-complexity */
import React, { FC, useEffect, useState } from 'react';
import { ImageSourcePropType, LayoutChangeEvent } from 'react-native';
import {
Expand Down Expand Up @@ -297,7 +298,7 @@ export const Toast: FC<Props> = ({ data, config }) => {
},
});

return (
return toast?.message?.length > 0 ? (
<PanGestureHandler onGestureEvent={panGestureEvent}>
<Container
onLayout={handleViewLayout}
Expand Down Expand Up @@ -341,5 +342,5 @@ export const Toast: FC<Props> = ({ data, config }) => {
)}
</Container>
</PanGestureHandler>
);
) : null;
};
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import ToastManagerInstance from './ToastManager';

const showSuccess = ToastManagerInstance.showSuccess;
const showError = ToastManagerInstance.showError;
const showCustom = ToastManagerInstance.showError;
const showWarning = ToastManagerInstance.showWarning;

export * from './Toast';
export * from './ToastProvider';
export { default as ToastManagerInstance } from './ToastManager';

export { showSuccess, showError, showCustom, showWarning };

0 comments on commit ac3f4e8

Please sign in to comment.