Skip to content

Commit

Permalink
Merge pull request #1 from tiberiumihai/fix-initial-page-for-tabs
Browse files Browse the repository at this point in the history
Fix initialPage for Tabs
  • Loading branch information
tiberiumihai authored Nov 17, 2017
2 parents cfcf28e + 8dda85e commit ca07659
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 22 deletions.
5 changes: 3 additions & 2 deletions dist/src/Utils/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/Utils/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions dist/src/Utils/interactionManager.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/src/Utils/interactionManager.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 8 additions & 11 deletions dist/src/basic/Tabs/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/basic/Tabs/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Utils/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ViewPropTypes from './viewPropTypes'
import InteractionManager from './interactionManager'

export { ViewPropTypes }
export { InteractionManager, ViewPropTypes }
15 changes: 15 additions & 0 deletions src/Utils/interactionManager.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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

0 comments on commit ca07659

Please sign in to comment.