Browse Source

Reshuffling

Jamon Holmgren 5 years ago
parent
commit
af0057a321

src/android/build.gradle → android/build.gradle View File


src/android/src/main/AndroidManifest.xml → android/src/main/AndroidManifest.xml View File


src/android/src/main/java/com/infinitered/irwebview/ReactWebViewManager.java → android/src/main/java/com/infinitered/irwebview/ReactWebViewManager.java View File


src/android/src/main/java/com/infinitered/irwebview/WebViewConfig.java → android/src/main/java/com/infinitered/irwebview/WebViewConfig.java View File


src/android/src/main/java/com/infinitered/irwebview/events/TopLoadingErrorEvent.java → android/src/main/java/com/infinitered/irwebview/events/TopLoadingErrorEvent.java View File


src/android/src/main/java/com/infinitered/irwebview/events/TopLoadingFinishEvent.java → android/src/main/java/com/infinitered/irwebview/events/TopLoadingFinishEvent.java View File


src/android/src/main/java/com/infinitered/irwebview/events/TopLoadingStartEvent.java → android/src/main/java/com/infinitered/irwebview/events/TopLoadingStartEvent.java View File


src/android/src/main/java/com/infinitered/irwebview/events/TopMessageEvent.java → android/src/main/java/com/infinitered/irwebview/events/TopMessageEvent.java View File


src/ios/RCTWebView.h → ios/IRWebView.h View File

@@ -7,7 +7,7 @@
7 7
 
8 8
 #import <React/RCTView.h>
9 9
 
10
-@class RCTWebView;
10
+@class IRWebView;
11 11
 
12 12
 /**
13 13
  * Special scheme used to pass messages to the injectedJavaScript
@@ -17,17 +17,17 @@
17 17
  */
18 18
 extern NSString *const RCTJSNavigationScheme;
19 19
 
20
-@protocol RCTWebViewDelegate <NSObject>
20
+@protocol IRWebViewDelegate <NSObject>
21 21
 
22
-- (BOOL)webView:(RCTWebView *)webView
22
+- (BOOL)webView:(IRWebView *)webView
23 23
 shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
24 24
    withCallback:(RCTDirectEventBlock)callback;
25 25
 
26 26
 @end
27 27
 
28
-@interface RCTWebView : RCTView
28
+@interface IRWebView : RCTView
29 29
 
30
-@property (nonatomic, weak) id<RCTWebViewDelegate> delegate;
30
+@property (nonatomic, weak) id<IRWebViewDelegate> delegate;
31 31
 
32 32
 @property (nonatomic, copy) NSDictionary *source;
33 33
 @property (nonatomic, assign) UIEdgeInsets contentInset;

src/ios/RCTWebView.m → ios/IRWebView.m View File

@@ -5,7 +5,7 @@
5 5
  * LICENSE file in the root directory of this source tree.
6 6
  */
7 7
 
8
-#import "RCTWebView.h"
8
+#import "IRWebView.h"
9 9
 
10 10
 #import <UIKit/UIKit.h>
11 11
 
@@ -21,7 +21,7 @@ NSString *const RCTJSNavigationScheme = @"react-js-navigation";
21 21
 
22 22
 static NSString *const kPostMessageHost = @"postMessage";
23 23
 
24
-@interface RCTWebView () <UIWebViewDelegate, RCTAutoInsetsProtocol>
24
+@interface IRWebView () <UIWebViewDelegate, RCTAutoInsetsProtocol>
25 25
 
26 26
 @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
27 27
 @property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
@@ -31,7 +31,7 @@ static NSString *const kPostMessageHost = @"postMessage";
31 31
 
32 32
 @end
33 33
 
34
-@implementation RCTWebView
34
+@implementation IRWebView
35 35
 {
36 36
   UIWebView *_webView;
37 37
   NSString *_injectedJavaScript;

+ 24
- 0
ios/IRWebView.podspec View File

@@ -0,0 +1,24 @@
1
+
2
+Pod::Spec.new do |s|
3
+  s.name         = "IRWebView"
4
+  s.version      = "1.0.0"
5
+  s.summary      = "IRWebView"
6
+  s.description  = <<-DESC
7
+                  IRWebView
8
+                   DESC
9
+  s.homepage     = ""
10
+  s.license      = "MIT"
11
+  # s.license      = { :type => "MIT", :file => "FILE_LICENSE" }
12
+  s.author             = { "author" => "author@domain.cn" }
13
+  s.platform     = :ios, "7.0"
14
+  s.source       = { :git => "https://github.com/author/IRWebView.git", :tag => "master" }
15
+  s.source_files  = "IRWebView/**/*.{h,m}"
16
+  s.requires_arc = true
17
+
18
+
19
+  s.dependency "React"
20
+  #s.dependency "others"
21
+
22
+end
23
+
24
+  

+ 259
- 0
ios/IRWebView.xcodeproj/project.pbxproj View File

@@ -0,0 +1,259 @@
1
+// !$*UTF8*$!
2
+{
3
+	archiveVersion = 1;
4
+	classes = {
5
+	};
6
+	objectVersion = 46;
7
+	objects = {
8
+
9
+/* Begin PBXBuildFile section */
10
+		B3E7B58A1CC2AC0600A0062D /* IRWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* IRWebView.m */; };
11
+/* End PBXBuildFile section */
12
+
13
+/* Begin PBXCopyFilesBuildPhase section */
14
+		58B511D91A9E6C8500147676 /* CopyFiles */ = {
15
+			isa = PBXCopyFilesBuildPhase;
16
+			buildActionMask = 2147483647;
17
+			dstPath = "include/$(PRODUCT_NAME)";
18
+			dstSubfolderSpec = 16;
19
+			files = (
20
+			);
21
+			runOnlyForDeploymentPostprocessing = 0;
22
+		};
23
+/* End PBXCopyFilesBuildPhase section */
24
+
25
+/* Begin PBXFileReference section */
26
+		134814201AA4EA6300B7C361 /* libIRWebView.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libIRWebView.a; sourceTree = BUILT_PRODUCTS_DIR; };
27
+		B3E7B5881CC2AC0600A0062D /* IRWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IRWebView.h; sourceTree = "<group>"; };
28
+		B3E7B5891CC2AC0600A0062D /* IRWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IRWebView.m; sourceTree = "<group>"; };
29
+/* End PBXFileReference section */
30
+
31
+/* Begin PBXFrameworksBuildPhase section */
32
+		58B511D81A9E6C8500147676 /* Frameworks */ = {
33
+			isa = PBXFrameworksBuildPhase;
34
+			buildActionMask = 2147483647;
35
+			files = (
36
+			);
37
+			runOnlyForDeploymentPostprocessing = 0;
38
+		};
39
+/* End PBXFrameworksBuildPhase section */
40
+
41
+/* Begin PBXGroup section */
42
+		134814211AA4EA7D00B7C361 /* Products */ = {
43
+			isa = PBXGroup;
44
+			children = (
45
+				134814201AA4EA6300B7C361 /* libIRWebView.a */,
46
+			);
47
+			name = Products;
48
+			sourceTree = "<group>";
49
+		};
50
+		58B511D21A9E6C8500147676 = {
51
+			isa = PBXGroup;
52
+			children = (
53
+				B3E7B5881CC2AC0600A0062D /* IRWebView.h */,
54
+				B3E7B5891CC2AC0600A0062D /* IRWebView.m */,
55
+				134814211AA4EA7D00B7C361 /* Products */,
56
+			);
57
+			sourceTree = "<group>";
58
+		};
59
+/* End PBXGroup section */
60
+
61
+/* Begin PBXNativeTarget section */
62
+		58B511DA1A9E6C8500147676 /* IRWebView */ = {
63
+			isa = PBXNativeTarget;
64
+			buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "IRWebView" */;
65
+			buildPhases = (
66
+				58B511D71A9E6C8500147676 /* Sources */,
67
+				58B511D81A9E6C8500147676 /* Frameworks */,
68
+				58B511D91A9E6C8500147676 /* CopyFiles */,
69
+			);
70
+			buildRules = (
71
+			);
72
+			dependencies = (
73
+			);
74
+			name = IRWebView;
75
+			productName = RCTDataManager;
76
+			productReference = 134814201AA4EA6300B7C361 /* libIRWebView.a */;
77
+			productType = "com.apple.product-type.library.static";
78
+		};
79
+/* End PBXNativeTarget section */
80
+
81
+/* Begin PBXProject section */
82
+		58B511D31A9E6C8500147676 /* Project object */ = {
83
+			isa = PBXProject;
84
+			attributes = {
85
+				LastUpgradeCheck = 0830;
86
+				ORGANIZATIONNAME = Facebook;
87
+				TargetAttributes = {
88
+					58B511DA1A9E6C8500147676 = {
89
+						CreatedOnToolsVersion = 6.1.1;
90
+					};
91
+				};
92
+			};
93
+			buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "IRWebView" */;
94
+			compatibilityVersion = "Xcode 3.2";
95
+			developmentRegion = English;
96
+			hasScannedForEncodings = 0;
97
+			knownRegions = (
98
+				en,
99
+			);
100
+			mainGroup = 58B511D21A9E6C8500147676;
101
+			productRefGroup = 58B511D21A9E6C8500147676;
102
+			projectDirPath = "";
103
+			projectRoot = "";
104
+			targets = (
105
+				58B511DA1A9E6C8500147676 /* IRWebView */,
106
+			);
107
+		};
108
+/* End PBXProject section */
109
+
110
+/* Begin PBXSourcesBuildPhase section */
111
+		58B511D71A9E6C8500147676 /* Sources */ = {
112
+			isa = PBXSourcesBuildPhase;
113
+			buildActionMask = 2147483647;
114
+			files = (
115
+				B3E7B58A1CC2AC0600A0062D /* IRWebView.m in Sources */,
116
+			);
117
+			runOnlyForDeploymentPostprocessing = 0;
118
+		};
119
+/* End PBXSourcesBuildPhase section */
120
+
121
+/* Begin XCBuildConfiguration section */
122
+		58B511ED1A9E6C8500147676 /* Debug */ = {
123
+			isa = XCBuildConfiguration;
124
+			buildSettings = {
125
+				ALWAYS_SEARCH_USER_PATHS = NO;
126
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
127
+				CLANG_CXX_LIBRARY = "libc++";
128
+				CLANG_ENABLE_MODULES = YES;
129
+				CLANG_ENABLE_OBJC_ARC = YES;
130
+				CLANG_WARN_BOOL_CONVERSION = YES;
131
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
132
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
133
+				CLANG_WARN_EMPTY_BODY = YES;
134
+				CLANG_WARN_ENUM_CONVERSION = YES;
135
+				CLANG_WARN_INFINITE_RECURSION = YES;
136
+				CLANG_WARN_INT_CONVERSION = YES;
137
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
138
+				CLANG_WARN_SUSPICIOUS_MOVE = YES;
139
+				CLANG_WARN_UNREACHABLE_CODE = YES;
140
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
141
+				COPY_PHASE_STRIP = NO;
142
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
143
+				ENABLE_TESTABILITY = YES;
144
+				GCC_C_LANGUAGE_STANDARD = gnu99;
145
+				GCC_DYNAMIC_NO_PIC = NO;
146
+				GCC_NO_COMMON_BLOCKS = YES;
147
+				GCC_OPTIMIZATION_LEVEL = 0;
148
+				GCC_PREPROCESSOR_DEFINITIONS = (
149
+					"DEBUG=1",
150
+					"$(inherited)",
151
+				);
152
+				GCC_SYMBOLS_PRIVATE_EXTERN = NO;
153
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
154
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
155
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
156
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
157
+				GCC_WARN_UNUSED_FUNCTION = YES;
158
+				GCC_WARN_UNUSED_VARIABLE = YES;
159
+				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
160
+				MTL_ENABLE_DEBUG_INFO = YES;
161
+				ONLY_ACTIVE_ARCH = YES;
162
+				SDKROOT = iphoneos;
163
+			};
164
+			name = Debug;
165
+		};
166
+		58B511EE1A9E6C8500147676 /* Release */ = {
167
+			isa = XCBuildConfiguration;
168
+			buildSettings = {
169
+				ALWAYS_SEARCH_USER_PATHS = NO;
170
+				CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
171
+				CLANG_CXX_LIBRARY = "libc++";
172
+				CLANG_ENABLE_MODULES = YES;
173
+				CLANG_ENABLE_OBJC_ARC = YES;
174
+				CLANG_WARN_BOOL_CONVERSION = YES;
175
+				CLANG_WARN_CONSTANT_CONVERSION = YES;
176
+				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
177
+				CLANG_WARN_EMPTY_BODY = YES;
178
+				CLANG_WARN_ENUM_CONVERSION = YES;
179
+				CLANG_WARN_INFINITE_RECURSION = YES;
180
+				CLANG_WARN_INT_CONVERSION = YES;
181
+				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
182
+				CLANG_WARN_SUSPICIOUS_MOVE = YES;
183
+				CLANG_WARN_UNREACHABLE_CODE = YES;
184
+				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
185
+				COPY_PHASE_STRIP = YES;
186
+				ENABLE_NS_ASSERTIONS = NO;
187
+				ENABLE_STRICT_OBJC_MSGSEND = YES;
188
+				GCC_C_LANGUAGE_STANDARD = gnu99;
189
+				GCC_NO_COMMON_BLOCKS = YES;
190
+				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
191
+				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
192
+				GCC_WARN_UNDECLARED_SELECTOR = YES;
193
+				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
194
+				GCC_WARN_UNUSED_FUNCTION = YES;
195
+				GCC_WARN_UNUSED_VARIABLE = YES;
196
+				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
197
+				MTL_ENABLE_DEBUG_INFO = NO;
198
+				SDKROOT = iphoneos;
199
+				VALIDATE_PRODUCT = YES;
200
+			};
201
+			name = Release;
202
+		};
203
+		58B511F01A9E6C8500147676 /* Debug */ = {
204
+			isa = XCBuildConfiguration;
205
+			buildSettings = {
206
+				HEADER_SEARCH_PATHS = (
207
+				"$(inherited)",
208
+					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
209
+					"$(SRCROOT)/../../../React/**",
210
+					"$(SRCROOT)/../../react-native/React/**",
211
+				);
212
+				LIBRARY_SEARCH_PATHS = "$(inherited)";
213
+				OTHER_LDFLAGS = "-ObjC";
214
+				PRODUCT_NAME = IRWebView;
215
+				SKIP_INSTALL = YES;
216
+			};
217
+			name = Debug;
218
+		};
219
+		58B511F11A9E6C8500147676 /* Release */ = {
220
+			isa = XCBuildConfiguration;
221
+			buildSettings = {
222
+				HEADER_SEARCH_PATHS = (
223
+					"$(inherited)",
224
+					/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
225
+					"$(SRCROOT)/../../../React/**",
226
+					"$(SRCROOT)/../../react-native/React/**",
227
+				);
228
+				LIBRARY_SEARCH_PATHS = "$(inherited)";
229
+				OTHER_LDFLAGS = "-ObjC";
230
+				PRODUCT_NAME = IRWebView;
231
+				SKIP_INSTALL = YES;
232
+			};
233
+			name = Release;
234
+		};
235
+/* End XCBuildConfiguration section */
236
+
237
+/* Begin XCConfigurationList section */
238
+		58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "IRWebView" */ = {
239
+			isa = XCConfigurationList;
240
+			buildConfigurations = (
241
+				58B511ED1A9E6C8500147676 /* Debug */,
242
+				58B511EE1A9E6C8500147676 /* Release */,
243
+			);
244
+			defaultConfigurationIsVisible = 0;
245
+			defaultConfigurationName = Release;
246
+		};
247
+		58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "IRWebView" */ = {
248
+			isa = XCConfigurationList;
249
+			buildConfigurations = (
250
+				58B511F01A9E6C8500147676 /* Debug */,
251
+				58B511F11A9E6C8500147676 /* Release */,
252
+			);
253
+			defaultConfigurationIsVisible = 0;
254
+			defaultConfigurationName = Release;
255
+		};
256
+/* End XCConfigurationList section */
257
+	};
258
+	rootObject = 58B511D31A9E6C8500147676 /* Project object */;
259
+}

+ 9
- 0
ios/IRWebView.xcworkspace/contents.xcworkspacedata View File

@@ -0,0 +1,9 @@
1
+// !$*UTF8*$!
2
+<?xml version="1.0" encoding="UTF-8"?>
3
+<Workspace
4
+   version = "1.0">
5
+   <FileRef
6
+      location = "group:IRWebView.xcodeproj">
7
+   </FileRef>
8
+</Workspace>
9
+  

src/ios/RCTWebViewManager.h → ios/IRWebViewManager.h View File

@@ -5,8 +5,8 @@
5 5
  * LICENSE file in the root directory of this source tree.
6 6
  */
7 7
 
8
-#import <React/RCTViewManager.h>
8
+#import <React/IRViewManager.h>
9 9
 
10
-@interface RCTWebViewManager : RCTViewManager
10
+@interface IRWebViewManager : IRViewManager
11 11
 
12 12
 @end

src/ios/RCTWebViewManager.m → ios/IRWebViewManager.m View File

@@ -5,18 +5,18 @@
5 5
  * LICENSE file in the root directory of this source tree.
6 6
  */
7 7
 
8
-#import "RCTWebViewManager.h"
8
+#import "IRWebViewManager.h"
9 9
 
10 10
 #import "RCTBridge.h"
11 11
 #import "RCTUIManager.h"
12
-#import "RCTWebView.h"
12
+#import "IRWebView.h"
13 13
 #import "UIView+React.h"
14 14
 
15
-@interface RCTWebViewManager () <RCTWebViewDelegate>
15
+@interface IRWebViewManager () <IRWebViewDelegate>
16 16
 
17 17
 @end
18 18
 
19
-@implementation RCTWebViewManager
19
+@implementation IRWebViewManager
20 20
 {
21 21
   NSConditionLock *_shouldStartLoadLock;
22 22
   BOOL _shouldStartLoad;
@@ -26,7 +26,7 @@ RCT_EXPORT_MODULE()
26 26
 
27 27
 - (UIView *)view
28 28
 {
29
-  RCTWebView *webView = [RCTWebView new];
29
+  IRWebView *webView = [IRWebView new];
30 30
   webView.delegate = self;
31 31
   return webView;
32 32
 }
@@ -51,10 +51,10 @@ RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, _webView.dataDetectorTypes, UIDataDet
51 51
 
52 52
 RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
53 53
 {
54
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
55
-    RCTWebView *view = viewRegistry[reactTag];
56
-    if (![view isKindOfClass:[RCTWebView class]]) {
57
-      RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
54
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
55
+    IRWebView *view = viewRegistry[reactTag];
56
+    if (![view isKindOfClass:[IRWebView class]]) {
57
+      RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
58 58
     } else {
59 59
       [view goBack];
60 60
     }
@@ -65,8 +65,8 @@ RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
65 65
 {
66 66
   [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
67 67
     id view = viewRegistry[reactTag];
68
-    if (![view isKindOfClass:[RCTWebView class]]) {
69
-      RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
68
+    if (![view isKindOfClass:[IRWebView class]]) {
69
+      RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
70 70
     } else {
71 71
       [view goForward];
72 72
     }
@@ -75,10 +75,10 @@ RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
75 75
 
76 76
 RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag)
77 77
 {
78
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
79
-    RCTWebView *view = viewRegistry[reactTag];
80
-    if (![view isKindOfClass:[RCTWebView class]]) {
81
-      RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
78
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
79
+    IRWebView *view = viewRegistry[reactTag];
80
+    if (![view isKindOfClass:[IRWebView class]]) {
81
+      RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
82 82
     } else {
83 83
       [view reload];
84 84
     }
@@ -87,10 +87,10 @@ RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag)
87 87
 
88 88
 RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag)
89 89
 {
90
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
91
-    RCTWebView *view = viewRegistry[reactTag];
92
-    if (![view isKindOfClass:[RCTWebView class]]) {
93
-      RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
90
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
91
+    IRWebView *view = viewRegistry[reactTag];
92
+    if (![view isKindOfClass:[IRWebView class]]) {
93
+      RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
94 94
     } else {
95 95
       [view stopLoading];
96 96
     }
@@ -99,10 +99,10 @@ RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag)
99 99
 
100 100
 RCT_EXPORT_METHOD(postMessage:(nonnull NSNumber *)reactTag message:(NSString *)message)
101 101
 {
102
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
103
-    RCTWebView *view = viewRegistry[reactTag];
104
-    if (![view isKindOfClass:[RCTWebView class]]) {
105
-      RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
102
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
103
+    IRWebView *view = viewRegistry[reactTag];
104
+    if (![view isKindOfClass:[IRWebView class]]) {
105
+      RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
106 106
     } else {
107 107
       [view postMessage:message];
108 108
     }
@@ -111,10 +111,10 @@ RCT_EXPORT_METHOD(postMessage:(nonnull NSNumber *)reactTag message:(NSString *)m
111 111
 
112 112
 RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
113 113
 {
114
-  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
115
-    RCTWebView *view = viewRegistry[reactTag];
116
-    if (![view isKindOfClass:[RCTWebView class]]) {
117
-      RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
114
+  [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
115
+    IRWebView *view = viewRegistry[reactTag];
116
+    if (![view isKindOfClass:[IRWebView class]]) {
117
+      RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
118 118
     } else {
119 119
       [view injectJavaScript:script];
120 120
     }
@@ -123,7 +123,7 @@ RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString
123 123
 
124 124
 #pragma mark - Exported synchronous methods
125 125
 
126
-- (BOOL)webView:(__unused RCTWebView *)webView
126
+- (BOOL)webView:(__unused IRWebView *)webView
127 127
 shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
128 128
    withCallback:(RCTDirectEventBlock)callback
129 129
 {

+ 46
- 0
ios/fb/RCTWebView.h View File

@@ -0,0 +1,46 @@
1
+// /**
2
+//  * Copyright (c) 2015-present, Facebook, Inc.
3
+//  *
4
+//  * This source code is licensed under the MIT license found in the
5
+//  * LICENSE file in the root directory of this source tree.
6
+//  */
7
+
8
+// #import <React/RCTView.h>
9
+
10
+// @class IRWebView;
11
+
12
+// /**
13
+//  * Special scheme used to pass messages to the injectedJavaScript
14
+//  * code without triggering a page load. Usage:
15
+//  *
16
+//  *   window.location.href = RCTJSNavigationScheme + '://hello'
17
+//  */
18
+// extern NSString *const RCTJSNavigationScheme;
19
+
20
+// @protocol IRWebViewDelegate <NSObject>
21
+
22
+// - (BOOL)webView:(IRWebView *)webView
23
+// shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
24
+//    withCallback:(RCTDirectEventBlock)callback;
25
+
26
+// @end
27
+
28
+// @interface IRWebView : RCTView
29
+
30
+// @property (nonatomic, weak) id<IRWebViewDelegate> delegate;
31
+
32
+// @property (nonatomic, copy) NSDictionary *source;
33
+// @property (nonatomic, assign) UIEdgeInsets contentInset;
34
+// @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
35
+// @property (nonatomic, assign) BOOL messagingEnabled;
36
+// @property (nonatomic, copy) NSString *injectedJavaScript;
37
+// @property (nonatomic, assign) BOOL scalesPageToFit;
38
+
39
+// - (void)goForward;
40
+// - (void)goBack;
41
+// - (void)reload;
42
+// - (void)stopLoading;
43
+// - (void)postMessage:(NSString *)message;
44
+// - (void)injectJavaScript:(NSString *)script;
45
+
46
+// @end

+ 351
- 0
ios/fb/RCTWebView.m View File

@@ -0,0 +1,351 @@
1
+// /**
2
+//  * Copyright (c) 2015-present, Facebook, Inc.
3
+//  *
4
+//  * This source code is licensed under the MIT license found in the
5
+//  * LICENSE file in the root directory of this source tree.
6
+//  */
7
+
8
+// #import "IRWebView.h"
9
+
10
+// #import <UIKit/UIKit.h>
11
+
12
+// #import "RCTAutoInsetsProtocol.h"
13
+// #import "RCTConvert.h"
14
+// #import "RCTEventDispatcher.h"
15
+// #import "RCTLog.h"
16
+// #import "RCTUtils.h"
17
+// #import "RCTView.h"
18
+// #import "UIView+React.h"
19
+
20
+// NSString *const RCTJSNavigationScheme = @"react-js-navigation";
21
+
22
+// static NSString *const kPostMessageHost = @"postMessage";
23
+
24
+// @interface IRWebView () <UIWebViewDelegate, RCTAutoInsetsProtocol>
25
+
26
+// @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
27
+// @property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
28
+// @property (nonatomic, copy) RCTDirectEventBlock onLoadingError;
29
+// @property (nonatomic, copy) RCTDirectEventBlock onShouldStartLoadWithRequest;
30
+// @property (nonatomic, copy) RCTDirectEventBlock onMessage;
31
+
32
+// @end
33
+
34
+// @implementation IRWebView
35
+// {
36
+//   UIWebView *_webView;
37
+//   NSString *_injectedJavaScript;
38
+// }
39
+
40
+// - (void)dealloc
41
+// {
42
+//   _webView.delegate = nil;
43
+// }
44
+
45
+// - (instancetype)initWithFrame:(CGRect)frame
46
+// {
47
+//   if ((self = [super initWithFrame:frame])) {
48
+//     super.backgroundColor = [UIColor clearColor];
49
+//     _automaticallyAdjustContentInsets = YES;
50
+//     _contentInset = UIEdgeInsetsZero;
51
+//     _webView = [[UIWebView alloc] initWithFrame:self.bounds];
52
+//     _webView.delegate = self;
53
+// #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
54
+//     if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
55
+//       _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
56
+//     }
57
+// #endif
58
+//     [self addSubview:_webView];
59
+//   }
60
+//   return self;
61
+// }
62
+
63
+// RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
64
+
65
+// - (void)goForward
66
+// {
67
+//   [_webView goForward];
68
+// }
69
+
70
+// - (void)goBack
71
+// {
72
+//   [_webView goBack];
73
+// }
74
+
75
+// - (void)reload
76
+// {
77
+//   NSURLRequest *request = [RCTConvert NSURLRequest:self.source];
78
+//   if (request.URL && !_webView.request.URL.absoluteString.length) {
79
+//     [_webView loadRequest:request];
80
+//   }
81
+//   else {
82
+//     [_webView reload];
83
+//   }
84
+// }
85
+
86
+// - (void)stopLoading
87
+// {
88
+//   [_webView stopLoading];
89
+// }
90
+
91
+// - (void)postMessage:(NSString *)message
92
+// {
93
+//   NSDictionary *eventInitDict = @{
94
+//     @"data": message,
95
+//   };
96
+//   NSString *source = [NSString
97
+//     stringWithFormat:@"document.dispatchEvent(new MessageEvent('message', %@));",
98
+//     RCTJSONStringify(eventInitDict, NULL)
99
+//   ];
100
+//   [_webView stringByEvaluatingJavaScriptFromString:source];
101
+// }
102
+
103
+// - (void)injectJavaScript:(NSString *)script
104
+// {
105
+//   [_webView stringByEvaluatingJavaScriptFromString:script];
106
+// }
107
+
108
+// - (void)setSource:(NSDictionary *)source
109
+// {
110
+//   if (![_source isEqualToDictionary:source]) {
111
+//     _source = [source copy];
112
+
113
+//     // Check for a static html source first
114
+//     NSString *html = [RCTConvert NSString:source[@"html"]];
115
+//     if (html) {
116
+//       NSURL *baseURL = [RCTConvert NSURL:source[@"baseUrl"]];
117
+//       if (!baseURL) {
118
+//         baseURL = [NSURL URLWithString:@"about:blank"];
119
+//       }
120
+//       [_webView loadHTMLString:html baseURL:baseURL];
121
+//       return;
122
+//     }
123
+
124
+//     NSURLRequest *request = [RCTConvert NSURLRequest:source];
125
+//     // Because of the way React works, as pages redirect, we actually end up
126
+//     // passing the redirect urls back here, so we ignore them if trying to load
127
+//     // the same url. We'll expose a call to 'reload' to allow a user to load
128
+//     // the existing page.
129
+//     if ([request.URL isEqual:_webView.request.URL]) {
130
+//       return;
131
+//     }
132
+//     if (!request.URL) {
133
+//       // Clear the webview
134
+//       [_webView loadHTMLString:@"" baseURL:nil];
135
+//       return;
136
+//     }
137
+//     [_webView loadRequest:request];
138
+//   }
139
+// }
140
+
141
+// - (void)layoutSubviews
142
+// {
143
+//   [super layoutSubviews];
144
+//   _webView.frame = self.bounds;
145
+// }
146
+
147
+// - (void)setContentInset:(UIEdgeInsets)contentInset
148
+// {
149
+//   _contentInset = contentInset;
150
+//   [RCTView autoAdjustInsetsForView:self
151
+//                     withScrollView:_webView.scrollView
152
+//                       updateOffset:NO];
153
+// }
154
+
155
+// - (void)setScalesPageToFit:(BOOL)scalesPageToFit
156
+// {
157
+//   if (_webView.scalesPageToFit != scalesPageToFit) {
158
+//     _webView.scalesPageToFit = scalesPageToFit;
159
+//     [_webView reload];
160
+//   }
161
+// }
162
+
163
+// - (BOOL)scalesPageToFit
164
+// {
165
+//   return _webView.scalesPageToFit;
166
+// }
167
+
168
+// - (void)setBackgroundColor:(UIColor *)backgroundColor
169
+// {
170
+//   CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor);
171
+//   self.opaque = _webView.opaque = (alpha == 1.0);
172
+//   _webView.backgroundColor = backgroundColor;
173
+// }
174
+
175
+// - (UIColor *)backgroundColor
176
+// {
177
+//   return _webView.backgroundColor;
178
+// }
179
+
180
+// - (NSMutableDictionary<NSString *, id> *)baseEvent
181
+// {
182
+//   NSMutableDictionary<NSString *, id> *event = [[NSMutableDictionary alloc] initWithDictionary:@{
183
+//     @"url": _webView.request.URL.absoluteString ?: @"",
184
+//     @"loading" : @(_webView.loading),
185
+//     @"title": [_webView stringByEvaluatingJavaScriptFromString:@"document.title"],
186
+//     @"canGoBack": @(_webView.canGoBack),
187
+//     @"canGoForward" : @(_webView.canGoForward),
188
+//   }];
189
+
190
+//   return event;
191
+// }
192
+
193
+// - (void)refreshContentInset
194
+// {
195
+//   [RCTView autoAdjustInsetsForView:self
196
+//                     withScrollView:_webView.scrollView
197
+//                       updateOffset:YES];
198
+// }
199
+
200
+// #pragma mark - UIWebViewDelegate methods
201
+
202
+// - (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
203
+//  navigationType:(UIWebViewNavigationType)navigationType
204
+// {
205
+//   BOOL isJSNavigation = [request.URL.scheme isEqualToString:RCTJSNavigationScheme];
206
+
207
+//   static NSDictionary<NSNumber *, NSString *> *navigationTypes;
208
+//   static dispatch_once_t onceToken;
209
+//   dispatch_once(&onceToken, ^{
210
+//     navigationTypes = @{
211
+//       @(UIWebViewNavigationTypeLinkClicked): @"click",
212
+//       @(UIWebViewNavigationTypeFormSubmitted): @"formsubmit",
213
+//       @(UIWebViewNavigationTypeBackForward): @"backforward",
214
+//       @(UIWebViewNavigationTypeReload): @"reload",
215
+//       @(UIWebViewNavigationTypeFormResubmitted): @"formresubmit",
216
+//       @(UIWebViewNavigationTypeOther): @"other",
217
+//     };
218
+//   });
219
+
220
+//   // skip this for the JS Navigation handler
221
+//   if (!isJSNavigation && _onShouldStartLoadWithRequest) {
222
+//     NSMutableDictionary<NSString *, id> *event = [self baseEvent];
223
+//     [event addEntriesFromDictionary: @{
224
+//       @"url": (request.URL).absoluteString,
225
+//       @"navigationType": navigationTypes[@(navigationType)]
226
+//     }];
227
+//     if (![self.delegate webView:self
228
+//       shouldStartLoadForRequest:event
229
+//                    withCallback:_onShouldStartLoadWithRequest]) {
230
+//       return NO;
231
+//     }
232
+//   }
233
+
234
+//   if (_onLoadingStart) {
235
+//     // We have this check to filter out iframe requests and whatnot
236
+//     BOOL isTopFrame = [request.URL isEqual:request.mainDocumentURL];
237
+//     if (isTopFrame) {
238
+//       NSMutableDictionary<NSString *, id> *event = [self baseEvent];
239
+//       [event addEntriesFromDictionary: @{
240
+//         @"url": (request.URL).absoluteString,
241
+//         @"navigationType": navigationTypes[@(navigationType)]
242
+//       }];
243
+//       _onLoadingStart(event);
244
+//     }
245
+//   }
246
+
247
+//   if (isJSNavigation && [request.URL.host isEqualToString:kPostMessageHost]) {
248
+//     NSString *data = request.URL.query;
249
+//     data = [data stringByReplacingOccurrencesOfString:@"+" withString:@" "];
250
+//     data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
251
+
252
+//     NSMutableDictionary<NSString *, id> *event = [self baseEvent];
253
+//     [event addEntriesFromDictionary: @{
254
+//       @"data": data,
255
+//     }];
256
+
257
+//     NSString *source = @"document.dispatchEvent(new MessageEvent('message:received'));";
258
+
259
+//     [_webView stringByEvaluatingJavaScriptFromString:source];
260
+
261
+//     _onMessage(event);
262
+//   }
263
+
264
+//   // JS Navigation handler
265
+//   return !isJSNavigation;
266
+// }
267
+
268
+// - (void)webView:(__unused UIWebView *)webView didFailLoadWithError:(NSError *)error
269
+// {
270
+//   if (_onLoadingError) {
271
+//     if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled) {
272
+//       // NSURLErrorCancelled is reported when a page has a redirect OR if you load
273
+//       // a new URL in the WebView before the previous one came back. We can just
274
+//       // ignore these since they aren't real errors.
275
+//       // http://stackoverflow.com/questions/1024748/how-do-i-fix-nsurlerrordomain-error-999-in-iphone-3-0-os
276
+//       return;
277
+//     }
278
+
279
+//     if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {
280
+//       // Error code 102 "Frame load interrupted" is raised by the UIWebView if
281
+//       // its delegate returns FALSE from webView:shouldStartLoadWithRequest:navigationType
282
+//       // when the URL is from an http redirect. This is a common pattern when
283
+//       // implementing OAuth with a WebView.
284
+//       return;
285
+//     }
286
+
287
+//     NSMutableDictionary<NSString *, id> *event = [self baseEvent];
288
+//     [event addEntriesFromDictionary:@{
289
+//       @"domain": error.domain,
290
+//       @"code": @(error.code),
291
+//       @"description": error.localizedDescription,
292
+//     }];
293
+//     _onLoadingError(event);
294
+//   }
295
+// }
296
+
297
+// - (void)webViewDidFinishLoad:(UIWebView *)webView
298
+// {
299
+//   if (_messagingEnabled) {
300
+//     #if RCT_DEV
301
+//     // See isNative in lodash
302
+//     NSString *testPostMessageNative = @"String(window.postMessage) === String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage')";
303
+//     BOOL postMessageIsNative = [
304
+//       [webView stringByEvaluatingJavaScriptFromString:testPostMessageNative]
305
+//       isEqualToString:@"true"
306
+//     ];
307
+//     if (!postMessageIsNative) {
308
+//       RCTLogError(@"Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined");
309
+//     }
310
+//     #endif
311
+//     NSString *source = [NSString stringWithFormat:
312
+//       @"(function() {"
313
+//         "window.originalPostMessage = window.postMessage;"
314
+
315
+//         "var messageQueue = [];"
316
+//         "var messagePending = false;"
317
+
318
+//         "function processQueue() {"
319
+//           "if (!messageQueue.length || messagePending) return;"
320
+//           "messagePending = true;"
321
+//           "window.location = '%@://%@?' + encodeURIComponent(messageQueue.shift());"
322
+//         "}"
323
+
324
+//         "window.postMessage = function(data) {"
325
+//           "messageQueue.push(String(data));"
326
+//           "processQueue();"
327
+//         "};"
328
+
329
+//         "document.addEventListener('message:received', function(e) {"
330
+//           "messagePending = false;"
331
+//           "processQueue();"
332
+//         "});"
333
+//       "})();", RCTJSNavigationScheme, kPostMessageHost
334
+//     ];
335
+//     [webView stringByEvaluatingJavaScriptFromString:source];
336
+//   }
337
+//   if (_injectedJavaScript != nil) {
338
+//     NSString *jsEvaluationValue = [webView stringByEvaluatingJavaScriptFromString:_injectedJavaScript];
339
+
340
+//     NSMutableDictionary<NSString *, id> *event = [self baseEvent];
341
+//     event[@"jsEvaluationValue"] = jsEvaluationValue;
342
+
343
+//     _onLoadingFinish(event);
344
+//   }
345
+//   // we only need the final 'finishLoad' call so only fire the event when we're actually done loading.
346
+//   else if (_onLoadingFinish && !webView.loading && ![webView.request.URL.absoluteString isEqualToString:@"about:blank"]) {
347
+//     _onLoadingFinish([self baseEvent]);
348
+//   }
349
+// }
350
+
351
+// @end

src/js/WebView.android.js → js/WebView.android.js View File


src/js/WebView.integration.js → js/WebView.integration.js View File


src/js/WebView.ios.js → js/WebView.ios.js View File


src/js/WebViewShared.js → js/WebViewShared.js View File


src/js/WebViewShared.test.js → js/WebViewShared.test.js View File