ソースを参照

Back-port insets fix to v1

Leo Natan 7 年 前
コミット
485623074f
No account linked to committer's email address
共有5 個のファイルを変更した77 個の追加17 個の削除を含む
  1. 6
    0
      ios/RCCManagerModule.m
  2. 0
    16
      ios/RCCViewController.m
  3. 15
    0
      ios/RNNSwizzles.h
  4. 49
    0
      ios/RNNSwizzles.m
  5. 7
    1
      ios/ReactNativeNavigation.xcodeproj/project.pbxproj

+ 6
- 0
ios/RCCManagerModule.m ファイルの表示

@@ -10,6 +10,7 @@
10 10
 #import "RCCTheSideBarManagerViewController.h"
11 11
 #import "RCCNotification.h"
12 12
 #import "RCTHelpers.h"
13
+#import "RNNSwizzles.h"
13 14
 
14 15
 #define kSlideDownAnimationDuration 0.35
15 16
 
@@ -241,6 +242,11 @@ RCT_EXPORT_METHOD(
241 242
     NSDictionary *appStyle = layout[@"props"][@"appStyle"];
242 243
     if (appStyle) {
243 244
         [[RCCManager sharedIntance] setAppStyle:appStyle];
245
+		
246
+		if([appStyle[@"autoAdjustScrollViewInsets"] boolValue] == YES)
247
+		{
248
+			[RNNSwizzles applySwizzles];
249
+		}
244 250
     }
245 251
     
246 252
     // create the new controller

+ 0
- 16
ios/RCCViewController.m ファイルの表示

@@ -291,21 +291,6 @@ const NSInteger TRANSPARENT_NAVBAR_TAG = 78264803;
291 291
   }];
292 292
 }
293 293
 
294
-// fix iOS11 safeArea - https://github.com/facebook/react-native/issues/15681
295
-// rnn issue - https://github.com/wix/react-native-navigation/issues/1858
296
-- (void)_traverseAndFixScrollViewSafeArea:(UIView *)view {
297
-#ifdef __IPHONE_11_0
298
-  if ([view isKindOfClass:UIScrollView.class] && [view respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
299
-    [((UIScrollView*)view) setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
300
-  }
301
-  
302
-  [view.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
303
-    [self _traverseAndFixScrollViewSafeArea:obj];
304
-  }];
305
-#endif
306
-  
307
-}
308
-
309 294
 - (void)viewDidAppear:(BOOL)animated
310 295
 {
311 296
   [super viewDidAppear:animated];
@@ -317,7 +302,6 @@ const NSInteger TRANSPARENT_NAVBAR_TAG = 78264803;
317 302
 - (void)viewWillAppear:(BOOL)animated
318 303
 {
319 304
   [super viewWillAppear:animated];
320
-  [self _traverseAndFixScrollViewSafeArea:self.view];
321 305
   [self sendGlobalScreenEvent:@"willAppear" endTimestampString:[self getTimestampString] shouldReset:NO];
322 306
   [self sendScreenChangedEvent:@"willAppear"];
323 307
   [self setStyleOnAppear];

+ 15
- 0
ios/RNNSwizzles.h ファイルの表示

@@ -0,0 +1,15 @@
1
+//
2
+//  RNNSwizzles.h
3
+//  ReactNativeNavigation
4
+//
5
+//  Created by Leo Natan (Wix) on 1/17/18.
6
+//  Copyright © 2018 artal. All rights reserved.
7
+//
8
+
9
+#import <Foundation/Foundation.h>
10
+
11
+@interface RNNSwizzles : NSObject
12
+
13
++ (void)applySwizzles;
14
+
15
+@end

+ 49
- 0
ios/RNNSwizzles.m ファイルの表示

@@ -0,0 +1,49 @@
1
+//
2
+//  RNNSwizzles.m
3
+//  ReactNativeNavigation
4
+//
5
+//  Created by Leo Natan (Wix) on 1/17/18.
6
+//  Copyright © 2018 artal. All rights reserved.
7
+//
8
+
9
+#import "RNNSwizzles.h"
10
+@import ObjectiveC;
11
+@import UIKit;
12
+
13
+static id (*__SWZ_initWithEventDispatcher_orig)(id self, SEL _cmd, id eventDispatcher);
14
+
15
+@implementation RNNSwizzles
16
+
17
+- (id)__swz_initWithEventDispatcher:(id)eventDispatcher
18
+{
19
+	id returnValue = __SWZ_initWithEventDispatcher_orig(self, _cmd, eventDispatcher);
20
+	
21
+	if (@available(iOS 11.0, *)) {
22
+		[(UIScrollView*)[returnValue valueForKey:@"scrollView"] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic];
23
+	}
24
+	
25
+	return returnValue;
26
+}
27
+
28
++ (void)applySwizzles
29
+{
30
+#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0
31
+	Class cls = NSClassFromString(@"RCTScrollView");
32
+	if(cls == NULL)
33
+	{
34
+		return;
35
+	}
36
+	Method m1 = class_getInstanceMethod(cls, NSSelectorFromString(@"initWithEventDispatcher:"));
37
+	
38
+	if(m1 == NULL)
39
+	{
40
+		return;
41
+	}
42
+	
43
+	__SWZ_initWithEventDispatcher_orig = (void*)method_getImplementation(m1);
44
+	Method m2 = class_getInstanceMethod([RNNSwizzles class], NSSelectorFromString(@"__swz_initWithEventDispatcher:"));
45
+	method_exchangeImplementations(m1, m2);
46
+}
47
+#endif
48
+
49
+@end

+ 7
- 1
ios/ReactNativeNavigation.xcodeproj/project.pbxproj ファイルの表示

@@ -13,6 +13,7 @@
13 13
 		26AFF3F51D7EEE2400CBA211 /* RCCTitleViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 26AFF3F41D7EEE2400CBA211 /* RCCTitleViewHelper.m */; };
14 14
 		2DCD499A1F33AAC30035123A /* RCCCustomBarButtonItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DCD49981F33AAC30035123A /* RCCCustomBarButtonItem.m */; };
15 15
 		2DDE72091FB27E730017290C /* RCTConvert+UIBarButtonSystemItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 2DDE72071FB27E720017290C /* RCTConvert+UIBarButtonSystemItem.m */; };
16
+		390AD487200F566100A8250D /* RNNSwizzles.m in Sources */ = {isa = PBXBuildFile; fileRef = 390AD486200F566100A8250D /* RNNSwizzles.m */; };
16 17
 		CC84A19E1C1A0C4E00B3A6A2 /* RCCManager.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */; };
17 18
 		CC84A19F1C1A0C4E00B3A6A2 /* RCCManagerModule.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1961C1A0C4E00B3A6A2 /* RCCManagerModule.m */; };
18 19
 		CC84A1A01C1A0C4E00B3A6A2 /* RCCNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = CC84A1981C1A0C4E00B3A6A2 /* RCCNavigationController.m */; };
@@ -64,6 +65,8 @@
64 65
 		2DCD49991F33AAC30035123A /* RCCCustomBarButtonItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCCustomBarButtonItem.h; sourceTree = "<group>"; };
65 66
 		2DDE72071FB27E720017290C /* RCTConvert+UIBarButtonSystemItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+UIBarButtonSystemItem.m"; sourceTree = "<group>"; };
66 67
 		2DDE72081FB27E730017290C /* RCTConvert+UIBarButtonSystemItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+UIBarButtonSystemItem.h"; sourceTree = "<group>"; };
68
+		390AD485200F566100A8250D /* RNNSwizzles.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSwizzles.h; sourceTree = "<group>"; };
69
+		390AD486200F566100A8250D /* RNNSwizzles.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSwizzles.m; sourceTree = "<group>"; };
67 70
 		CC84A1931C1A0C4E00B3A6A2 /* RCCManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManager.h; sourceTree = "<group>"; };
68 71
 		CC84A1941C1A0C4E00B3A6A2 /* RCCManager.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = RCCManager.m; sourceTree = "<group>"; tabWidth = 2; };
69 72
 		CC84A1951C1A0C4E00B3A6A2 /* RCCManagerModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCManagerModule.h; sourceTree = "<group>"; };
@@ -73,7 +76,7 @@
73 76
 		CC84A1991C1A0C4E00B3A6A2 /* RCCTabBarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCTabBarController.h; sourceTree = "<group>"; };
74 77
 		CC84A19A1C1A0C4E00B3A6A2 /* RCCTabBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = RCCTabBarController.m; sourceTree = "<group>"; tabWidth = 2; };
75 78
 		CC84A19B1C1A0C4E00B3A6A2 /* RCCViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCViewController.h; sourceTree = "<group>"; };
76
-		CC84A19C1C1A0C4E00B3A6A2 /* RCCViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = RCCViewController.m; sourceTree = "<group>"; tabWidth = 2; };
79
+		CC84A19C1C1A0C4E00B3A6A2 /* RCCViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = RCCViewController.m; sourceTree = "<group>"; tabWidth = 4; };
77 80
 		D800E8171CFED1DB004A187F /* RCCExternalViewControllerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCExternalViewControllerProtocol.h; sourceTree = "<group>"; };
78 81
 		D83514F41D29719A00D53758 /* RCCNotification.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCCNotification.h; sourceTree = "<group>"; };
79 82
 		D83514F51D29719A00D53758 /* RCCNotification.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCCNotification.m; sourceTree = "<group>"; };
@@ -229,6 +232,8 @@
229 232
 				D800E8171CFED1DB004A187F /* RCCExternalViewControllerProtocol.h */,
230 233
 				D83514F41D29719A00D53758 /* RCCNotification.h */,
231 234
 				D83514F51D29719A00D53758 /* RCCNotification.m */,
235
+				390AD485200F566100A8250D /* RNNSwizzles.h */,
236
+				390AD486200F566100A8250D /* RNNSwizzles.m */,
232 237
 				D8AFADBE1BEE6F3F00A4592D /* Products */,
233 238
 			);
234 239
 			sourceTree = "<group>";
@@ -316,6 +321,7 @@
316 321
 				2DCD499A1F33AAC30035123A /* RCCCustomBarButtonItem.m in Sources */,
317 322
 				D83514F61D29719A00D53758 /* RCCNotification.m in Sources */,
318 323
 				CC84A19F1C1A0C4E00B3A6A2 /* RCCManagerModule.m in Sources */,
324
+				390AD487200F566100A8250D /* RNNSwizzles.m in Sources */,
319 325
 				26AFF3F51D7EEE2400CBA211 /* RCCTitleViewHelper.m in Sources */,
320 326
 				D8D779981D04B7180050CFEA /* RCTHelpers.m in Sources */,
321 327
 				D85082E81CBCF54200FDB961 /* SidebarLuvocracyAnimation.m in Sources */,