Skip to content

Commit 971afec

Browse files
committed
2 parents f58bf15 + fc0ec06 commit 971afec

File tree

2 files changed

+52
-49
lines changed

2 files changed

+52
-49
lines changed

DropdownAlert.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export default class DropdownAlert extends Component {
5050
updateStatusBar: PropTypes.bool,
5151
elevation: PropTypes.number,
5252
sensitivity: PropTypes.number,
53+
defaultContainer: ViewPropTypes.style,
54+
defaultTextContainer: ViewPropTypes.style,
5355
};
5456
static defaultProps = {
5557
onClose: null,
@@ -99,6 +101,15 @@ export default class DropdownAlert extends Component {
99101
height: DEFAULT_IMAGE_DIMENSIONS,
100102
alignSelf: 'center',
101103
},
104+
defaultContainer: {
105+
padding: 8,
106+
paddingTop: IS_ANDROID ? 0 : 20,
107+
flexDirection: 'row',
108+
},
109+
defaultTextContainer: {
110+
flex: 1,
111+
padding: 8,
112+
},
102113
translucent: false,
103114
activeStatusBarStyle: 'light-content',
104115
activeStatusBarBackgroundColor: StatusBarDefaultBackgroundColor,
@@ -321,17 +332,18 @@ export default class DropdownAlert extends Component {
321332
}
322333
}
323334
getStyleForType(type) {
335+
const { defaultContainer } = this.props;
324336
switch (type) {
325337
case 'info':
326-
return [styles.defaultContainer, { backgroundColor: this.props.infoColor }];
338+
return [StyleSheet.flatten(defaultContainer), { backgroundColor: this.props.infoColor }];
327339
case 'warn':
328-
return [styles.defaultContainer, { backgroundColor: this.props.warnColor }];
340+
return [StyleSheet.flatten(defaultContainer), { backgroundColor: this.props.warnColor }];
329341
case 'error':
330-
return [styles.defaultContainer, { backgroundColor: this.props.errorColor }];
342+
return [StyleSheet.flatten(defaultContainer), { backgroundColor: this.props.errorColor }];
331343
case 'success':
332-
return [styles.defaultContainer, { backgroundColor: this.props.successColor }];
344+
return [StyleSheet.flatten(defaultContainer), { backgroundColor: this.props.successColor }];
333345
default:
334-
return [styles.defaultContainer, StyleSheet.flatten(this.props.containerStyle)];
346+
return [StyleSheet.flatten(defaultContainer), StyleSheet.flatten(this.props.containerStyle)];
335347
}
336348
}
337349
getSourceForType(type) {
@@ -413,7 +425,7 @@ export default class DropdownAlert extends Component {
413425
>
414426
<View style={style}>
415427
<ImageView style={StyleSheet.flatten(this.props.imageStyle)} source={source} />
416-
<View style={styles.textContainer}>
428+
<View style={StyleSheet.flatten(this.props.defaultTextContainer)}>
417429
<Label style={StyleSheet.flatten(this.props.titleStyle)} numberOfLines={this.props.titleNumOfLines} text={this.state.title} />
418430
<Label style={StyleSheet.flatten(this.props.messageStyle)} numberOfLines={this.props.messageNumOfLines} text={this.state.message} />
419431
</View>
@@ -436,15 +448,3 @@ export default class DropdownAlert extends Component {
436448
return null;
437449
}
438450
}
439-
440-
var styles = StyleSheet.create({
441-
defaultContainer: {
442-
padding: 8,
443-
paddingTop: IS_ANDROID ? 0 : 20,
444-
flexDirection: 'row',
445-
},
446-
textContainer: {
447-
flex: 1,
448-
padding: 8,
449-
},
450-
});

README.md

+34-31
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@
66
[![Build Status](https://travis-ci.org/testshallpass/react-native-dropdownalert.svg?branch=master)](https://travis-ci.org/testshallpass/react-native-dropdownalert)
77
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.github.com/testshallpass/react-native-dropdownalert/master/LICENSE)
88

9-
A simple alert to notify users about new chat messages, something went wrong or everything is ok. It can be dismissed by onPress, cancel onPress, automatically with `closeInterval` prop, pan responder up gesture or programmatically.
9+
![screenshot](https://raw.github.com/testshallpass/react-native-dropdownalert/master/screenshots/info.png) ![screenshot](https://raw.github.com/testshallpass/react-native-dropdownalert/master/screenshots/warning.png) ![screenshot](https://raw.github.com/testshallpass/react-native-dropdownalert/master/screenshots/error.png) ![screenshot](https://raw.github.com/testshallpass/react-native-dropdownalert/master/screenshots/success.png)
10+
11+
### Table of contents
12+
1. [News](#news)
13+
2. [Installation](#installation)
14+
3. [Demo](#demo)
15+
4. [Usage](#usage)
16+
5. [Props](#props)
17+
18+
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.
1019

1120
### News
1221
> v2.13.0 supports ViewPropTypes introduced in react-native **0.44.0**. If you support an earlier react-native version, please use v2.12.0 or earlier.
@@ -21,39 +30,31 @@ npm i react-native-dropdownalert --save
2130

2231
### Usage
2332
```javascript
24-
25-
import DropdownAlert from 'react-native-dropdownalert'
26-
// ...
27-
render() {
28-
return (
29-
<View>
30-
// !!! Make sure it's the last component in your document tree.
31-
<DropdownAlert
32-
ref={(ref) => this.dropdown = ref}
33-
onClose={(data) => this.onClose(data)} />
34-
</View>
35-
)
36-
}
37-
// ...
38-
handleRequestCallback(err, response) {
39-
if (err != null) {
40-
this.dropdown.alertWithType('error', 'Error', err)
33+
import DropdownAlert from 'react-native-dropdownalert';
34+
export default class Example extends Component {
35+
// ...
36+
onError = error => {
37+
if (error) {
38+
this.dropdown.alertWithType('error', 'Error', error);
39+
}
40+
};
41+
// ...
42+
onClose(data) {
43+
// data = {type, title, message, action}
44+
// action means how the alert was closed.
45+
// returns: automatic, programmatic, tap, pan or cancel
46+
}
47+
render() {
48+
return (
49+
<View>
50+
// !!! Make sure it's the last component in your document tree.
51+
<DropdownAlert ref={ref => this.dropdown = ref} onClose={data => this.onClose(data)} />
52+
</View>
53+
);
4154
}
4255
}
43-
// ...
44-
onClose(data) {
45-
// data = {type, title, message, action}
46-
// action means how the alert was dismissed. returns: automatic, programmatic, tap, pan or cancel
47-
}
48-
// ...
4956
```
5057

51-
### Predefined Types
52-
53-
| info | warn | error | success |
54-
| :---: | :---: | :---: | :---: |
55-
|![screenshot](https://raw.github.com/testshallpass/react-native-dropdownalert/master/screenshots/info.png) |![screenshot](https://raw.github.com/testshallpass/react-native-dropdownalert/master/screenshots/warning.png) |![screenshot](https://raw.github.com/testshallpass/react-native-dropdownalert/master/screenshots/error.png)|![screenshot](https://raw.github.com/testshallpass/react-native-dropdownalert/master/screenshots/success.png)
56-
5758
### Props
5859
| Name | Type | Description | Default |
5960
| ---- | :---: | --- | --- |
@@ -76,7 +77,7 @@ onClose(data) {
7677
| ```activeStatusBarBackgroundColor``` | String | StatusBar backgroundColor when alert is open | It takes on the backgroundColor of alert if predefined else default or provided prop
7778
| ```inactiveStatusBarStyle``` | String | StatusBar barStyle when alert dismisses | `StatusBar._defaultProps.barStyle.value`
7879
| ```inactiveStatusBarBackgroundColor``` | String | StatusBar backgroundColor when alert dismisses | `StatusBar._defaultProps.backgroundColor.value`
79-
| ```containerStyle``` | View.propTypes.style | styles for container for custom type only | ```{ padding: 16, flexDirection: 'row' }```
80+
| ```containerStyle``` | ViewPropTypes.style | styles for container for custom type only | ```{ padding: 16, flexDirection: 'row' }```
8081
| ```titleStyle``` | Text.propTypes.style | styles for title for all types | ```{ fontSize: 16, textAlign: 'left', fontWeight: 'bold', color: 'white', backgroundColor: 'transparent' }```
8182
| ```messageStyle``` | Text.propTypes.style | styles for message for all types | ```{ fontSize: 14, textAlign: 'left', fontWeight: 'bold', color: 'white', backgroundColor: 'transparent' }```
8283
| ```imageStyle``` | Image.propTypes.style | styles for image for all types | ```{ padding: 8, width: 36, height: 36, alignSelf: 'center' }```
@@ -87,5 +88,7 @@ onClose(data) {
8788
| ```errorColor``` | String | Default background color of error message | #cc3232
8889
| ```elevation``` | Number | Animated.View elevation | 1
8990
| ```sensitivity``` | Number | Sensitivity for the pan responder up gesture | 20
91+
| ```defaultContainer``` | ViewPropTypes.style | Style for inner view container (**override paddingTop with this**) | ```{ padding: 8, paddingTop: IS_ANDROID ? 0 : 20, flexDirection: 'row' } ```
92+
| ```defaultTextContainer``` | ViewPropTypes.style | Style for inner text container (holds title and message) | ```{ flex: 1, padding: 8 }```
9093

9194
> Inspired by: [RKDropdownAlert](https://github.com/cwRichardKim/RKDropdownAlert)

0 commit comments

Comments
 (0)