Не могу ориентироваться после упаковки компонента - PullRequest
0 голосов
/ 06 февраля 2019

У меня есть 2 компонента: IOSWrapperNav и настройки,

Я прилагаю код:

export class IOSWrapperNav extends Component {
constructor(props){
    super(props)
}
render() {
   const flag= (this.props.profile.role==='ROLE'||this.props.profile.role==='MAINTENANCE')?true:false
   const MaintenanceView = TabNavigator({
    DashboardTabs: {
      screen: DashboardTabsWrapper,
        navigationOptions: {
          initialRouteName: 'DashboardTabs',
          title: 'Dashboard',
          tabBarIcon: ({tintColor}) => (
            <FontAwesome name='dashboard' color={tintColor} size={29}/>
          )
        }
    },
    Profile : {
      screen: ProfileWrapper,
      navigationOptions: {
        initialRouteName: 'Profile',
        title: 'Profile',
        tabBarIcon: ({tintColor}) => (
          <FontAwesome name='user' color={tintColor} size={27}/>
        )
      }
    },
    Settings: {
      screen: SettingsWrapper,
      navigationOptions: {
        initialRouteName: 'Settings',
        title: 'Settings',
        tabBarIcon: ({tintColor}) => (
          <Icon name='ios-settings' color={tintColor} size={28}/>
        )
      }
    },
    Maintenance: {
      screen: Maintenance,
      navigationOptions: {
        initialRouteName: 'Maintenance',
        title: 'Maintenance',
        tabBarIcon: ({tintColor}) => (
          <Icon name='ios-settings' color={tintColor} size={28}/>
        )
      }
    }
   },

  {
    lazyLoad: true,
    tabBarOptions:{
    style:{ paddingBottom: isIphoneXSMax()===true? 30:0,
      height:isIphoneXSMax()===true? 80: 50
    },
  },
    tabBarPosition: 'bottom',
    swipeEnabled: false,
  });
  const NoMaintenanceView = TabNavigator({
    DashboardTabs: {
      screen: DashboardTabsWrapper,
        navigationOptions: {
          initialRouteName: 'DashboardTabs',
          title: 'Dashboard',
          tabBarIcon: ({tintColor}) => (
            <FontAwesome name='dashboard' color={tintColor} size={29}/>
          )
        }
    },
    Profile : {
      screen: ProfileWrapper,
      navigationOptions: {
        initialRouteName: 'Profile',
        title: 'Profile',
        tabBarIcon: ({tintColor}) => (
          <FontAwesome name='user' color={tintColor} size={27}/>
        )
      }
    },
    Settings: {
      screen: SettingsWrapper,
      navigationOptions: {
        initialRouteName: 'Settings',
        title: 'Settings',
        tabBarIcon: ({tintColor}) => (
          <Icon name='ios-settings' color={tintColor} size={28}/>
        )
      }
    },
   },

  {
    lazyLoad: true,
    tabBarOptions:{
    style:{ paddingBottom: isIphoneXSMax()===true? 30:0,
      height:isIphoneXSMax()===true? 80: 50
    },
  },
    tabBarPosition: 'bottom',
    swipeEnabled: false,
  });
  const MainTab= flag?MaintenanceView:NoMaintenanceView
  return (
    <View style={{ flex: 1 }}>
      <MainTab />
    </View>
  );
}
 }

 export default connect(
state => {
  return {
    profile: state.profile,
    login: state.login
  }
},
dispatch => ({
  profileActions : bindActionCreators(ProfileActions, dispatch)
})
 )(IOSWrapperNav)

