react-native-navigation的迁移库

SideMenu.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React, {Component} from 'react';
  2. import {
  3. Text,
  4. View,
  5. ScrollView,
  6. TouchableOpacity,
  7. StyleSheet,
  8. AlertIOS
  9. } from 'react-native';
  10. export default class SideMenu extends Component {
  11. constructor(props) {
  12. super(props);
  13. }
  14. render() {
  15. return (
  16. <View style={styles.container}>
  17. <Text style={styles.title}>Side Menu</Text>
  18. <TouchableOpacity onPress={ this.onReplaceTab2Press.bind(this) }>
  19. <Text style={styles.button}>Replace Tab#2 Root</Text>
  20. </TouchableOpacity>
  21. <TouchableOpacity onPress={ this.onModalPress.bind(this) }>
  22. <Text style={styles.button}>Show Modal Screen</Text>
  23. </TouchableOpacity>
  24. </View>
  25. );
  26. }
  27. onReplaceTab2Press() {
  28. this._toggleDrawer();
  29. // push/pop navigator actions affect the navigation stack of the current screen only.
  30. // since side menu actions are normally directed at sibling tabs, push/pop will
  31. // not help us. the recommended alternative is to use deep links for this purpose
  32. this.props.navigator.handleDeepLink({
  33. link: "tab2/example.PushedScreen"
  34. });
  35. }
  36. onModalPress() {
  37. this._toggleDrawer();
  38. this.props.navigator.showModal({
  39. title: "Modal",
  40. screen: "example.ModalScreen"
  41. });
  42. }
  43. _toggleDrawer() {
  44. this.props.navigator.toggleDrawer({
  45. to: 'closed',
  46. side: 'left',
  47. animated: true
  48. });
  49. }
  50. }
  51. const styles = StyleSheet.create({
  52. container: {
  53. flex: 1,
  54. alignItems: 'center',
  55. backgroundColor: 'white',
  56. justifyContent: 'center',
  57. width: 300
  58. },
  59. title: {
  60. textAlign: 'center',
  61. fontSize: 18,
  62. marginBottom: 10,
  63. marginTop:10,
  64. fontWeight: '500'
  65. },
  66. button: {
  67. textAlign: 'center',
  68. fontSize: 18,
  69. marginBottom: 10,
  70. marginTop:10,
  71. color: 'blue'
  72. }
  73. });