Skip to content

Commit fe8a93d

Browse files
assertchrisjanicduplessis
authored andcommitted
Prevent null reference errors for lists (#6)
1 parent b8178d3 commit fe8a93d

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/MasonryList.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,35 @@ export default class MasonryList extends Component {
140140
}
141141

142142
_onLayout = event => {
143-
this._listRefs.forEach(list => list._onLayout(event));
143+
this._listRefs.forEach(
144+
list => list && list._onLayout && list._onLayout(event),
145+
);
144146
};
145147

146148
_onContentSizeChange = (width, height) => {
147-
this._listRefs.forEach(list => list._onContentSizeChange(width, height));
149+
this._listRefs.forEach(
150+
list =>
151+
list &&
152+
list._onContentSizeChange &&
153+
list._onContentSizeChange(width, height),
154+
);
148155
};
149156

150157
_onScroll = event => {
151158
if (this.props.onScroll) {
152159
this.props.onScroll(event);
153160
}
154-
this._listRefs.forEach(list => list._onScroll(event));
161+
this._listRefs.forEach(
162+
list => list && list._onScroll && list._onScroll(event),
163+
);
155164
};
156165

157166
_onScrollBeginDrag = event => {
158167
if (this.props.onScrollBeginDrag) {
159168
this.props.onScrollBeginDrag(event);
160169
}
161170
this._listRefs.forEach(
162-
list => list._onScrollBeginDrag && list._onScrollBeginDrag(event),
171+
list => list && list._onScrollBeginDrag && list._onScrollBeginDrag(event),
163172
);
164173
};
165174

@@ -168,7 +177,7 @@ export default class MasonryList extends Component {
168177
this.props.onScrollEndDrag(event);
169178
}
170179
this._listRefs.forEach(
171-
list => list._onScrollEndDrag && list._onScrollEndDrag(event),
180+
list => list && list._onScrollEndDrag && list._onScrollEndDrag(event),
172181
);
173182
};
174183

@@ -177,7 +186,8 @@ export default class MasonryList extends Component {
177186
this.props.onMomentumScrollEnd(event);
178187
}
179188
this._listRefs.forEach(
180-
list => list._onMomentumScrollEnd && list._onMomentumScrollEnd(event),
189+
list =>
190+
list && list._onMomentumScrollEnd && list._onMomentumScrollEnd(event),
181191
);
182192
};
183193

0 commit comments

Comments
 (0)