react-native-modal-bottom-alert

Getting Started
Installation
$ yarn add react-native-modal-bottom-alert lottie-react-native
Or
$ npm install react-native-modal-bottom-alert lottie-react-native --save
Basic Usage
import { BottomAlert } from 'react-native-modal-bottom-alert';
onOpenAlert() {
this.modalBottom.onOpenAlert('info', 'This Title', 'This Message Example Info')
}
onOpenAlertButtonPressed() {
this.modalBottom.onOpenAlert('error', 'This Title', 'This Message Example Error', () => console.log('This Button Try Again Pressed'))
}
return (
<>
<Button
title={'Open Alert'}
onPress={() => this.onOpenAlert()}
/>
<Button
title={'Open Alert Button Preesed With Action'}
onPress={() => this.onOpenAlertButtonPressed()}
/>
<BottomAlert
ref={(ref) => this.modalBottom = ref}
/>
</>
)
Set Global Alert
1. Add Modal Bottom Alert on Root App
import store from './reduxStore';
import React from 'react';
import { Provider } from 'react-redux';
import { useRefBottomAlert, BottomAlert } from 'react-native-modal-bottom-alert';
let App = () => (
<Navigator>
<MainScreen />
<OtherScreen />
</Navigator>
);
const Root = () => (
<Provider store={store}>
<App />
{}
<BottomAlert ref={(ref) => useRefBottomAlert(ref) }/>
</Provider>
);
2. Add on your screen or other function
import React, { Component } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import { showBottomAlert } from 'react-native-modal-bottom-alert';
export default class App extends Component {
onOpenAlert() {
showBottomAlert('info', 'This Title', 'This Message Example Info', () => this.onDonePress())
}
onDonePress = () => {
console.log('Pressed')
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Modal Bottom Alert example</Text>
<Button
title={'Info'}
onPress={() => this.onOpenAlert()}
/>
<Button
title={'Error'}
onPress={() => showBottomAlert('error', 'This Title', 'This Message Example Error')}
/>
<Button
title={'Success'}
onPress={() => showBottomAlert('success', 'This Title', 'This Message Example Success')}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'space-around',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}
});
Props
Basic
| Prop |
Type |
Description |
Default |
| statusBarTranslucent |
boolean |
Status Bar Translucent |
false |
| loopAnimation |
boolean |
Animation Loop For Lottie Icon |
false |
Styling
| Prop |
Type |
Description |
Default |
| styleTextTitle |
object |
Text Title Style |
- |
| styleTextMessage |
object |
Text Message Style |
- |
| styleTextButton |
object |
Text Button Style |
- |
| styleButton |
object |
Button Style |
- |
| styleContainerAlert |
object |
Container Style Alert |
- |
评论