Bläddra i källkod

Update swizzles for RN scrollview

Leo Natan 6 år sedan
förälder
incheckning
d878a01e8c
No account linked to committer's email address
1 ändrade filer med 42 tillägg och 0 borttagningar
  1. 42
    0
      lib/ios/RNNSwizzles.m

+ 42
- 0
lib/ios/RNNSwizzles.m Visa fil

@@ -11,6 +11,36 @@
11 11
 @import UIKit;
12 12
 
13 13
 static id (*__SWZ_initWithEventDispatcher_orig)(id self, SEL _cmd, id eventDispatcher);
14
+static void (*__SWZ_setFrame_orig)(id self, SEL _cmd, CGRect frame);
15
+
16
+static void __RNN_setFrame_orig(UIScrollView* self, SEL _cmd, CGRect frame)
17
+{
18
+	CGPoint originalOffset = self.contentOffset;
19
+	
20
+	__SWZ_setFrame_orig(self, _cmd, frame);
21
+	
22
+	UIEdgeInsets contentInset;
23
+	if (@available(iOS 11.0, *)) {
24
+		contentInset = self.adjustedContentInset;
25
+	} else {
26
+		contentInset = self.contentInset;
27
+	}
28
+	
29
+	CGSize contentSize = self.contentSize;
30
+	
31
+	// If contentSize has not been measured yet we can't check bounds.
32
+	if (CGSizeEqualToSize(contentSize, CGSizeZero))
33
+	{
34
+		self.contentOffset = originalOffset;
35
+	}
36
+	else
37
+	{
38
+		// Make sure offset don't exceed bounds. This could happen on screen rotation.
39
+		CGSize boundsSize = self.bounds.size;
40
+		self.contentOffset = CGPointMake(MAX(-contentInset.left, MIN(contentSize.width - boundsSize.width + contentInset.right, originalOffset.x)),
41
+										 MAX(-contentInset.top, MIN(contentSize.height - boundsSize.height + contentInset.bottom, originalOffset.y)));
42
+	}
43
+}
14 44
 
15 45
 @implementation RNNSwizzles
16 46
 
@@ -43,6 +73,18 @@ static id (*__SWZ_initWithEventDispatcher_orig)(id self, SEL _cmd, id eventDispa
43 73
 	__SWZ_initWithEventDispatcher_orig = (void*)method_getImplementation(m1);
44 74
 	Method m2 = class_getInstanceMethod([RNNSwizzles class], NSSelectorFromString(@"__swz_initWithEventDispatcher:"));
45 75
 	method_exchangeImplementations(m1, m2);
76
+	
77
+	if (@available(iOS 11.0, *)) {
78
+		cls = NSClassFromString(@"RCTCustomScrollView");
79
+		if(cls == NULL)
80
+		{
81
+			return;
82
+		}
83
+			
84
+		m1 = class_getInstanceMethod(cls, @selector(setFrame:));
85
+		__SWZ_setFrame_orig = (void*)method_getImplementation(m1);
86
+		method_setImplementation(m1, (IMP)__RNN_setFrame_orig);
87
+	}
46 88
 }
47 89
 #endif
48 90