forked from vergnet/application-amicale
Fixed home header button + fixed snackbar button not working
This commit is contained in:
parent
2d26f2c395
commit
557dd000ae
3 changed files with 43 additions and 63 deletions
|
@ -13,7 +13,7 @@ function HeaderButton(props) {
|
||||||
<IconButton
|
<IconButton
|
||||||
icon={props.icon}
|
icon={props.icon}
|
||||||
size={26}
|
size={26}
|
||||||
color={colors.text}
|
color={props.color !== undefined ? props.color : colors.text}
|
||||||
onPress={props.onPress}
|
onPress={props.onPress}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
|
@ -57,8 +57,6 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
|
||||||
onFetchSuccess: Function;
|
onFetchSuccess: Function;
|
||||||
onFetchError: Function;
|
onFetchError: Function;
|
||||||
getEmptySectionHeader: Function;
|
getEmptySectionHeader: Function;
|
||||||
showSnackBar: Function;
|
|
||||||
hideSnackBar: Function;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
@ -67,8 +65,6 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
|
||||||
this.onFetchSuccess = this.onFetchSuccess.bind(this);
|
this.onFetchSuccess = this.onFetchSuccess.bind(this);
|
||||||
this.onFetchError = this.onFetchError.bind(this);
|
this.onFetchError = this.onFetchError.bind(this);
|
||||||
this.getEmptySectionHeader = this.getEmptySectionHeader.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<Props, State> {
|
||||||
/**
|
/**
|
||||||
* Shows the error popup
|
* Shows the error popup
|
||||||
*/
|
*/
|
||||||
showSnackBar() {
|
showSnackBar = () => this.setState({snackbarVisible: true});
|
||||||
this.setState({snackbarVisible: true})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hides the error popup
|
* Hides the error popup
|
||||||
*/
|
*/
|
||||||
hideSnackBar() {
|
hideSnackBar = () => this.setState({snackbarVisible: false});
|
||||||
this.setState({snackbarVisible: false})
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let dataset = [];
|
let dataset = [];
|
||||||
|
@ -177,17 +169,6 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
|
||||||
const shouldRenderHeader = this.props.renderSectionHeader !== null;
|
const shouldRenderHeader = this.props.renderSectionHeader !== null;
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
<Snackbar
|
|
||||||
visible={this.state.snackbarVisible}
|
|
||||||
onDismiss={this.hideSnackBar}
|
|
||||||
action={{
|
|
||||||
label: 'OK',
|
|
||||||
onPress: this.hideSnackBar,
|
|
||||||
}}
|
|
||||||
duration={4000}
|
|
||||||
>
|
|
||||||
{i18n.t("homeScreen.listUpdateFail")}
|
|
||||||
</Snackbar>
|
|
||||||
{/*$FlowFixMe*/}
|
{/*$FlowFixMe*/}
|
||||||
<SectionList
|
<SectionList
|
||||||
sections={dataset}
|
sections={dataset}
|
||||||
|
@ -212,6 +193,17 @@ export default class WebSectionList extends React.PureComponent<Props, State> {
|
||||||
onRefresh={this.onRefresh}/>
|
onRefresh={this.onRefresh}/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<Snackbar
|
||||||
|
visible={this.state.snackbarVisible}
|
||||||
|
onDismiss={this.hideSnackBar}
|
||||||
|
action={{
|
||||||
|
label: 'OK',
|
||||||
|
onPress: () => {},
|
||||||
|
}}
|
||||||
|
duration={4000}
|
||||||
|
>
|
||||||
|
{i18n.t("homeScreen.listUpdateFail")}
|
||||||
|
</Snackbar>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,16 +32,10 @@ type Props = {
|
||||||
theme: Object,
|
theme: Object,
|
||||||
}
|
}
|
||||||
|
|
||||||
type State = {
|
|
||||||
imageModalVisible: boolean,
|
|
||||||
imageList: Array<Object>,
|
|
||||||
isLoggedIn: boolean,
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class defining the app's home screen
|
* Class defining the app's home screen
|
||||||
*/
|
*/
|
||||||
class HomeScreen extends React.Component<Props, State> {
|
class HomeScreen extends React.Component<Props> {
|
||||||
|
|
||||||
onProxiwashClick: Function;
|
onProxiwashClick: Function;
|
||||||
onTutorInsaClick: Function;
|
onTutorInsaClick: Function;
|
||||||
|
@ -52,15 +46,10 @@ class HomeScreen extends React.Component<Props, State> {
|
||||||
|
|
||||||
colors: Object;
|
colors: Object;
|
||||||
|
|
||||||
state = {
|
isLoggedIn: boolean | null;
|
||||||
imageModalVisible: false,
|
|
||||||
imageList: [],
|
|
||||||
isLoggedIn: ConnectionManager.getInstance().isLoggedIn(),
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
ConnectionManager.getInstance().addLoginStateListener((value) => this.setState({isLoggedIn: value}));
|
|
||||||
this.onProxiwashClick = this.onProxiwashClick.bind(this);
|
this.onProxiwashClick = this.onProxiwashClick.bind(this);
|
||||||
this.onTutorInsaClick = this.onTutorInsaClick.bind(this);
|
this.onTutorInsaClick = this.onTutorInsaClick.bind(this);
|
||||||
this.onMenuClick = this.onMenuClick.bind(this);
|
this.onMenuClick = this.onMenuClick.bind(this);
|
||||||
|
@ -68,6 +57,8 @@ class HomeScreen extends React.Component<Props, State> {
|
||||||
this.getRenderItem = this.getRenderItem.bind(this);
|
this.getRenderItem = this.getRenderItem.bind(this);
|
||||||
this.createDataset = this.createDataset.bind(this);
|
this.createDataset = this.createDataset.bind(this);
|
||||||
this.colors = props.theme.colors;
|
this.colors = props.theme.colors;
|
||||||
|
|
||||||
|
this.isLoggedIn = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,20 +73,32 @@ class HomeScreen extends React.Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.navigation.setOptions({
|
this.props.navigation.addListener('focus', this.onScreenFocus);
|
||||||
headerRight: this.getHeaderButton,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onScreenFocus = () => {
|
||||||
|
if (this.isLoggedIn !== ConnectionManager.getInstance().isLoggedIn()) {
|
||||||
|
this.isLoggedIn = ConnectionManager.getInstance().isLoggedIn();
|
||||||
|
this.props.navigation.setOptions({
|
||||||
|
headerRight: this.getHeaderButton,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
getHeaderButton = () => {
|
getHeaderButton = () => {
|
||||||
const screen = this.state.isLoggedIn
|
const screen = this.isLoggedIn
|
||||||
? "ProfileScreen"
|
? "ProfileScreen"
|
||||||
: "LoginScreen";
|
: "LoginScreen";
|
||||||
const icon = this.state.isLoggedIn
|
const icon = this.isLoggedIn
|
||||||
? "account"
|
? "account"
|
||||||
: "login";
|
: "login";
|
||||||
const onPress = () => this.props.navigation.navigate(screen);
|
const onPress = () => this.props.navigation.navigate(screen);
|
||||||
return <HeaderButton icon={icon} onPress={onPress}/>;
|
return <HeaderButton
|
||||||
|
icon={icon}
|
||||||
|
onPress={onPress}
|
||||||
|
color={this.isLoggedIn ? undefined : this.colors.primary}
|
||||||
|
/>;
|
||||||
};
|
};
|
||||||
|
|
||||||
onProxiwashClick() {
|
onProxiwashClick() {
|
||||||
|
@ -448,18 +451,6 @@ class HomeScreen extends React.Component<Props, State> {
|
||||||
openBrowser(link, this.colors.primary);
|
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
|
* Gets a render item for the given feed object
|
||||||
*
|
*
|
||||||
|
@ -494,16 +485,13 @@ class HomeScreen extends React.Component<Props, State> {
|
||||||
render() {
|
render() {
|
||||||
const nav = this.props.navigation;
|
const nav = this.props.navigation;
|
||||||
return (
|
return (
|
||||||
<View>
|
<WebSectionList
|
||||||
<WebSectionList
|
createDataset={this.createDataset}
|
||||||
createDataset={this.createDataset}
|
navigation={nav}
|
||||||
navigation={nav}
|
autoRefreshTime={REFRESH_TIME}
|
||||||
autoRefreshTime={REFRESH_TIME}
|
refreshOnFocus={true}
|
||||||
refreshOnFocus={true}
|
fetchUrl={DATA_URL}
|
||||||
fetchUrl={DATA_URL}
|
renderItem={this.getRenderItem}/>
|
||||||
renderItem={this.getRenderItem}/>
|
|
||||||
</View>
|
|
||||||
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue