Skip to content

Commit 58fd8c9

Browse files
committed
update docs and usage example
1 parent fe61834 commit 58fd8c9

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

Diff for: README.md

+14-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## react-native-dropdownalert
1+
# react-native-dropdownalert
22

33
[![Platform](https://img.shields.io/badge/platform-react--native-lightgrey.svg)](http://facebook.github.io/react-native/)
44
[![npm version](http://img.shields.io/npm/v/react-native-dropdownalert.svg)](https://www.npmjs.com/package/react-native-dropdownalert)
@@ -18,7 +18,7 @@
1818
5. [Props](docs/PROPS.md)
1919
6. [Caveats](#caveats)
2020

21-
A simple alert to notify users about new chat messages, something went wrong or everything is ok. It can be closed by tap, cancel button, automatically with `closeInterval`, pan responder up gesture or programmatically.
21+
A simple alert to notify users about new chat messages, something went wrong or everything is ok. It can be closed by tap, cancel button, automatically with `closeInterval`, pan responder up gesture or programmatically (```this.dropDownAlertRef.closeAction()```).
2222

2323
### Support
2424

@@ -29,9 +29,7 @@ A simple alert to notify users about new chat messages, something went wrong or
2929

3030
### Installation
3131

32-
```
33-
npm i react-native-dropdownalert --save
34-
```
32+
```npm i react-native-dropdownalert --save```
3533

3634
### Demo
3735

@@ -40,27 +38,28 @@ npm i react-native-dropdownalert --save
4038
### Usage
4139

4240
```javascript
43-
// ...
4441
import DropdownAlert from 'react-native-dropdownalert';
4542
export default class App extends Component {
4643
componentDidMount() {
47-
this.fetchData();
44+
this._fetchData();
4845
}
49-
fetchData = async () => {
46+
_fetchData = async () => {
5047
try {
51-
const data = await fetch('https://mywebsite.com/endpoint/');
52-
if (data) {
53-
this.dropdown.alertWithType('success', 'Success', 'Received data.');
54-
}
48+
await fetch('https://mywebsite.com/endpoint/');
49+
// alertWithType parameters: type, title, message, payload, interval.
50+
// There are 4 pre-defined types: info, warn, success, error.
51+
// payload object with source property overrides image source prop. (optional)
52+
// interval overrides closeInterval prop. (optional)
53+
this.dropDownAlertRef.alertWithType('success', 'Success', 'Fetch data is complete.');
5554
} catch (error) {
56-
this.dropdown.alertWithType('error', 'Error', error.message);
55+
this.dropDownAlertRef.alertWithType('error', 'Error', error.message);
5756
}
5857
};
5958
render() {
59+
// Make sure DropdownAlert is the last component in the document tree.
6060
return (
6161
<View>
62-
// !!! Make sure it is the last component in your document tree.
63-
<DropdownAlert ref={ref => this.dropdown = ref} />
62+
<DropdownAlert ref={ref => this.dropDownAlertRef = ref} />
6463
</View>
6564
);
6665
}

Diff for: docs/PROPS.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
| Name | Type | Description | Default |
6464
| ---- | :---: | --- | --- |
65-
| ```defaultContainer``` | Object | Style for inner view container (**override paddingTop with this**) | ```{ padding: 8, paddingTop: IS_ANDROID ? 0 : 20, flexDirection: 'row' } ```
65+
| ```defaultContainer``` | Object | Style for inner view container (**override paddingTop with this**) | ```{ padding: 8, paddingTop: IS_ANDROID ? 0 : 20, flexDirection: 'row' }```
6666
| ```defaultTextContainer``` | Object | Style for inner text container (holds title and message) | ```{ flex: 1, padding: 8 }```
6767
| ```wrapperStyle``` | Object | styles for the view that wraps the container. For [React Native Web](https://github.com/necolas/react-native-web) support you might want to set this to `{ position: 'fixed' }` | ```null```
6868
| ```containerStyle``` | Object | styles for container for custom type only | ```{ padding: 16, flexDirection: 'row', backgroundColor: '#202020' }```
@@ -72,6 +72,8 @@
7272

7373
### Image
7474

75+
image sources are overridden if payload parameter has source property. For example,```{ source: 'https://facebook.github.io/react-native/docs/assets/favicon.png' }```
76+
7577
| Name | Type | Description | Default |
7678
| ---- | :---: | --- | --- |
7779
| ```imageStyle``` | Object | styles for image for all types | ```{ padding: 8, width: 36, height: 36, alignSelf: 'center' }```

0 commit comments

Comments
 (0)