diff --git a/components/Custom/HeaderButton.js b/components/Custom/HeaderButton.js index 5e09cee..6c9edcf 100644 --- a/components/Custom/HeaderButton.js +++ b/components/Custom/HeaderButton.js @@ -13,7 +13,7 @@ function HeaderButton(props) { ); diff --git a/components/Lists/WebSectionList.js b/components/Lists/WebSectionList.js index af215b5..b0ec351 100644 --- a/components/Lists/WebSectionList.js +++ b/components/Lists/WebSectionList.js @@ -57,8 +57,6 @@ export default class WebSectionList extends React.PureComponent { onFetchSuccess: Function; onFetchError: Function; getEmptySectionHeader: Function; - showSnackBar: Function; - hideSnackBar: Function; constructor() { super(); @@ -67,8 +65,6 @@ export default class WebSectionList extends React.PureComponent { this.onFetchSuccess = this.onFetchSuccess.bind(this); this.onFetchError = this.onFetchError.bind(this); this.getEmptySectionHeader = this.getEmptySectionHeader.bind(this); - this.showSnackBar = this.showSnackBar.bind(this); - this.hideSnackBar = this.hideSnackBar.bind(this); } /** @@ -159,16 +155,12 @@ export default class WebSectionList extends React.PureComponent { /** * Shows the error popup */ - showSnackBar() { - this.setState({snackbarVisible: true}) - } + showSnackBar = () => this.setState({snackbarVisible: true}); /** * Hides the error popup */ - hideSnackBar() { - this.setState({snackbarVisible: false}) - } + hideSnackBar = () => this.setState({snackbarVisible: false}); render() { let dataset = []; @@ -177,17 +169,6 @@ export default class WebSectionList extends React.PureComponent { const shouldRenderHeader = this.props.renderSectionHeader !== null; return ( - - {i18n.t("homeScreen.listUpdateFail")} - {/*$FlowFixMe*/} { onRefresh={this.onRefresh}/> } /> + {}, + }} + duration={4000} + > + {i18n.t("homeScreen.listUpdateFail")} + ); } diff --git a/screens/HomeScreen.js b/screens/HomeScreen.js index f39617a..6b85bbf 100644 --- a/screens/HomeScreen.js +++ b/screens/HomeScreen.js @@ -32,16 +32,10 @@ type Props = { theme: Object, } -type State = { - imageModalVisible: boolean, - imageList: Array, - isLoggedIn: boolean, -} - /** * Class defining the app's home screen */ -class HomeScreen extends React.Component { +class HomeScreen extends React.Component { onProxiwashClick: Function; onTutorInsaClick: Function; @@ -52,15 +46,10 @@ class HomeScreen extends React.Component { colors: Object; - state = { - imageModalVisible: false, - imageList: [], - isLoggedIn: ConnectionManager.getInstance().isLoggedIn(), - }; + isLoggedIn: boolean | null; constructor(props) { super(props); - ConnectionManager.getInstance().addLoginStateListener((value) => this.setState({isLoggedIn: value})); this.onProxiwashClick = this.onProxiwashClick.bind(this); this.onTutorInsaClick = this.onTutorInsaClick.bind(this); this.onMenuClick = this.onMenuClick.bind(this); @@ -68,6 +57,8 @@ class HomeScreen extends React.Component { this.getRenderItem = this.getRenderItem.bind(this); this.createDataset = this.createDataset.bind(this); this.colors = props.theme.colors; + + this.isLoggedIn = null; } /** @@ -82,20 +73,32 @@ class HomeScreen extends React.Component { } componentDidMount() { - this.props.navigation.setOptions({ - headerRight: this.getHeaderButton, - }); + this.props.navigation.addListener('focus', this.onScreenFocus); } + onScreenFocus = () => { + if (this.isLoggedIn !== ConnectionManager.getInstance().isLoggedIn()) { + this.isLoggedIn = ConnectionManager.getInstance().isLoggedIn(); + this.props.navigation.setOptions({ + headerRight: this.getHeaderButton, + }); + } + + }; + getHeaderButton = () => { - const screen = this.state.isLoggedIn + const screen = this.isLoggedIn ? "ProfileScreen" : "LoginScreen"; - const icon = this.state.isLoggedIn + const icon = this.isLoggedIn ? "account" : "login"; const onPress = () => this.props.navigation.navigate(screen); - return ; + return ; }; onProxiwashClick() { @@ -448,18 +451,6 @@ class HomeScreen extends React.Component { openBrowser(link, this.colors.primary); } - showImageModal(imageList) { - this.setState({ - imageModalVisible: true, - imageList: imageList, - }); - }; - - hideImageModal = () => { - this.setState({imageModalVisible: false}); - }; - - /** * Gets a render item for the given feed object * @@ -494,16 +485,13 @@ class HomeScreen extends React.Component { render() { const nav = this.props.navigation; return ( - - - - + ); } }