Skip to content

Commit b9135b1

Browse files
committed
improve tab controller transition performance when moving to a "heavy" tab page
1 parent 090fa21 commit b9135b1

File tree

2 files changed

+12
-6
lines changed
  • demo/src/screens/incubatorScreens/TabControllerScreen
  • src/incubator/TabController

2 files changed

+12
-6
lines changed

demo/src/screens/incubatorScreens/TabControllerScreen/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ class TabControllerScreen extends Component {
7979
<Incubator.TabController.TabPage index={0}>
8080
<Tab1/>
8181
</Incubator.TabController.TabPage>
82-
<Incubator.TabController.TabPage index={1} lazy={!USE_CAROUSEL}>
82+
<Incubator.TabController.TabPage index={1}>
8383
<Tab2/>
8484
</Incubator.TabController.TabPage>
85-
<Incubator.TabController.TabPage index={2}>
85+
<Incubator.TabController.TabPage index={2} lazy>
8686
<Tab3/>
8787
</Incubator.TabController.TabPage>
8888
{/* <Incubator.TabController.TabPage index={3}>

src/incubator/TabController/TabPage.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default class TabPage extends PureComponent {
3535
loaded: !this.props.lazy
3636
};
3737

38+
_loaded = new Value(Number(!this.props.lazy));
3839
_opacity = new Value(0);
3940
_zIndex = new Value(0);
4041
_pageStyle = [
@@ -44,9 +45,11 @@ export default class TabPage extends PureComponent {
4445
];
4546

4647
lazyLoad = () => {
47-
this.setState({
48-
loaded: true
49-
});
48+
setTimeout(() => {
49+
this.setState({
50+
loaded: true
51+
});
52+
}, 300); // tab bar indicator transition time
5053
};
5154

5255
render() {
@@ -60,7 +63,10 @@ export default class TabPage extends PureComponent {
6063
<Code>
6164
{() => {
6265
return block([
63-
cond(and(eq(currentPage, index), lazy, !loaded), call([], this.lazyLoad)),
66+
cond(and(eq(currentPage, index), lazy, eq(this._loaded, 0)), [
67+
set(this._loaded, 1),
68+
call([], this.lazyLoad)
69+
]),
6470
cond(eq(currentPage, index),
6571
[set(this._opacity, 1), set(this._zIndex, 1)],
6672
[set(this._opacity, 0), set(this._zIndex, 0)])

0 commit comments

Comments
 (0)