Files
devhub/patches/react-native+0.57.7-hooks.1.patch

150 lines
4.5 KiB
Diff

patch-package
--- a/node_modules/react-native/scripts/react-native-xcode.sh
+++ b/node_modules/react-native/scripts/react-native-xcode.sh
@@ -47,7 +47,10 @@ cd "${REACT_NATIVE_DIR}"/../..
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"
# Define entry file
-if [[ -s "index.ios.js" ]]; then
+if [[ "$ENTRY_FILE" ]]; then
+ # Use ENTRY_FILE defined by user
+ :
+elif [[ -s "index.ios.js" ]]; then
ENTRY_FILE=${1:-index.ios.js}
else
ENTRY_FILE=${1:-index.js}
--- a/node_modules/react-native/React/Views/SafeAreaView/RCTSafeAreaView.h
+++ b/node_modules/react-native/React/Views/SafeAreaView/RCTSafeAreaView.h
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2015-present, Facebook, Inc.
+ * Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
@@ -17,6 +17,8 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)initWithBridge:(RCTBridge *)bridge;
+@property (nonatomic, assign) BOOL emulateUnlessSupported;
+
@end
NS_ASSUME_NONNULL_END
--- a/node_modules/react-native/React/Views/SafeAreaView/RCTSafeAreaView.m
+++ b/node_modules/react-native/React/Views/SafeAreaView/RCTSafeAreaView.m
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2015-present, Facebook, Inc.
+ * Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
@@ -21,6 +21,7 @@
{
if (self = [super initWithFrame:CGRectZero]) {
_bridge = bridge;
+ _emulateUnlessSupported = YES; // The default.
}
return self;
@@ -29,7 +30,45 @@
RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)decoder)
RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame)
+- (BOOL)isSupportedByOS
+{
+ return [self respondsToSelector:@selector(safeAreaInsets)];
+}
+
+- (UIEdgeInsets)safeAreaInsetsIfSupportedAndEnabled
+{
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
+ if (self.isSupportedByOS) {
+ return self.safeAreaInsets;
+ }
+#endif
+ return self.emulateUnlessSupported ? self.emulatedSafeAreaInsets : UIEdgeInsetsZero;
+}
+
+- (UIEdgeInsets)emulatedSafeAreaInsets
+{
+ UIViewController* vc = self.reactViewController;
+
+ if (!vc) {
+ return UIEdgeInsetsZero;
+ }
+
+ CGFloat topLayoutOffset = vc.topLayoutGuide.length;
+ CGFloat bottomLayoutOffset = vc.bottomLayoutGuide.length;
+ CGRect safeArea = vc.view.bounds;
+ safeArea.origin.y += topLayoutOffset;
+ safeArea.size.height -= topLayoutOffset + bottomLayoutOffset;
+ CGRect localSafeArea = [vc.view convertRect:safeArea toView:self];
+ UIEdgeInsets safeAreaInsets = UIEdgeInsetsMake(0, 0, 0, 0);
+ if (CGRectGetMinY(localSafeArea) > CGRectGetMinY(self.bounds)) {
+ safeAreaInsets.top = CGRectGetMinY(localSafeArea) - CGRectGetMinY(self.bounds);
+ }
+ if (CGRectGetMaxY(localSafeArea) < CGRectGetMaxY(self.bounds)) {
+ safeAreaInsets.bottom = CGRectGetMaxY(self.bounds) - CGRectGetMaxY(localSafeArea);
+ }
+
+ return safeAreaInsets;
+}
static BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIEdgeInsets insets2, CGFloat threshold) {
return
@@ -41,23 +80,44 @@ static BOOL UIEdgeInsetsEqualToEdgeInsetsWithThreshold(UIEdgeInsets insets1, UIE
- (void)safeAreaInsetsDidChange
{
- if (![self respondsToSelector:@selector(safeAreaInsets)]) {
- return;
- }
+ [self invalidateSafeAreaInsets];
+}
+
+- (void)invalidateSafeAreaInsets
+{
+ [self setSafeAreaInsets:self.safeAreaInsetsIfSupportedAndEnabled];
+}
- UIEdgeInsets safeAreaInsets = self.safeAreaInsets;
+- (void)layoutSubviews
+{
+ [super layoutSubviews];
+
+ if (!self.isSupportedByOS && self.emulateUnlessSupported) {
+ [self invalidateSafeAreaInsets];
+ }
+}
+- (void)setSafeAreaInsets:(UIEdgeInsets)safeAreaInsets
+{
if (UIEdgeInsetsEqualToEdgeInsetsWithThreshold(safeAreaInsets, _currentSafeAreaInsets, 1.0 / RCTScreenScale())) {
return;
}
_currentSafeAreaInsets = safeAreaInsets;
- RCTSafeAreaViewLocalData *localData =
- [[RCTSafeAreaViewLocalData alloc] initWithInsets:safeAreaInsets];
+ RCTSafeAreaViewLocalData *localData = [[RCTSafeAreaViewLocalData alloc] initWithInsets:safeAreaInsets];
[_bridge.uiManager setLocalData:localData forView:self];
}
-#endif
+- (void)setEmulateUnlessSupported:(BOOL)emulateUnlessSupported
+{
+ if (_emulateUnlessSupported == emulateUnlessSupported) {
+ return;
+ }
+
+ _emulateUnlessSupported = emulateUnlessSupported;
+
+ [self invalidateSafeAreaInsets];
+}
@end
\ No newline at end of file