@@ -51,6 +51,14 @@ class LazyLoadImage extends React.Component {
51
51
return false ;
52
52
}
53
53
54
+ componentDidUpdate ( prevProps , prevState ) {
55
+ if ( ! prevState . visible && this . state . visible ) {
56
+ this . props . afterLoad ( ) ;
57
+ }
58
+
59
+ this . updateVisibility ( ) ;
60
+ }
61
+
54
62
getPlaceholderBoundingBox ( scrollPosition = this . props . scrollPosition ) {
55
63
const boundingRect = this . placeholder . getBoundingClientRect ( ) ;
56
64
const style = ReactDOM . findDOMNode ( this . placeholder ) . style ;
@@ -67,30 +75,6 @@ class LazyLoadImage extends React.Component {
67
75
} ;
68
76
}
69
77
70
- componentDidUpdate ( prevProps , prevState ) {
71
- if ( ! prevState . visible && this . state . visible ) {
72
- this . props . afterLoad ( ) ;
73
- }
74
-
75
- this . updateVisibility ( ) ;
76
- }
77
-
78
- updateVisibility ( ) {
79
- if ( this . state . visible ) {
80
- return ;
81
- }
82
-
83
- if ( ! this . isImageInViewport ( ) ) {
84
- return ;
85
- }
86
-
87
- this . props . beforeLoad ( ) ;
88
-
89
- this . setState ( {
90
- visible : true
91
- } ) ;
92
- }
93
-
94
78
isImageInViewport ( ) {
95
79
if ( ! this . placeholder ) {
96
80
return false ;
@@ -111,6 +95,18 @@ class LazyLoadImage extends React.Component {
111
95
viewport . right + threshold >= boundingBox . left ) ;
112
96
}
113
97
98
+ updateVisibility ( ) {
99
+ if ( this . state . visible || ! this . isImageInViewport ( ) ) {
100
+ return ;
101
+ }
102
+
103
+ this . props . beforeLoad ( ) ;
104
+
105
+ this . setState ( {
106
+ visible : true
107
+ } ) ;
108
+ }
109
+
114
110
getPlaceholder ( ) {
115
111
const { className, height, placeholder, style, width } = this . props ;
116
112
0 commit comments