fix: iOS crash on iOS 14 when onLayout is called without a nativeView

This commit is contained in:
Martin Guillon
2021-08-02 15:01:20 +02:00
parent ba773c78ae
commit ae193189ae

View File

@ -165,7 +165,7 @@ export class ScrollView extends ScrollViewBase {
const nativeView = this.nativeViewProtected; const nativeView = this.nativeViewProtected;
if (majorVersion > 10) { if (nativeView && majorVersion > 10) {
// Disable automatic adjustment of scroll view insets // Disable automatic adjustment of scroll view insets
// Consider exposing this as property with all 4 modes // Consider exposing this as property with all 4 modes
// https://developer.apple.com/documentation/uikit/uiscrollview/contentinsetadjustmentbehavior // https://developer.apple.com/documentation/uikit/uiscrollview/contentinsetadjustmentbehavior
@ -182,7 +182,10 @@ export class ScrollView extends ScrollViewBase {
height = Math.max(this._contentMeasuredHeight, height); height = Math.max(this._contentMeasuredHeight, height);
} }
nativeView.contentSize = CGSizeMake(layout.toDeviceIndependentPixels(scrollWidth), layout.toDeviceIndependentPixels(scrollHeight)); if (nativeView) {
nativeView.contentSize = CGSizeMake(layout.toDeviceIndependentPixels(scrollWidth), layout.toDeviceIndependentPixels(scrollHeight));
}
View.layoutChild(this, this.layoutView, insets.left, insets.top, insets.left + width, insets.top + height); View.layoutChild(this, this.layoutView, insets.left, insets.top, insets.left + width, insets.top + height);
} }