Skip to content
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

Fix initialPage for Tabs #1376

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Utils/index.js
@@ -1,3 +1,4 @@
import { ViewPropTypes } from "react-native";
import InteractionManager from './interactionManager'

export { ViewPropTypes };
export { InteractionManager, ViewPropTypes }
15 changes: 15 additions & 0 deletions src/Utils/interactionManager.js
@@ -0,0 +1,15 @@
import { InteractionManager } from "react-native";
export default {
...InteractionManager,
runAfterInteractions: f => {
// ensure f get called, timeout at 10ms
// @gre workaround https://github.com/facebook/react-native/issues/8624
let called = false;
const timeout = setTimeout(() => { called = true; f() }, 10);
InteractionManager.runAfterInteractions(() => {
if (called) return;
clearTimeout(timeout);
f();
});
}
};
9 changes: 3 additions & 6 deletions src/basic/Tabs/index.js
Expand Up @@ -9,10 +9,9 @@ const {
Animated,
ScrollView,
StyleSheet,
InteractionManager,
Platform,
} = ReactNative;
import { ViewPropTypes } from "../../Utils";
import { InteractionManager, ViewPropTypes } from "../../Utils";
const TimerMixin = require("react-timer-mixin");
import _ from "lodash";

Expand Down Expand Up @@ -66,14 +65,12 @@ const ScrollableTabView = createReactClass({

componentDidMount() {
const scrollFn = () => {
if (this.scrollView && Platform.OS === "android") {
if (this.scrollView) {
const x = this.props.initialPage * this.state.containerWidth;
this.scrollView.scrollTo({ x, animated: false });
}
};
this.setTimeout(() => {
InteractionManager.runAfterInteractions(scrollFn);
}, 0);
InteractionManager.runAfterInteractions(scrollFn);
},

componentWillReceiveProps(props) {
Expand Down