-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
95 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,112 @@ | ||
# rn-notify | ||
|
||
A notify utility that show notification in app UI | ||
https://user-images.githubusercontent.com/22038798/164993645-bd2b6942-92c2-45c6-b8f1-4286b66bdcd8.mov | ||
|
||
## Installation | ||
A utility that displays notifications to user ✏️ | ||
|
||
## Installation ⚙️ | ||
|
||
```sh | ||
yarn add rn-notify | ||
``` | ||
|
||
`rn-notify` needs `react-native-reanimated` package 💎 | ||
|
||
```sh | ||
npm install rn-notify | ||
yarn add react-native-reanimated | ||
``` | ||
|
||
## Usage | ||
👇 You also need to complete installations of these packages for more information use the links below 👇 | ||
|
||
- [react-native-reanimated](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation) | ||
|
||
## Usage 🧑💻 | ||
|
||
```tsx | ||
import * as React from 'react'; | ||
import { View, Text, TouchableOpacity } from 'react-native'; | ||
|
||
```js | ||
import { multiply } from 'rn-notify'; | ||
import { NotifyProvider, useNotify } from 'rn-notify'; | ||
|
||
// ... | ||
function Page() { | ||
const notify = useNotify(); | ||
return ( | ||
<View style={styles.container}> | ||
<TouchableOpacity | ||
onPress={() => | ||
notify.success({ | ||
message: 'Good Job 👍', | ||
duration: 1000, | ||
}) | ||
} | ||
> | ||
<Text>Show alert</Text> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
} | ||
|
||
const result = await multiply(3, 7); | ||
export default function App() { | ||
return ( | ||
<NotifyProvider> | ||
<Page /> | ||
</NotifyProvider> | ||
); | ||
} | ||
``` | ||
|
||
## Contributing | ||
For more examples check out the [example](https://github.com/Papyon-Apps/rn-notify/blob/feat/reanimated/example/src/App.tsx) folder 📂 | ||
|
||
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. | ||
## Usage 🎚️ | ||
|
||
#### `notify.<type>(options: NotifyOptions)` | ||
|
||
Used to show a message. can take 3 types: | ||
|
||
- `notify.success` - Shows the message in a green box | ||
- `notify.info` - Shows the message in a yellow box | ||
- `notify.error` - Shows the message in a red box | ||
|
||
## License | ||
`NotifyOptions` is an object with the following properties: | ||
|
||
MIT | ||
```ts | ||
export type NotifyOptions = { | ||
/** | ||
* The text of the notification. | ||
*/ | ||
message: string; | ||
/** | ||
* The level of the notification. Can be 'info', 'success' or 'error'. | ||
*/ | ||
level: NotifyLevel; | ||
/** | ||
* The duration of the notification. Defaults to `3000`. | ||
*/ | ||
duration?: number; | ||
/** | ||
* Show the timeout bar | ||
*/ | ||
noTimeoutBar?: boolean; | ||
/** | ||
* the function to call when the notification is clicked | ||
* @param remove - the function to remove the notification that was clicked | ||
*/ | ||
onPress?: (remove: () => void) => void; | ||
/** | ||
* The style of the notification. | ||
*/ | ||
options?: { | ||
containerStyle?: ViewStyle; | ||
textStyle?: TextStyle; | ||
timeoutBarStyle?: ViewStyle; | ||
}; | ||
}; | ||
``` | ||
|
||
## Contributing 🔖 | ||
|
||
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. | ||
|
||
--- | ||
## License 📰 | ||
|
||
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) | ||
[MIT](https://github.com/Papyon-Apps/rn-notify/blob/master/LICENSE) |