-
Notifications
You must be signed in to change notification settings - Fork 2.3k
setTimeout() instead of InteractionManager #534
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 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
Next
Next commit
setTimeout() instead of InteractionManager
In componentDidMount() of index.js, using a timeout resolves a problem with scrollView.scrollTo() not working
- Loading branch information
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 |
|---|---|---|
|
|
@@ -21,14 +21,14 @@ const ScrollableTabBar = require('./ScrollableTabBar'); | |
|
|
||
|
|
||
| const ScrollableTabView = React.createClass({ | ||
| mixins: [TimerMixin, ], | ||
| mixins: [TimerMixin,], | ||
| statics: { | ||
| DefaultTabBar, | ||
| ScrollableTabBar, | ||
| }, | ||
|
|
||
| propTypes: { | ||
| tabBarPosition: PropTypes.oneOf(['top', 'bottom', 'overlayTop', 'overlayBottom', ]), | ||
| tabBarPosition: PropTypes.oneOf(['top', 'bottom', 'overlayTop', 'overlayBottom',]), | ||
| initialPage: PropTypes.number, | ||
| page: PropTypes.number, | ||
| onChangeTab: PropTypes.func, | ||
|
|
@@ -46,8 +46,8 @@ const ScrollableTabView = React.createClass({ | |
| tabBarPosition: 'top', | ||
| initialPage: 0, | ||
| page: -1, | ||
| onChangeTab: () => {}, | ||
| onScroll: () => {}, | ||
| onChangeTab: () => { }, | ||
| onScroll: () => { }, | ||
| contentProps: {}, | ||
| scrollWithoutAnimation: false, | ||
| locked: false, | ||
|
|
@@ -65,12 +65,14 @@ const ScrollableTabView = React.createClass({ | |
| }, | ||
|
|
||
| componentDidMount() { | ||
| InteractionManager.runAfterInteractions(() => { | ||
| //InteractionManager.runAfterInteractions(() => { | ||
| setTimeout(() => { | ||
| if (this.scrollView && Platform.OS === 'android') { | ||
| console.log("Scrolling to " + this.props.initialPage + " with containerWidth " + this.state.containerWidth); | ||
|
||
| const x = this.props.initialPage * this.state.containerWidth; | ||
| this.scrollView.scrollTo({ x, animated: false }); | ||
| } | ||
| }); | ||
| }, 0); | ||
| }, | ||
|
|
||
| componentWillReceiveProps(props) { | ||
|
|
@@ -86,7 +88,7 @@ const ScrollableTabView = React.createClass({ | |
| goToPage(pageNumber) { | ||
| const offset = pageNumber * this.state.containerWidth; | ||
| if (this.scrollView) { | ||
| this.scrollView.scrollTo({x: offset, y: 0, animated: !this.props.scrollWithoutAnimation, }); | ||
| this.scrollView.scrollTo({ x: offset, y: 0, animated: !this.props.scrollWithoutAnimation, }); | ||
| } | ||
|
|
||
| const currentPage = this.state.currentPage; | ||
|
|
@@ -106,9 +108,9 @@ const ScrollableTabView = React.createClass({ | |
| } | ||
| }, | ||
|
|
||
| updateSceneKeys({ page, children = this.props.children, callback = () => {}, }) { | ||
| updateSceneKeys({ page, children = this.props.children, callback = () => { }, }) { | ||
| let newKeys = this.newSceneKeys({ previousKeys: this.state.sceneKeys, currentPage: page, children, }); | ||
| this.setState({currentPage: page, sceneKeys: newKeys, }, callback); | ||
| this.setState({ currentPage: page, sceneKeys: newKeys, }, callback); | ||
| }, | ||
|
|
||
| newSceneKeys({ previousKeys = [], currentPage = 0, children = this.props.children, }) { | ||
|
|
@@ -144,11 +146,11 @@ const ScrollableTabView = React.createClass({ | |
| pagingEnabled | ||
| automaticallyAdjustContentInsets={false} | ||
| contentOffset={{ x: this.props.initialPage * this.state.containerWidth, }} | ||
| ref={(scrollView) => { this.scrollView = scrollView; }} | ||
| ref={(scrollView) => { this.scrollView = scrollView; } } | ||
| onScroll={(e) => { | ||
| const offsetX = e.nativeEvent.contentOffset.x; | ||
| this._updateScrollValue(offsetX / this.state.containerWidth); | ||
| }} | ||
| } } | ||
| onMomentumScrollBegin={this._onMomentumScrollBeginAndEnd} | ||
| onMomentumScrollEnd={this._onMomentumScrollBeginAndEnd} | ||
| scrollEventThrottle={16} | ||
|
|
@@ -170,9 +172,9 @@ const ScrollableTabView = React.createClass({ | |
| return <SceneComponent | ||
| key={child.key} | ||
| shouldUpdated={this._shouldRenderSceneKey(idx, this.state.currentPage)} | ||
| style={{width: this.state.containerWidth, }} | ||
| > | ||
| {this._keyExists(this.state.sceneKeys, key) ? child : <View tabLabel={child.props.tabLabel}/>} | ||
| style={{ width: this.state.containerWidth, }} | ||
| > | ||
| {this._keyExists(this.state.sceneKeys, key) ? child : <View tabLabel={child.props.tabLabel} />} | ||
| </SceneComponent>; | ||
| }); | ||
| }, | ||
|
|
@@ -260,7 +262,7 @@ const ScrollableTabView = React.createClass({ | |
| }; | ||
| } | ||
|
|
||
| return <View style={[styles.container, this.props.style, ]} onLayout={this._handleLayout}> | ||
| return <View style={[styles.container, this.props.style,]} onLayout={this._handleLayout}> | ||
| {this.props.tabBarPosition === 'top' && this.renderTabBar(tabBarProps)} | ||
| {this.renderScrollableContent()} | ||
| {(this.props.tabBarPosition === 'bottom' || overlayTabs) && this.renderTabBar(tabBarProps)} | ||
|
|
||
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.
Use this.setTimeout like in documentation