-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixed library list rendering way in a single map func using absolute pos #33
Open
ochanje210
wants to merge
3
commits into
master
Choose a base branch
from
sort
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,19 @@ import { | |
Text, | ||
TouchableOpacity, | ||
View, | ||
Image | ||
Image, | ||
PanResponder, | ||
LayoutAnimation | ||
} from 'react-native'; | ||
import { Actions } from 'react-native-router-flux'; | ||
import Styles from './styles'; | ||
import Styles, { HEIGHT, WIDTH } from './styles'; | ||
import Footer from '../../footer'; | ||
|
||
const COLUMN_CONSTANT = { | ||
LEFT: 'left', | ||
RIGHT: 'right' | ||
}; | ||
|
||
const HEIGHT = Dimensions.get('window').height; | ||
|
||
const generateRandomColor = () => { | ||
// eslint-disable-next-line | ||
return '#' + (function co(lor){ return (lor += | ||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'a', 'b', 'c', 'd', 'e', 'f'][Math.floor(Math.random() * 16)]) | ||
&& (lor.length === 6) ? lor : co(lor); })(''); | ||
const compareLists = (a, b) => { | ||
if (a && b) { | ||
return (a.toString() !== b.toString()); | ||
} | ||
return (a || b); | ||
}; | ||
|
||
export default class LibraryView extends Component { | ||
|
@@ -33,23 +28,46 @@ export default class LibraryView extends Component { | |
this.state = { | ||
dataSource: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], | ||
onPressedBookIndex: undefined, | ||
onPressedColumn: undefined, | ||
initialBookColor: [], | ||
fadeAnimRow: new Animated.Value(0), | ||
offset: 0, | ||
direction: undefined | ||
direction: undefined, | ||
pan: new Animated.ValueXY() | ||
}; | ||
for (let i = 0; i < this.state.dataSource.length; i = i + 1) { | ||
this.state.initialBookColor.push(generateRandomColor()); | ||
} | ||
this.panResponder = PanResponder.create({ | ||
onStartShouldSetPanResponder: () => {console.log('touched');}, | ||
onPanResponderMove: Animated.event([null, { | ||
dx: this.state.pan.x, | ||
dy: this.state.pan.y | ||
}]), | ||
onPanResponderRelease : (e, gesture) => {} | ||
}); | ||
this.renderAbsoluteRow = this.renderAbsoluteRow.bind(this); | ||
} | ||
|
||
static propTypes = { | ||
user: PropTypes.object, | ||
libraryList: PropTypes.any, | ||
prevScene: PropTypes.string | ||
prevScene: PropTypes.string, | ||
coordinate: PropTypes.array, | ||
initialBookColor: PropTypes.array, | ||
sortRows: PropTypes.func | ||
}; | ||
|
||
shouldComponentUpdate(nextState) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is in order to optimize performance. Here is the ref FYI: https://facebook.github.io/react/docs/optimizing-performance.html#shouldcomponentupdate-in-action |
||
let { | ||
dataSource, | ||
direction, | ||
fadeAnimRow, | ||
offset | ||
} = this.state; | ||
return ( | ||
(fadeAnimRow !== nextState.fadeAnimRow) || | ||
(offset !== nextState.offset) || | ||
(direction !== nextState.direction) || | ||
(compareLists(dataSource, nextState.dataSource)) || | ||
(compareLists(refs, nextState.refs))); | ||
} | ||
|
||
animateFadeRow() { | ||
Animated.sequence([ | ||
Animated.timing( | ||
|
@@ -129,28 +147,76 @@ export default class LibraryView extends Component { | |
); | ||
} | ||
|
||
filterDataSourceUponColumn(start) { | ||
let dataSource = []; | ||
for (let i = start; i < this.props.libraryList.length; i = i + 2) { | ||
dataSource.push({data: this.props.libraryList[i], color: this.state.initialBookColor[i]}); | ||
} | ||
return dataSource; | ||
renderRowContent(node, i) { | ||
const { initialBookColor } = this.props; | ||
return ( | ||
<View style={[Styles.row, {backgroundColor: 'transparent'}]}> | ||
<TouchableOpacity | ||
style={Styles.row} | ||
onPress={this.handleOnPressBookTransition.bind(this)} | ||
onLongPress={this.handleOnLongPress.bind(this)} | ||
activeOpacity={0.8} | ||
> | ||
{(node.thumbnail) ? | ||
<Image | ||
source={{uri: node.thumbnail}} | ||
style={Styles.book} | ||
/> | ||
: | ||
<View style={[Styles.book, {backgroundColor: initialBookColor[i]}]}/> | ||
} | ||
<View style={Styles.textContainerTitle}> | ||
<Text style={Styles.textBookTitle}>BOOK{'\n'}Example #{i}</Text> | ||
<View style={Styles.snippetCountContainer}> | ||
<View style={Styles.snippetCountBox}> | ||
<Text style={Styles.textSnippetCount}>{i}</Text> | ||
</View> | ||
</View> | ||
</View> | ||
<View style={Styles.textContainerInfo}> | ||
<Text style={Styles.textBookInfo}>author: {i} bibbid vav sust reandsaf asdf lkdasdfas kds</Text> | ||
</View> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
} | ||
|
||
renderLeftColumn() { | ||
const leftDataSource = this.filterDataSourceUponColumn(0); | ||
renderAbsoluteRow(node, i) { | ||
const { coordinate } = this.props; | ||
return ( | ||
<View style={Styles.leftColumn}> | ||
{leftDataSource.map((t, i) => this.renderRow(t, i, COLUMN_CONSTANT.LEFT))} | ||
<View | ||
key={i} | ||
style={[{ | ||
top: coordinate[i].top, | ||
left: coordinate[i].left, | ||
height: HEIGHT * 0.477, | ||
width: WIDTH * 0.433, | ||
position: 'absolute', | ||
borderRadius: 7, | ||
zIndex: 10 | ||
}]}> | ||
{this.renderRowContent(node, i)} | ||
</View> | ||
); | ||
} | ||
|
||
renderRightColumn() { | ||
const rightDataSource = this.filterDataSourceUponColumn(1); | ||
handleOnLongPress() { | ||
this.props.sortRows(); | ||
} | ||
|
||
renderAbsoluteBoxes() { | ||
const { libraryList } = this.props; | ||
const height = HEIGHT * 0.477; | ||
return ( | ||
<View style={Styles.rightColumn}> | ||
{rightDataSource.map((t, i) => this.renderRow(t, i, COLUMN_CONSTANT.RIGHT))} | ||
<View | ||
style={{ | ||
width: WIDTH, | ||
height: (libraryList.length - 1) * height / 2 + height + HEIGHT * 0.096, | ||
marginLeft: WIDTH * 0.064, | ||
flexDirection: 'column' | ||
}} | ||
> | ||
{libraryList.map((content, index) => this.renderAbsoluteRow(content.node, index))} | ||
</View> | ||
); | ||
} | ||
|
@@ -172,9 +238,8 @@ export default class LibraryView extends Component { | |
onScroll={this.onScroll.bind(this)} | ||
style={{flex: 1, marginTop: HEIGHT * 0.11}} | ||
> | ||
<View style={Styles.container}> | ||
{this.renderLeftColumn()} | ||
{this.renderRightColumn()} | ||
<View style={Styles.myLibraryContainer}> | ||
{this.renderAbsoluteBoxes()} | ||
</View> | ||
</ScrollView> | ||
<Footer status={this.state.direction}/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this panresponder is not being used. I will either delete this or update it to use it