react-native-navigation的迁移库

Toast.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const React = require('react');
  2. const { View, Text, StyleSheet, TouchableOpacity } = require('react-native');
  3. const Colors = require('../commons/Colors');
  4. const Navigation = require('../services/Navigation');
  5. const {
  6. TOAST_OK_BTN_INNER,
  7. TOAST_OK_BTN_OUTER
  8. } = require('../testIDs');
  9. const Toast = function ({componentId}) {
  10. const dismiss = (txt) => {
  11. alert(txt)
  12. Navigation.dismissOverlay(componentId);
  13. }
  14. return (
  15. <View style={styles.root}>
  16. <TouchableOpacity testID={TOAST_OK_BTN_OUTER} onPress={() => dismiss('Outer button clicked')}>
  17. <View style={styles.toast}>
  18. <Text style={styles.text}>This a very important message!</Text>
  19. <TouchableOpacity testID={TOAST_OK_BTN_INNER} style={styles.button} onPress={() => dismiss('Inner button clicked')}>
  20. <Text style={styles.buttonText}>OK</Text>
  21. </TouchableOpacity>
  22. </View>
  23. </TouchableOpacity>
  24. </View>
  25. )
  26. }
  27. const styles = StyleSheet.create({
  28. root: {
  29. flex: 1,
  30. flexDirection: 'column-reverse',
  31. backgroundColor: 0x3e434aa1
  32. },
  33. toast: {
  34. elevation: 2,
  35. flexDirection: 'row',
  36. height: 40,
  37. margin: 16,
  38. borderRadius: 20,
  39. backgroundColor: Colors.accent,
  40. alignItems: 'center',
  41. justifyContent: 'space-between'
  42. },
  43. text: {
  44. color: 'white',
  45. fontSize: 16,
  46. marginLeft: 16
  47. },
  48. button: {
  49. marginRight: 16
  50. },
  51. buttonText: {
  52. color: 'white',
  53. fontSize: 16,
  54. fontWeight: 'bold'
  55. }
  56. });
  57. Toast.options = {
  58. statusBar: {
  59. drawBehind: true,
  60. backgroundColor: 0x3e434aa1,
  61. style: 'light'
  62. },
  63. layout: {
  64. componentBackgroundColor: 'transparent'
  65. },
  66. overlay: {
  67. interceptTouchOutside: false
  68. }
  69. }
  70. module.exports = Toast;