Просмотр исходного кода

Avoid sending wrong insets because rn hasn't set view size yet

Janic Duplessis 4 лет назад
Родитель
Сommit
eb234c8db3
1 измененных файлов: 6 добавлений и 0 удалений
  1. 6
    0
      ios/SafeAreaView/RNCSafeAreaView.m

+ 6
- 0
ios/SafeAreaView/RNCSafeAreaView.m Просмотреть файл

@@ -68,6 +68,12 @@ static BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIE
68 68
 
69 69
 - (void)invalidateSafeAreaInsets
70 70
 {
71
+  // This gets called before the view size is set by react-native so
72
+  // make sure to wait so we don't set wrong insets to JS.
73
+  if (CGSizeEqualToSize(self.frame.size, CGSizeZero)) {
74
+    return;
75
+  }
76
+
71 77
   UIEdgeInsets safeAreaInsets = [self realOrEmulateSafeAreaInsets];
72 78
 
73 79
   if (_initialInsetsSent && UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {