Guest User

Untitled

a guest
Jul 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { Button, StyleSheeet, View } from 'react-native';
  3.  
  4. class MultiPageWizard extends Component {
  5. static navigationOptions = ({ navigation }) => ({
  6. headerRight: navigation.getParam('getHeaderRight')
  7. });
  8.  
  9. constructor(props) {
  10. super(props);
  11.  
  12. this.state = {
  13. comment: ''
  14. }
  15. }
  16.  
  17. componentDidMount() {
  18. this.props.navigation.setParams({ getHeaderRight: this.renderHeaderRight(false) });
  19. }
  20.  
  21. goToNext = () => {
  22. // Handler of onPress method of button
  23. // ... do something like navigate to next page
  24. }
  25.  
  26. updateComment = newValue => {
  27. this.setState({
  28. comment: newValue
  29. }, () => {
  30. // Callback that executes after state is updated
  31. if (this.state.comment.length > 4) {
  32. // Replace what's rendered for the right header with an enabled button
  33. this.props.navigation.setParams({
  34. getHeaderRight: this.renderHeaderRight(true)
  35. });
  36. } else {
  37. // Replace what's rendered for the right header with a disabled button
  38. this.props.navigation.setParams({
  39. getHeaderRight: this.renderHeaderRight(false)
  40. });
  41. }
  42. });
  43. }
  44.  
  45. renderHeaderRight = enabled => (
  46. <View style={styles.headerRightButtonContainer}>
  47. <Button
  48. title="Next"
  49. disabled={!enabled}
  50. onPress={this.goToNext}
  51. />
  52. </View>
  53. );
  54.  
  55. render() {
  56. // ... Render your screen here ...
  57. }
  58. }
  59.  
  60. const styles = StyleSheet.create({
  61. headerRightContainer: {
  62. paddingRight: 5
  63. }
  64. });
  65.  
  66. export default MultiPageWizard;
Add Comment
Please, Sign In to add comment