react-native-navigation的迁移库

SetRootScreen.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const React = require('react');
  2. const Root = require('../components/Root');
  3. const Button = require('../components/Button')
  4. const Navigation = require('./../services/Navigation');
  5. const {
  6. NAVIGATION_TAB,
  7. SET_MULTIPLE_ROOTS_BTN
  8. } = require('../testIDs');
  9. const Screens = require('./Screens');
  10. class SetRootScreen extends React.Component {
  11. static options() {
  12. return {
  13. topBar: {
  14. title: {
  15. text: 'Navigation'
  16. }
  17. },
  18. bottomTab: {
  19. text: 'Navigation',
  20. icon: require('../../img/navigation.png'),
  21. testID: NAVIGATION_TAB
  22. }
  23. };
  24. }
  25. render() {
  26. return (
  27. <Root componentId={this.props.componentId}>
  28. <Button label='Set Multiple Roots' testID={SET_MULTIPLE_ROOTS_BTN} onPress={this.setMultipleRoot} />
  29. </Root>
  30. );
  31. }
  32. setMultipleRoot = async () => {
  33. await this.setRoot();
  34. await this.setRoot();
  35. };
  36. setRoot = async () => await Navigation.setRoot({
  37. root: {
  38. stack: {
  39. id: 'stack',
  40. children: [{
  41. component: {
  42. id: 'component',
  43. name: Screens.Pushed
  44. }
  45. }]
  46. }
  47. }
  48. });
  49. }
  50. module.exports = SetRootScreen;