|
6 | 6 | import React from 'react'; |
7 | 7 | import { |
8 | 8 | AppRegistry, |
| 9 | + Dimensions, |
| 10 | + FlatList, |
9 | 11 | StyleSheet, |
10 | | - Text, |
11 | 12 | View, |
12 | 13 | } from 'react-native'; |
| 14 | +import NoteWidget from './Widgets/NoteWidget'; |
| 15 | + |
| 16 | +const window = Dimensions.get("window"); |
| 17 | +const screen = Dimensions.get("screen"); |
| 18 | + |
| 19 | +const noteWidgetWidth = 300; |
13 | 20 |
|
14 | 21 |
|
15 | 22 | class NotesMainPanel extends React.Component { |
| 23 | + constructor(props) { |
| 24 | + super(props); |
| 25 | + this.state = { |
| 26 | + notes: [{key: "1"}, {key: "2"}, {key: "3"}, {key: "4"}, {key: "5"}, {key: "6"}, {key: "7"}, {key: "8"}, {key: "9"}], |
| 27 | + dimensions: {window, screen}, |
| 28 | + columns: this.calculateColumnWidth(window), |
| 29 | + } |
| 30 | + }; |
| 31 | + |
| 32 | + calculateColumnWidth = (window) => { |
| 33 | + return Math.floor(window.width / noteWidgetWidth); |
| 34 | + }; |
| 35 | + |
| 36 | + onChange = ({ window, screen }) => { |
| 37 | + this.setState({ dimensions: { window, screen }, columns: this.calculateColumnWidth(window) }); |
| 38 | + }; |
| 39 | + |
| 40 | + componentDidMount() { |
| 41 | + Dimensions.addEventListener("change", this.onChange); |
| 42 | + }; |
| 43 | + |
| 44 | + componentWillUnmount() { |
| 45 | + Dimensions.removeEventListener("change", this.onChange); |
| 46 | + }; |
| 47 | + |
| 48 | + renderNote = notes => { |
| 49 | + return <NoteWidget width={noteWidgetWidth} ID={notes.item.key}/> |
| 50 | + }; |
16 | 51 |
|
17 | 52 | render() { |
18 | 53 | return( |
19 | | - <View> |
20 | | - <Text>NotesMainPanel</Text> |
| 54 | + <View style={styles.mainContainer}> |
| 55 | + <FlatList numColumns={this.state.columns} key={this.state.columns} data={this.state.notes} renderItem={this.renderNote}/> |
21 | 56 | </View> |
22 | 57 | ); |
23 | 58 | } |
24 | 59 | }; |
25 | 60 |
|
26 | 61 |
|
27 | 62 | const styles = StyleSheet.create({ |
| 63 | + mainContainer: { |
| 64 | + flex: 1, |
| 65 | + flexDirection: "column", |
| 66 | + margin: 20, |
| 67 | + backgroundColor: "transparent", |
| 68 | + }, |
28 | 69 | }); |
29 | 70 |
|
30 | 71 |
|
|
0 commit comments