@@ -17,6 +17,7 @@ @implementation RNCSafeAreaProviderComponentView {
17
17
UIEdgeInsets _currentSafeAreaInsets;
18
18
CGRect _currentFrame;
19
19
BOOL _initialInsetsSent;
20
+ BOOL _registeredNotifications;
20
21
}
21
22
22
23
// Needed because of this: https://github.com/facebook/react-native/pull/37274
@@ -30,7 +31,21 @@ - (instancetype)initWithFrame:(CGRect)frame
30
31
if (self = [super initWithFrame: frame]) {
31
32
static const auto defaultProps = std::make_shared<const RNCSafeAreaProviderProps>();
32
33
_props = defaultProps;
34
+ }
35
+
36
+ return self;
37
+ }
38
+
39
+ - (void )willMoveToSuperview : (UIView*)newSuperView {
40
+ [super willMoveToSuperview: newSuperView];
33
41
42
+ if (newSuperView != nil && !_registeredNotifications) {
43
+ _registeredNotifications = YES ;
44
+ [self registerNotifications ];
45
+ }
46
+ }
47
+
48
+ - (void )registerNotifications {
34
49
#if !TARGET_OS_TV && !TARGET_OS_OSX
35
50
[NSNotificationCenter .defaultCenter addObserver: self
36
51
selector: @selector (invalidateSafeAreaInsets )
@@ -45,9 +60,6 @@ - (instancetype)initWithFrame:(CGRect)frame
45
60
name: UIKeyboardDidChangeFrameNotification
46
61
object: nil ];
47
62
#endif
48
- }
49
-
50
- return self;
51
63
}
52
64
53
65
- (void )safeAreaInsetsDidChange
@@ -125,6 +137,7 @@ - (void)prepareForRecycle
125
137
_currentFrame = CGRectZero;
126
138
_initialInsetsSent = NO ;
127
139
[NSNotificationCenter .defaultCenter removeObserver: self ];
140
+ _registeredNotifications = NO ;
128
141
}
129
142
130
143
@end
0 commit comments