Skip to content

Commit

Permalink
feat: ✨ Limit with the number of notification shown (#8)
Browse files Browse the repository at this point in the history
* feat: ✨ Limit with the number of notification shown

* fix: 🐛 initial value of the limit changed to null

* docs: 📝 The type value of the limit has been changed
  • Loading branch information
Skipperlla authored Dec 4, 2022
1 parent ab277f7 commit f185e57
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export type NotifyOptions = {
* Show the timeout bar
*/
noTimeoutBar?: boolean;
/**
* Limit the number of notification displayed at the same time.
*/
limit?: number | null;
/**
* the function to call when the notification is clicked
* @param remove - the function to remove the notification that was clicked
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 520bd180df6b59d9e514e0a1f7b7818051cbf850

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
32 changes: 20 additions & 12 deletions src/NotifyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,27 @@ export const NotifyProviderBase = ({ children }: PropsWithChildren<{}>) => {
options,
onPress,
noTimeoutBar = false,
limit = null,
}: NotifyOptions) => {
setItems((prev) => [
...prev,
{
id: generateUUID(10),
level,
message,
duration,
options,
onPress,
noTimeoutBar,
},
]);
setItems((prev) => {
if (limit) {
const count = prev.filter((i) => i.level === level).length;
if (count >= limit) return prev;
}
return [
...prev,
{
id: generateUUID(10),
message,
duration,
level,
options,
onPress,
noTimeoutBar,
limit,
},
];
});
},
[]
);
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export type NotifyOptions = {
* Show the timeout bar
*/
noTimeoutBar?: boolean;
/**
* Limit the number of notification displayed at the same time.
*/
limit?: number | null;
/**
* the function to call when the notification is clicked
* @param remove - the function to remove the notification that was clicked
Expand Down

0 comments on commit f185e57

Please sign in to comment.