-
Notifications
You must be signed in to change notification settings - Fork 44
update layout on orientation change #2
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
Open
acerbetti
wants to merge
3
commits into
goshacmd:master
Choose a base branch
from
acerbetti:master
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
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 hidden or 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 |
|---|---|---|
|
|
@@ -5,18 +5,38 @@ import tinycolor from 'tinycolor2'; | |
| import PageData from './components/PageData'; | ||
| import Paginator from './components/Paginator'; | ||
|
|
||
| var { height, width } = Dimensions.get('window'); | ||
|
|
||
| export default class Onboarding extends Component { | ||
| constructor() { | ||
| super(); | ||
|
|
||
| this.state = { | ||
| currentPage: 0, | ||
| layout:{ | ||
|
Owner
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. Styling nitpick: please add a space after the colon :) |
||
| height: height, | ||
| width: width, | ||
|
Owner
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. Both of these can use the ES6 shorthand syntax: layout: {
height,
width,
} |
||
| } | ||
| }; | ||
| } | ||
|
|
||
| onLayout = (event) => { | ||
| this.setState({ | ||
| layout: { | ||
| height: event.nativeEvent.layout.height, | ||
| width: event.nativeEvent.layout.width, | ||
| } | ||
| }); | ||
|
|
||
| // adjust the scrolling | ||
| const { currentPage } = this.state; | ||
| const offsetX = currentPage * event.nativeEvent.layout.width; | ||
| this.refs.scroll.scrollTo({ x: offsetX, animated: false }); | ||
| }; | ||
|
|
||
| updatePosition = (event) => { | ||
| const { contentOffset, layoutMeasurement } = event.nativeEvent; | ||
| const pageFraction = contentOffset.x / layoutMeasurement.width; | ||
| const { contentOffset } = event.nativeEvent; | ||
| const pageFraction = contentOffset.x / this.state.layout.width; | ||
| const page = Math.round(pageFraction); | ||
| const isLastPage = this.props.pages.length === page + 1; | ||
| if (isLastPage && pageFraction - page > 0.3) { | ||
|
|
@@ -27,23 +47,21 @@ export default class Onboarding extends Component { | |
| }; | ||
|
|
||
| goNext = () => { | ||
| const { width } = Dimensions.get('window'); | ||
| const { currentPage } = this.state; | ||
| const nextPage = currentPage + 1; | ||
| const offsetX = nextPage * width; | ||
| const offsetX = nextPage * this.state.layout.width; | ||
| this.refs.scroll.scrollTo({ x: offsetX, animated: true }); | ||
| this.setState({ currentPage: nextPage }); | ||
| }; | ||
|
|
||
| render() { | ||
| const { width, height } = Dimensions.get('window'); | ||
| const { pages, bottomOverlay, showSkip, showNext, showDone } = this.props; | ||
| const currentPage = pages[this.state.currentPage] || pages[0]; | ||
| const { backgroundColor } = currentPage; | ||
| const isLight = tinycolor(backgroundColor).getBrightness() > 180; | ||
|
|
||
| return ( | ||
| <View style={{ flex: 1, backgroundColor: backgroundColor, justifyContent: 'center' }}> | ||
| <View style={{ flex: 1, backgroundColor: backgroundColor, justifyContent: 'center' }} onLayout={this.onLayout}> | ||
| <ScrollView | ||
| ref="scroll" | ||
| pagingEnabled={true} | ||
|
|
@@ -59,8 +77,8 @@ export default class Onboarding extends Component { | |
| image={image} | ||
| title={title} | ||
| subtitle={subtitle} | ||
| width={width} | ||
| height={height} | ||
| width={this.state.layout.width} | ||
| height={this.state.layout.height} | ||
| /> | ||
| ))} | ||
| </ScrollView> | ||
|
|
||
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.
Minor nitpick: can you switch to
constplease?