Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. /**
  2. * Demostrate how the positioning of a fullscreen modal on Android tablet's can go wrong
  3. */
  4.  
  5. import React, { Component } from 'react';
  6. import {
  7. AppRegistry,
  8. StyleSheet,
  9. Modal,
  10. Text,
  11. TouchableHighlight,
  12. TouchableWithoutFeedback,
  13. View
  14. } from 'react-native';
  15.  
  16. class ModalProblem extends Component {
  17. constructor(props) {
  18. super(props);
  19.  
  20. this.state = {
  21. modal: false,
  22. }
  23. }
  24. render() {
  25. return (
  26. <View style={styles.container}>
  27. <Text style={styles.welcome}>
  28. Welcome to React Native!
  29. </Text>
  30. <Text style={styles.instructions}>
  31. To get started, edit index.android.js
  32. </Text>
  33. <Text style={styles.instructions}>
  34. Double tap R on your keyboard to reload,{'\n'}
  35. Shake or press menu button for dev menu
  36. </Text>
  37. <TouchableHighlight
  38. onPress={() => {
  39. this.setState({
  40. modal: true,
  41. });
  42. }}
  43. >
  44. <View style={{ backgroundColor: 'red', padding: 10, borderRadius: 2 }}>
  45. <Text style={{ color: 'white' }}>open modal</Text>
  46. </View>
  47. </TouchableHighlight>
  48. <Modal
  49. visible={this.state.modal}
  50. transparent
  51. onRequestClose={() => {
  52. this.setState({
  53. modal: false,
  54. });
  55. }}
  56. >
  57. <TouchableWithoutFeedback
  58. onPress={() => {
  59. this.setState({
  60. modal: false,
  61. });
  62. }}
  63. >
  64. {/* Full screen dark transparent modal */}
  65. <View style={{ backgroundColor: '#000', opacity: 0.7, left: 0, top: 0, right: 0, bottom: 0, position: 'absolute' }} />
  66. </TouchableWithoutFeedback>
  67. </Modal>
  68. </View>
  69. );
  70. }
  71. }
  72.  
  73. const styles = StyleSheet.create({
  74. container: {
  75. flex: 1,
  76. justifyContent: 'center',
  77. alignItems: 'center',
  78. backgroundColor: '#F5FCFF',
  79. },
  80. welcome: {
  81. fontSize: 20,
  82. textAlign: 'center',
  83. margin: 10,
  84. },
  85. instructions: {
  86. textAlign: 'center',
  87. color: '#333333',
  88. marginBottom: 5,
  89. },
  90. });
  91.  
  92. AppRegistry.registerComponent('ModalProblem', () => ModalProblem);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement