Browse Source

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

Janic Duplessis 5 years ago
parent
commit
eb234c8db3
1 changed files with 6 additions and 0 deletions
  1. 6
    0
      ios/SafeAreaView/RNCSafeAreaView.m

+ 6
- 0
ios/SafeAreaView/RNCSafeAreaView.m View File

68
 
68
 
69
 - (void)invalidateSafeAreaInsets
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
   UIEdgeInsets safeAreaInsets = [self realOrEmulateSafeAreaInsets];
77
   UIEdgeInsets safeAreaInsets = [self realOrEmulateSafeAreaInsets];
72
 
78
 
73
   if (_initialInsetsSent && UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
79
   if (_initialInsetsSent && UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {