Skip to content

Commit f367c87

Browse files
committed
add Lazy Load capabilities like lazy load time and the option to render custom loader
1 parent 66ea305 commit f367c87

File tree

2 files changed

+29
-5
lines changed
  • demo/src/screens/incubatorScreens/TabControllerScreen
  • src/incubator/TabController

2 files changed

+29
-5
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, {Component} from 'react';
2+
import {ActivityIndicator} from 'react-native';
23
import {Incubator, Colors, View, Text, Image, Assets, Button} from 'react-native-ui-lib'; //eslint-disable-line
34
import _ from 'lodash';
45

@@ -71,6 +72,17 @@ class TabControllerScreen extends Component {
7172
// ];
7273
// }
7374

75+
renderLoadingPage() {
76+
return (
77+
<View flex center>
78+
<ActivityIndicator size="large"/>
79+
<Text text60L marginT-10>
80+
Loading
81+
</Text>
82+
</View>
83+
);
84+
}
85+
7486
renderTabPages() {
7587
const Container = USE_CAROUSEL ? Incubator.TabController.PageCarousel : View;
7688
const containerProps = USE_CAROUSEL ? {} : {flex: true};
@@ -82,7 +94,7 @@ class TabControllerScreen extends Component {
8294
<Incubator.TabController.TabPage index={1}>
8395
<Tab2/>
8496
</Incubator.TabController.TabPage>
85-
<Incubator.TabController.TabPage index={2} lazy>
97+
<Incubator.TabController.TabPage index={2} lazy lazyLoadTime={1500} renderLoading={this.renderLoadingPage}>
8698
<Tab3/>
8799
</Incubator.TabController.TabPage>
88100
{/* <Incubator.TabController.TabPage index={3}>

src/incubator/TabController/TabPage.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {PureComponent} from 'react';
22
import {StyleSheet} from 'react-native';
33
import PropTypes from 'prop-types';
44
import Reanimated from 'react-native-reanimated';
5+
import _ from 'lodash';
56
import TabBarContext from './TabBarContext';
67
import {Constants} from '../../helpers';
78

@@ -24,11 +25,21 @@ export default class TabPage extends PureComponent {
2425
/**
2526
* Whether this page should be loaded lazily
2627
*/
27-
lazy: PropTypes.bool
28+
lazy: PropTypes.bool,
29+
/**
30+
* How long to wait till lazy load complete (good for showing loader screens)
31+
*/
32+
lazyLoadTime: PropTypes.number,
33+
/**
34+
* Render a custom loading page when lazy loading
35+
*/
36+
renderLoading: PropTypes.func
2837
};
2938

3039
static defaultProps = {
31-
activeOpacity: 0.6
40+
activeOpacity: 0.6,
41+
lazyLoadTime: 300,
42+
renderLoading: _.noop
3243
};
3344

3445
state = {
@@ -49,16 +60,17 @@ export default class TabPage extends PureComponent {
4960
this.setState({
5061
loaded: true
5162
});
52-
}, 300); // tab bar indicator transition time
63+
}, this.props.lazyLoadTime); // tab bar indicator transition time
5364
};
5465

5566
render() {
5667
const {currentPage} = this.context;
57-
const {index, lazy, testID} = this.props;
68+
const {index, lazy, renderLoading, testID} = this.props;
5869
const {loaded} = this.state;
5970

6071
return (
6172
<Reanimated.View style={this._pageStyle} testID={testID}>
73+
{!loaded && renderLoading()}
6274
{loaded && this.props.children}
6375
<Code>
6476
{() => {

0 commit comments

Comments
 (0)