1
- import React , { Component } from 'react' ;
1
+ import React , { PureComponent } from 'react' ;
2
2
import { StyleSheet } from 'react-native' ;
3
3
import PropTypes from 'prop-types' ;
4
4
import Reanimated from 'react-native-reanimated' ;
5
5
import TabBarContext from './TabBarContext' ;
6
6
7
- const { cond, and, call, block, eq} = Reanimated ;
7
+ const { Code , Value , cond, set , and, call, block, eq} = Reanimated ;
8
8
9
9
/**
10
- * @description : TabController's TabPage
11
- * @example : https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/incubatorScreens/TabControllerScreen/index.js
12
- */
13
- export default class TabPage extends Component {
10
+ * @description : TabController's TabPage
11
+ * @example : https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/incubatorScreens/TabControllerScreen/index.js
12
+ */
13
+ export default class TabPage extends PureComponent {
14
14
static displayName = 'TabController.TabPage' ;
15
15
16
16
static contextType = TabBarContext ;
@@ -34,6 +34,10 @@ export default class TabPage extends Component {
34
34
loaded : ! this . props . lazy ,
35
35
} ;
36
36
37
+ _opacity = new Value ( 0 ) ;
38
+ _zIndex = new Value ( 0 ) ;
39
+ _pageStyle = [ styles . page , { opacity : this . _opacity } , { zIndex : this . _zIndex } ] ;
40
+
37
41
lazyLoad = ( ) => {
38
42
this . setState ( {
39
43
loaded : true ,
@@ -44,16 +48,22 @@ export default class TabPage extends Component {
44
48
const { currentPage} = this . context ;
45
49
const { index, lazy, testID} = this . props ;
46
50
const { loaded} = this . state ;
47
- const opacity = block ( [
48
- cond ( and ( eq ( currentPage , index ) , lazy , ! loaded ) , call ( [ ] , this . lazyLoad ) ) ,
49
- cond ( eq ( currentPage , index ) , 1 , 0 ) ,
50
- ] ) ;
51
-
52
- const zIndex = cond ( eq ( currentPage , index ) , 1 , 0 ) ;
53
51
54
52
return (
55
- < Reanimated . View style = { [ styles . page , { opacity } , { zIndex } ] } testID = { testID } >
53
+ < Reanimated . View style = { this . _pageStyle } testID = { testID } >
56
54
{ loaded && this . props . children }
55
+ < Code >
56
+ { ( ) => {
57
+ return block ( [
58
+ cond ( and ( eq ( currentPage , index ) , lazy , ! loaded ) , call ( [ ] , this . lazyLoad ) ) ,
59
+ cond (
60
+ eq ( currentPage , index ) ,
61
+ [ set ( this . _opacity , 1 ) , set ( this . _zIndex , 1 ) ] ,
62
+ [ set ( this . _opacity , 0 ) , set ( this . _zIndex , 0 ) ] ,
63
+ ) ,
64
+ ] ) ;
65
+ } }
66
+ </ Code >
57
67
</ Reanimated . View >
58
68
) ;
59
69
}
0 commit comments