и настройки:

  class Settings extends Component {
  constructor(props) {
super(props)
this.state = { }
this.version = '2.0'
  }

  /**
   * Navigation methods
     */
   goToWristbandGuide() {
   this.props.navigation.navigate('Wristband')
    }
  goToFaq() {
   this.props.navigation.navigate('Faq')
 }
  goToDashboardGuide() {
   this.props.navigation.navigate('DashboardHelp')
  }
  goToChangePassword() {
   this.props.navigation.navigate('ChangePassword')
   }
   goToSupport() {}


  handleLogout() {
    this.props.rootNav.dispatch(GoToLogin)
    }


      /**
     * Render
      */
    render() {
      return (
  <View style={styles.root}>
  <View style={styles.container}>
    <LinearGradient
      colors={['#465EDC', '#1A87F2']}
      start={{x: 0, y: 1}}
      end={{x:1,y:0}}
      locations={[.05,.95]}
      >
        <Header height={85} drawerNav={this.props.rootNav}/>
      </LinearGradient>
  <ScrollView style={styles.scroll}>
    <View style={styles.bottomContainer}>
    </View>
    <TouchableOpacity
        activeOpacity={100}>
      <View style={styles.row}>
          <Text style={styles.leftText}>Account</Text>
      </View>
    </TouchableOpacity>
    <TouchableOpacity
        activeOpacity={100}
        onPress={this.goToChangePassword.bind(this)}>
      <View style={styles.row}>
          <Text style={styles.indentText}>Change Password</Text>
      </View>
    </TouchableOpacity>
    <TouchableOpacity 
      activeOpacity={100}>
    <View style={styles.bottomContainer}>
    </View>
      <View style={styles.row}>
          <Text style={styles.leftText}>Help</Text>
      </View>
    </TouchableOpacity>
    <TouchableOpacity
       activeOpacity={100}
       onPress={this.goToFaq.bind(this)}>
      <View style={styles.row}>
          <Text style={styles.indentText}>FAQs</Text>
      </View>
    </TouchableOpacity>
    <TouchableOpacity
       activeOpacity={100}
       onPress={this.goToDashboardGuide.bind(this)}>
      <View style={styles.row}>
          <Text style={styles.indentText}>Dashboard Data Guide</Text>
      </View>
    </TouchableOpacity>
    <TouchableOpacity
        activeOpacity={100}
        onPress={this.goToWristbandGuide.bind(this)}>
      <View style={styles.row}>
          <Text style={styles.indentText}>Wristband User Guide</Text>
      </View>
    </TouchableOpacity>
    <TouchableOpacity
       activeOpacity={100}
       onPress={this.goToSupport.bind(this)}>
    </TouchableOpacity>
    <TouchableOpacity 
      activeOpacity={100}>
    <View style={styles.bottomContainer}>
    </View>
      <View style={styles.row}>
          <Text style={styles.leftText}>Support</Text>
      </View>
    </TouchableOpacity>
      <View style={styles.row}>
          <Text style={styles.indentText} numberOfLines={1}>Version</Text><View style={[styles.rightBox]}>
          <View style={{backgroundColor: Colors.VITALACY_PURPLE, padding: 3, paddingLeft: 5, paddingRight: 5, borderRadius: 8, marginRight: 25}}>
          <Text style={[styles.rightText,{color: '#FFFFFF', fontFamily: 'NunitoSans-regular', marginRight: 0}]} >{this.version}</Text></View>
      </View>
      </View>
    <TouchableOpacity
       activeOpacity={100}>
      <View style={styles.row}>
          <Text style={styles.indentText}>Help Center</Text><View style={styles.rightBox}><Text style={styles.rightTextEmail}  onPress={() => Linking.openURL('mailto:help@vitalacy.com')}>help@vitalacy.com</Text></View>
      </View>
    </TouchableOpacity>

    <TouchableOpacity
        activeOpacity={100}
        onPress={this.handleLogout.bind(this)}>
      <View style={styles.logoutRow}>
          <Text style={styles.leftText}>Logout</Text>
      </View>
      </TouchableOpacity>

  </ScrollView>
  </View>
  </View>
      )
   }
 }



  export default connect(
    state => {
   return {
  profile: state.profile,
  login: state.login
}
 },
  dispatch => ({
    profileActions : bindActionCreators(ProfileActions, dispatch)
    })
    )(Settings)

Проблема заключается вчто эта функция: handleLogout () в компоненте «Настройки» не работает после того, как я решил обернуть IOSWrapperNav.

Перед тем, как обернуть его, компонент IOSWrapperNav выглядел следующим образом, а handleLogout () работал нормально:

     const DashboardTabsWrapper = ({navigation}) =>
      <DashboardTabs screenProps={navigation} />

 const ProfileWrapper = ({navigation}) =>   
   <ProfileNav screenProps={navigation} />

 const DrawerContentWrapper = (props) => 
  <DrawerContent items={props} navigation={props.navigation} />


 const SettingsWrapper = (props) => 

   <SettingsNav screenProps={props.navigation} />
  /**
   * Tab Navigator
   */

  const MaintenanceScreen=
   TabNavigator({
   DashboardTabs: {
screen: DashboardTabsWrapper,
  navigationOptions: {
    initialRouteName: 'DashboardTabs',
    title: 'Dashboard',
    tabBarIcon: ({tintColor}) => (
      <FontAwesome name='dashboard' color={tintColor} size={29}/>
    )
  }
   },
    Profile : {
screen: ProfileWrapper,
navigationOptions: {
  initialRouteName: 'Profile',
  title: 'Profile',
  tabBarIcon: ({tintColor}) => (
    <FontAwesome name='user' color={tintColor} size={27}/>
  )
}
   },
     Settings: {
    screen: SettingsWrapper,
navigationOptions: {
  initialRouteName: 'Settings',
  title: 'Settings',
  tabBarIcon: ({tintColor}) => (
    <Icon name='ios-settings' color={tintColor} size={28}/>
  )
}
   },
    Maintenance: {
screen: Maintenance,
navigationOptions: {
  initialRouteName: 'Maintenance',
  title: 'Maintenance',
  tabBarIcon: ({tintColor}) => (
    <Icon name='ios-settings' color={tintColor} size={28}/>
  )
   }
   }
    },

 {
 lazyLoad: true,
  tabBarOptions:{
  style:{ paddingBottom: isIphoneXSMax()===true? 30:0,
  height:isIphoneXSMax()===true? 80: 50
    },
    },
  tabBarPosition: 'bottom',
  swipeEnabled: false,
   })

  const NoMaintenanceScreen= TabNavigator({
   DashboardTabs: {
   screen: DashboardTabsWrapper,
  navigationOptions: {
    initialRouteName: 'DashboardTabs',
    title: 'Dashboard',
    tabBarIcon: ({tintColor}) => (
      <FontAwesome name='dashboard' color={tintColor} size={29}/>
    )
  }
  },
 Profile : {
 screen: ProfileWrapper,
 navigationOptions: {
  initialRouteName: 'Profile',
  title: 'Profile',
  tabBarIcon: ({tintColor}) => (
    <FontAwesome name='user' color={tintColor} size={27}/>
  )
}
   },
   Settings: {
  screen: SettingsWrapper,
  navigationOptions: {
  initialRouteName: 'Settings',
  title: 'Settings',
  tabBarIcon: ({tintColor}) => (
    <Icon name='ios-settings' color={tintColor} size={28}/>
  )
}
  },

 },

 {
 lazyLoad: true,
 tabBarOptions:{
 style:{ paddingBottom: isIphoneXSMax()===true? 30:0,
height:isIphoneXSMax()===true? 80: 50
  },
 },
  tabBarPosition: 'bottom',
  swipeEnabled: false,
})

      const IOSNav= true? 
      MaintenanceScreen
       :
       NoMaintenanceScreen;


   export default IOSNav

вот код для GoToLogin в случае необходимости:

  export const GoToLogin = NavigationActions.reset({
index: 0,
actions: [
  NavigationActions.navigate({ routeName: 'Login'})
]
})

Я пытался найти проблему, но ничего не пришло ... Мне пришлось обернуть его для получения реквизитаот родительского компонента.спасибо за помощь

...