forked from vergnet/application-amicale
		
	Improved layout
This commit is contained in:
		
							parent
							
								
									1f64c734aa
								
							
						
					
					
						commit
						38ada0c027
					
				
					 6 changed files with 69 additions and 45 deletions
				
			
		|  | @ -5,7 +5,7 @@ import ThemeManager from '../utils/ThemeManager'; | ||||||
| import WebDataManager from "../utils/WebDataManager"; | import WebDataManager from "../utils/WebDataManager"; | ||||||
| import {MaterialCommunityIcons} from "@expo/vector-icons"; | import {MaterialCommunityIcons} from "@expo/vector-icons"; | ||||||
| import i18n from "i18n-js"; | import i18n from "i18n-js"; | ||||||
| import {ActivityIndicator, Subheading} from 'react-native-paper'; | import {ActivityIndicator, Snackbar, Subheading} from 'react-native-paper'; | ||||||
| import {RefreshControl, SectionList, View} from "react-native"; | import {RefreshControl, SectionList, View} from "react-native"; | ||||||
| 
 | 
 | ||||||
| type Props = { | type Props = { | ||||||
|  | @ -16,13 +16,13 @@ type Props = { | ||||||
|     renderSectionHeader: React.Node, |     renderSectionHeader: React.Node, | ||||||
|     stickyHeader: boolean, |     stickyHeader: boolean, | ||||||
|     createDataset: Function, |     createDataset: Function, | ||||||
|     updateErrorText: string, |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type State = { | type State = { | ||||||
|     refreshing: boolean, |     refreshing: boolean, | ||||||
|     firstLoading: boolean, |     firstLoading: boolean, | ||||||
|     fetchedData: Object, |     fetchedData: Object, | ||||||
|  |     snackbarVisible: boolean | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  | @ -37,7 +37,7 @@ type State = { | ||||||
| export default class WebSectionList extends React.Component<Props, State> { | export default class WebSectionList extends React.Component<Props, State> { | ||||||
| 
 | 
 | ||||||
|     static defaultProps = { |     static defaultProps = { | ||||||
|         renderSectionHeader: undefined, |         renderSectionHeader: null, | ||||||
|         stickyHeader: false, |         stickyHeader: false, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | @ -50,6 +50,7 @@ export default class WebSectionList extends React.Component<Props, State> { | ||||||
|         refreshing: false, |         refreshing: false, | ||||||
|         firstLoading: true, |         firstLoading: true, | ||||||
|         fetchedData: {}, |         fetchedData: {}, | ||||||
|  |         snackbarVisible: false | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     onRefresh: Function; |     onRefresh: Function; | ||||||
|  | @ -57,6 +58,8 @@ export default class WebSectionList extends React.Component<Props, State> { | ||||||
|     onFetchError: Function; |     onFetchError: Function; | ||||||
|     getEmptyRenderItem: Function; |     getEmptyRenderItem: Function; | ||||||
|     getEmptySectionHeader: Function; |     getEmptySectionHeader: Function; | ||||||
|  |     showSnackBar: Function; | ||||||
|  |     hideSnackBar: Function; | ||||||
| 
 | 
 | ||||||
|     constructor() { |     constructor() { | ||||||
|         super(); |         super(); | ||||||
|  | @ -66,6 +69,8 @@ export default class WebSectionList extends React.Component<Props, State> { | ||||||
|         this.onFetchError = this.onFetchError.bind(this); |         this.onFetchError = this.onFetchError.bind(this); | ||||||
|         this.getEmptyRenderItem = this.getEmptyRenderItem.bind(this); |         this.getEmptyRenderItem = this.getEmptyRenderItem.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); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -112,7 +117,8 @@ export default class WebSectionList extends React.Component<Props, State> { | ||||||
|             refreshing: false, |             refreshing: false, | ||||||
|             firstLoading: false |             firstLoading: false | ||||||
|         }); |         }); | ||||||
|         this.webDataManager.showUpdateToast(this.props.updateErrorText); |         this.showSnackBar(); | ||||||
|  |         // this.webDataManager.showUpdateToast(this.props.updateErrorText);
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -194,30 +200,51 @@ export default class WebSectionList extends React.Component<Props, State> { | ||||||
|         return item.text |         return item.text | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     showSnackBar() { | ||||||
|  |         this.setState({snackbarVisible: true}) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     hideSnackBar() { | ||||||
|  |         this.setState({snackbarVisible: false}) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     render() { |     render() { | ||||||
|         let dataset = this.props.createDataset(this.state.fetchedData); |         let dataset = this.props.createDataset(this.state.fetchedData); | ||||||
|         const isEmpty = dataset[0].data.length === 0; |         const isEmpty = dataset[0].data.length === 0; | ||||||
|         const shouldRenderHeader = isEmpty || (this.props.renderSectionHeader !== undefined); |         const shouldRenderHeader = !isEmpty || (this.props.renderSectionHeader !== null); | ||||||
|         if (isEmpty) |         if (isEmpty) | ||||||
|             dataset = this.createEmptyDataset(); |             dataset = this.createEmptyDataset(); | ||||||
|         return ( |         return ( | ||||||
|             <SectionList |             <View> | ||||||
|                 sections={dataset} |                 <Snackbar | ||||||
|                 refreshControl={ |                     visible={this.state.snackbarVisible} | ||||||
|                     <RefreshControl |                     onDismiss={this.hideSnackBar} | ||||||
|                         refreshing={this.state.refreshing} |                     action={{ | ||||||
|                         onRefresh={this.onRefresh} |                         label: 'OK', | ||||||
|                     /> |                         onPress: this.hideSnackBar, | ||||||
|                 } |                     }} | ||||||
|                 renderSectionHeader={shouldRenderHeader ? this.getEmptySectionHeader : this.props.renderSectionHeader} |                     duration={4000} | ||||||
|                 renderItem={isEmpty ? this.getEmptyRenderItem : this.props.renderItem} |                 > | ||||||
|                 style={{minHeight: 300, width: '100%'}} |                     {i18n.t("homeScreen.listUpdateFail")} | ||||||
|                 stickySectionHeadersEnabled={this.props.stickyHeader} |                 </Snackbar> | ||||||
|                 contentContainerStyle={ |                 <SectionList | ||||||
|                     isEmpty ? |                     sections={dataset} | ||||||
|                         {flexGrow: 1, justifyContent: 'center', alignItems: 'center'} : {} |                     refreshControl={ | ||||||
|                 } |                         <RefreshControl | ||||||
|             /> |                             refreshing={this.state.refreshing} | ||||||
|  |                             onRefresh={this.onRefresh} | ||||||
|  |                         /> | ||||||
|  |                     } | ||||||
|  |                     renderSectionHeader={shouldRenderHeader ? this.props.renderSectionHeader : this.getEmptySectionHeader} | ||||||
|  |                     renderItem={isEmpty ? this.getEmptyRenderItem : this.props.renderItem} | ||||||
|  |                     style={{minHeight: 300, width: '100%'}} | ||||||
|  |                     stickySectionHeadersEnabled={this.props.stickyHeader} | ||||||
|  |                     contentContainerStyle={ | ||||||
|  |                         isEmpty ? | ||||||
|  |                             {flexGrow: 1, justifyContent: 'center', alignItems: 'center'} : {} | ||||||
|  |                     } | ||||||
|  |                 /> | ||||||
|  |             </View> | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -552,8 +552,7 @@ export default class HomeScreen extends React.Component<Props> { | ||||||
|                 navigation={nav} |                 navigation={nav} | ||||||
|                 refreshTime={REFRESH_TIME} |                 refreshTime={REFRESH_TIME} | ||||||
|                 fetchUrl={DATA_URL} |                 fetchUrl={DATA_URL} | ||||||
|                 renderItem={this.getRenderItem} |                 renderItem={this.getRenderItem}/> | ||||||
|                 updateErrorText={i18n.t("homeScreen.listUpdateFail")}/> |  | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -327,7 +327,7 @@ export default class ProximoListScreen extends React.Component<Props, State> { | ||||||
|                 description={item.quantity + ' ' + i18n.t('proximoScreen.inStock')} |                 description={item.quantity + ' ' + i18n.t('proximoScreen.inStock')} | ||||||
|                 descriptionStyle={{color: this.getStockColor(parseInt(item.quantity))}} |                 descriptionStyle={{color: this.getStockColor(parseInt(item.quantity))}} | ||||||
|                 onPress={onPress} |                 onPress={onPress} | ||||||
|                 left={props => <Avatar.Image size={64} source={{uri: item.image}}/>} |                 left={props => <Avatar.Image style={{backgroundColor: 'transparent'}} size={64} source={{uri: item.image}}/>} | ||||||
|                 right={props => |                 right={props => | ||||||
|                     <Text style={{fontWeight: "bold"}}> |                     <Text style={{fontWeight: "bold"}}> | ||||||
|                         {item.price}€ |                         {item.price}€ | ||||||
|  |  | ||||||
|  | @ -205,8 +205,7 @@ export default class ProximoMainScreen extends React.Component<Props, State> { | ||||||
|                 navigation={nav} |                 navigation={nav} | ||||||
|                 refreshTime={0} |                 refreshTime={0} | ||||||
|                 fetchUrl={DATA_URL} |                 fetchUrl={DATA_URL} | ||||||
|                 renderItem={this.getRenderItem} |                 renderItem={this.getRenderItem}/> | ||||||
|                 updateErrorText={i18n.t("homeScreen.listUpdateFail")}/> |  | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -8,7 +8,7 @@ import WebSectionList from "../../components/WebSectionList"; | ||||||
| import NotificationsManager from "../../utils/NotificationsManager"; | import NotificationsManager from "../../utils/NotificationsManager"; | ||||||
| import AsyncStorageManager from "../../utils/AsyncStorageManager"; | import AsyncStorageManager from "../../utils/AsyncStorageManager"; | ||||||
| import * as Expo from "expo"; | import * as Expo from "expo"; | ||||||
| import {Divider, IconButton, List, Text} from 'react-native-paper'; | import {Divider, IconButton, List, Text, Title} from 'react-native-paper'; | ||||||
| 
 | 
 | ||||||
| const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json"; | const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json"; | ||||||
| 
 | 
 | ||||||
|  | @ -47,6 +47,7 @@ export default class ProxiwashScreen extends React.Component<Props, State> { | ||||||
| 
 | 
 | ||||||
|     onAboutPress: Function; |     onAboutPress: Function; | ||||||
|     getRenderItem: Function; |     getRenderItem: Function; | ||||||
|  |     getRenderSectionHeader: Function; | ||||||
|     createDataset: Function; |     createDataset: Function; | ||||||
| 
 | 
 | ||||||
|     state = { |     state = { | ||||||
|  | @ -88,9 +89,9 @@ export default class ProxiwashScreen extends React.Component<Props, State> { | ||||||
|         stateIcons[MACHINE_STATES.ERREUR] = 'alert'; |         stateIcons[MACHINE_STATES.ERREUR] = 'alert'; | ||||||
| 
 | 
 | ||||||
|         // let dataString = AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.current;
 |         // let dataString = AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.current;
 | ||||||
|         // this.setMinTimeRefresh(30);
 |  | ||||||
|         this.onAboutPress = this.onAboutPress.bind(this); |         this.onAboutPress = this.onAboutPress.bind(this); | ||||||
|         this.getRenderItem = this.getRenderItem.bind(this); |         this.getRenderItem = this.getRenderItem.bind(this); | ||||||
|  |         this.getRenderSectionHeader = this.getRenderSectionHeader.bind(this); | ||||||
|         this.createDataset = this.createDataset.bind(this); |         this.createDataset = this.createDataset.bind(this); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -303,7 +304,18 @@ export default class ProxiwashScreen extends React.Component<Props, State> { | ||||||
|                 refreshTime={REFRESH_TIME} |                 refreshTime={REFRESH_TIME} | ||||||
|                 fetchUrl={DATA_URL} |                 fetchUrl={DATA_URL} | ||||||
|                 renderItem={this.getRenderItem} |                 renderItem={this.getRenderItem} | ||||||
|                 updateErrorText={i18n.t("proxiwashScreen.listUpdateFail")}/> |                 renderSectionHeader={this.getRenderSectionHeader}/> | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     getRenderSectionHeader({section}: Object) { | ||||||
|  |         return ( | ||||||
|  |             <Title style={{ | ||||||
|  |                 marginTop: 10, | ||||||
|  |                 textAlign: 'center' | ||||||
|  |             }}> | ||||||
|  |                 {section.title} | ||||||
|  |             </Title> | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -95,19 +95,7 @@ export default class SelfMenuScreen extends React.Component<Props> { | ||||||
| 
 | 
 | ||||||
|     getRenderSectionHeader({section}: Object) { |     getRenderSectionHeader({section}: Object) { | ||||||
|         return ( |         return ( | ||||||
|             <Card style={{ |             <Title>{section.title}</Title> | ||||||
|                 marginLeft: 10, |  | ||||||
|                 marginRight: 10, |  | ||||||
|                 marginTop: 10, |  | ||||||
|                 marginBottom: 10, |  | ||||||
|                 borderRadius: 50 |  | ||||||
|             }}> |  | ||||||
|                 <Title style={{ |  | ||||||
|                     textAlign: 'center', |  | ||||||
|                     marginTop: 10, |  | ||||||
|                     marginBottom: 10 |  | ||||||
|                 }}>{section.title}</Title> |  | ||||||
|             </Card> |  | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -119,7 +107,7 @@ export default class SelfMenuScreen extends React.Component<Props> { | ||||||
|             }}> |             }}> | ||||||
|                     <Card.Title |                     <Card.Title | ||||||
|                         title={item.name} |                         title={item.name} | ||||||
|                         titleStyle={{textAlign: 'center'}}/> |                     /> | ||||||
|                     <View style={{ |                     <View style={{ | ||||||
|                         width: '80%', |                         width: '80%', | ||||||
|                         marginLeft: 'auto', |                         marginLeft: 'auto', | ||||||
|  | @ -159,7 +147,6 @@ export default class SelfMenuScreen extends React.Component<Props> { | ||||||
|                 fetchUrl={DATA_URL} |                 fetchUrl={DATA_URL} | ||||||
|                 renderItem={this.getRenderItem} |                 renderItem={this.getRenderItem} | ||||||
|                 renderSectionHeader={this.getRenderSectionHeader} |                 renderSectionHeader={this.getRenderSectionHeader} | ||||||
|                 updateErrorText={i18n.t("homeScreen.listUpdateFail")} |  | ||||||
|                 stickyHeader={true}/> |                 stickyHeader={true}/> | ||||||
|         ); |         ); | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue