mirror of
https://github.com/status-im/react-native-webview.git
synced 2025-02-23 17:28:37 +00:00
Rename back to RCT
This commit is contained in:
parent
af0057a321
commit
e9a6c6134f
@ -7,7 +7,7 @@
|
||||
|
||||
#import <React/RCTView.h>
|
||||
|
||||
@class IRWebView;
|
||||
@class RCTWebView;
|
||||
|
||||
/**
|
||||
* Special scheme used to pass messages to the injectedJavaScript
|
||||
@ -17,17 +17,17 @@
|
||||
*/
|
||||
extern NSString *const RCTJSNavigationScheme;
|
||||
|
||||
@protocol IRWebViewDelegate <NSObject>
|
||||
@protocol RCTWebViewDelegate <NSObject>
|
||||
|
||||
- (BOOL)webView:(IRWebView *)webView
|
||||
- (BOOL)webView:(RCTWebView *)webView
|
||||
shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
|
||||
withCallback:(RCTDirectEventBlock)callback;
|
||||
|
||||
@end
|
||||
|
||||
@interface IRWebView : RCTView
|
||||
@interface RCTWebView : RCTView
|
||||
|
||||
@property (nonatomic, weak) id<IRWebViewDelegate> delegate;
|
||||
@property (nonatomic, weak) id<RCTWebViewDelegate> delegate;
|
||||
|
||||
@property (nonatomic, copy) NSDictionary *source;
|
||||
@property (nonatomic, assign) UIEdgeInsets contentInset;
|
@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "IRWebView.h"
|
||||
#import "RCTWebView.h"
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@ -21,7 +21,7 @@ NSString *const RCTJSNavigationScheme = @"react-js-navigation";
|
||||
|
||||
static NSString *const kPostMessageHost = @"postMessage";
|
||||
|
||||
@interface IRWebView () <UIWebViewDelegate, RCTAutoInsetsProtocol>
|
||||
@interface RCTWebView () <UIWebViewDelegate, RCTAutoInsetsProtocol>
|
||||
|
||||
@property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
|
||||
@property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
|
||||
@ -31,7 +31,7 @@ static NSString *const kPostMessageHost = @"postMessage";
|
||||
|
||||
@end
|
||||
|
||||
@implementation IRWebView
|
||||
@implementation RCTWebView
|
||||
{
|
||||
UIWebView *_webView;
|
||||
NSString *_injectedJavaScript;
|
@ -1,18 +1,18 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = "IRWebView"
|
||||
s.name = "RCTWebView"
|
||||
s.version = "1.0.0"
|
||||
s.summary = "IRWebView"
|
||||
s.summary = "RCTWebView"
|
||||
s.description = <<-DESC
|
||||
IRWebView
|
||||
RCTWebView
|
||||
DESC
|
||||
s.homepage = ""
|
||||
s.license = "MIT"
|
||||
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
|
||||
s.author = { "author" => "author@domain.cn" }
|
||||
s.platform = :ios, "7.0"
|
||||
s.source = { :git => "https://github.com/author/IRWebView.git", :tag => "master" }
|
||||
s.source_files = "IRWebView/**/*.{h,m}"
|
||||
s.source = { :git => "https://github.com/author/RCTWebView.git", :tag => "master" }
|
||||
s.source_files = "RCTWebView/**/*.{h,m}"
|
||||
s.requires_arc = true
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
B3E7B58A1CC2AC0600A0062D /* IRWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* IRWebView.m */; };
|
||||
B3E7B58A1CC2AC0600A0062D /* RCTWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RCTWebView.m */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
@ -23,9 +23,9 @@
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
134814201AA4EA6300B7C361 /* libIRWebView.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libIRWebView.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B3E7B5881CC2AC0600A0062D /* IRWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IRWebView.h; sourceTree = "<group>"; };
|
||||
B3E7B5891CC2AC0600A0062D /* IRWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IRWebView.m; sourceTree = "<group>"; };
|
||||
134814201AA4EA6300B7C361 /* libRCTWebView.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTWebView.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B3E7B5881CC2AC0600A0062D /* RCTWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWebView.h; sourceTree = "<group>"; };
|
||||
B3E7B5891CC2AC0600A0062D /* RCTWebView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTWebView.m; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -42,7 +42,7 @@
|
||||
134814211AA4EA7D00B7C361 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
134814201AA4EA6300B7C361 /* libIRWebView.a */,
|
||||
134814201AA4EA6300B7C361 /* libRCTWebView.a */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
@ -50,8 +50,8 @@
|
||||
58B511D21A9E6C8500147676 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B3E7B5881CC2AC0600A0062D /* IRWebView.h */,
|
||||
B3E7B5891CC2AC0600A0062D /* IRWebView.m */,
|
||||
B3E7B5881CC2AC0600A0062D /* RCTWebView.h */,
|
||||
B3E7B5891CC2AC0600A0062D /* RCTWebView.m */,
|
||||
134814211AA4EA7D00B7C361 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
@ -59,9 +59,9 @@
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
58B511DA1A9E6C8500147676 /* IRWebView */ = {
|
||||
58B511DA1A9E6C8500147676 /* RCTWebView */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "IRWebView" */;
|
||||
buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTWebView" */;
|
||||
buildPhases = (
|
||||
58B511D71A9E6C8500147676 /* Sources */,
|
||||
58B511D81A9E6C8500147676 /* Frameworks */,
|
||||
@ -71,9 +71,9 @@
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = IRWebView;
|
||||
name = RCTWebView;
|
||||
productName = RCTDataManager;
|
||||
productReference = 134814201AA4EA6300B7C361 /* libIRWebView.a */;
|
||||
productReference = 134814201AA4EA6300B7C361 /* libRCTWebView.a */;
|
||||
productType = "com.apple.product-type.library.static";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
@ -90,7 +90,7 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "IRWebView" */;
|
||||
buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTWebView" */;
|
||||
compatibilityVersion = "Xcode 3.2";
|
||||
developmentRegion = English;
|
||||
hasScannedForEncodings = 0;
|
||||
@ -102,7 +102,7 @@
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
58B511DA1A9E6C8500147676 /* IRWebView */,
|
||||
58B511DA1A9E6C8500147676 /* RCTWebView */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
@ -112,7 +112,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
B3E7B58A1CC2AC0600A0062D /* IRWebView.m in Sources */,
|
||||
B3E7B58A1CC2AC0600A0062D /* RCTWebView.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@ -211,7 +211,7 @@
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PRODUCT_NAME = IRWebView;
|
||||
PRODUCT_NAME = RCTWebView;
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Debug;
|
||||
@ -227,7 +227,7 @@
|
||||
);
|
||||
LIBRARY_SEARCH_PATHS = "$(inherited)";
|
||||
OTHER_LDFLAGS = "-ObjC";
|
||||
PRODUCT_NAME = IRWebView;
|
||||
PRODUCT_NAME = RCTWebView;
|
||||
SKIP_INSTALL = YES;
|
||||
};
|
||||
name = Release;
|
||||
@ -235,7 +235,7 @@
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "IRWebView" */ = {
|
||||
58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "RCTWebView" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
58B511ED1A9E6C8500147676 /* Debug */,
|
||||
@ -244,7 +244,7 @@
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "IRWebView" */ = {
|
||||
58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "RCTWebView" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
58B511F01A9E6C8500147676 /* Debug */,
|
@ -3,7 +3,7 @@
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "group:IRWebView.xcodeproj">
|
||||
location = "group:RCTWebView.xcodeproj">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
|
@ -5,8 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <React/IRViewManager.h>
|
||||
#import <React/RCTViewManager.h>
|
||||
|
||||
@interface IRWebViewManager : IRViewManager
|
||||
@interface RCTWebViewManager : RCTViewManager
|
||||
|
||||
@end
|
@ -5,18 +5,18 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "IRWebViewManager.h"
|
||||
#import "RCTWebViewManager.h"
|
||||
|
||||
#import "RCTBridge.h"
|
||||
#import "RCTUIManager.h"
|
||||
#import "IRWebView.h"
|
||||
#import "RCTWebView.h"
|
||||
#import "UIView+React.h"
|
||||
|
||||
@interface IRWebViewManager () <IRWebViewDelegate>
|
||||
@interface RCTWebViewManager () <RCTWebViewDelegate>
|
||||
|
||||
@end
|
||||
|
||||
@implementation IRWebViewManager
|
||||
@implementation RCTWebViewManager
|
||||
{
|
||||
NSConditionLock *_shouldStartLoadLock;
|
||||
BOOL _shouldStartLoad;
|
||||
@ -26,7 +26,7 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
- (UIView *)view
|
||||
{
|
||||
IRWebView *webView = [IRWebView new];
|
||||
RCTWebView *webView = [RCTWebView new];
|
||||
webView.delegate = self;
|
||||
return webView;
|
||||
}
|
||||
@ -51,10 +51,10 @@ RCT_REMAP_VIEW_PROPERTY(dataDetectorTypes, _webView.dataDetectorTypes, UIDataDet
|
||||
|
||||
RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
|
||||
IRWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[IRWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
|
||||
RCTWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
||||
} else {
|
||||
[view goBack];
|
||||
}
|
||||
@ -65,8 +65,8 @@ RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
|
||||
id view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[IRWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
||||
} else {
|
||||
[view goForward];
|
||||
}
|
||||
@ -75,10 +75,10 @@ RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag)
|
||||
|
||||
RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
|
||||
IRWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[IRWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
|
||||
RCTWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
||||
} else {
|
||||
[view reload];
|
||||
}
|
||||
@ -87,10 +87,10 @@ RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag)
|
||||
|
||||
RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
|
||||
IRWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[IRWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
|
||||
RCTWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
||||
} else {
|
||||
[view stopLoading];
|
||||
}
|
||||
@ -99,10 +99,10 @@ RCT_EXPORT_METHOD(stopLoading:(nonnull NSNumber *)reactTag)
|
||||
|
||||
RCT_EXPORT_METHOD(postMessage:(nonnull NSNumber *)reactTag message:(NSString *)message)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
|
||||
IRWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[IRWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
|
||||
RCTWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
||||
} else {
|
||||
[view postMessage:message];
|
||||
}
|
||||
@ -111,10 +111,10 @@ RCT_EXPORT_METHOD(postMessage:(nonnull NSNumber *)reactTag message:(NSString *)m
|
||||
|
||||
RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, IRWebView *> *viewRegistry) {
|
||||
IRWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[IRWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting IRWebView, got: %@", view);
|
||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWebView *> *viewRegistry) {
|
||||
RCTWebView *view = viewRegistry[reactTag];
|
||||
if (![view isKindOfClass:[RCTWebView class]]) {
|
||||
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
||||
} else {
|
||||
[view injectJavaScript:script];
|
||||
}
|
||||
@ -123,7 +123,7 @@ RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString
|
||||
|
||||
#pragma mark - Exported synchronous methods
|
||||
|
||||
- (BOOL)webView:(__unused IRWebView *)webView
|
||||
- (BOOL)webView:(__unused RCTWebView *)webView
|
||||
shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
|
||||
withCallback:(RCTDirectEventBlock)callback
|
||||
{
|
@ -1,46 +0,0 @@
|
||||
// /**
|
||||
// * Copyright (c) 2015-present, Facebook, Inc.
|
||||
// *
|
||||
// * This source code is licensed under the MIT license found in the
|
||||
// * LICENSE file in the root directory of this source tree.
|
||||
// */
|
||||
|
||||
// #import <React/RCTView.h>
|
||||
|
||||
// @class IRWebView;
|
||||
|
||||
// /**
|
||||
// * Special scheme used to pass messages to the injectedJavaScript
|
||||
// * code without triggering a page load. Usage:
|
||||
// *
|
||||
// * window.location.href = RCTJSNavigationScheme + '://hello'
|
||||
// */
|
||||
// extern NSString *const RCTJSNavigationScheme;
|
||||
|
||||
// @protocol IRWebViewDelegate <NSObject>
|
||||
|
||||
// - (BOOL)webView:(IRWebView *)webView
|
||||
// shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
|
||||
// withCallback:(RCTDirectEventBlock)callback;
|
||||
|
||||
// @end
|
||||
|
||||
// @interface IRWebView : RCTView
|
||||
|
||||
// @property (nonatomic, weak) id<IRWebViewDelegate> delegate;
|
||||
|
||||
// @property (nonatomic, copy) NSDictionary *source;
|
||||
// @property (nonatomic, assign) UIEdgeInsets contentInset;
|
||||
// @property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
|
||||
// @property (nonatomic, assign) BOOL messagingEnabled;
|
||||
// @property (nonatomic, copy) NSString *injectedJavaScript;
|
||||
// @property (nonatomic, assign) BOOL scalesPageToFit;
|
||||
|
||||
// - (void)goForward;
|
||||
// - (void)goBack;
|
||||
// - (void)reload;
|
||||
// - (void)stopLoading;
|
||||
// - (void)postMessage:(NSString *)message;
|
||||
// - (void)injectJavaScript:(NSString *)script;
|
||||
|
||||
// @end
|
@ -1,351 +0,0 @@
|
||||
// /**
|
||||
// * Copyright (c) 2015-present, Facebook, Inc.
|
||||
// *
|
||||
// * This source code is licensed under the MIT license found in the
|
||||
// * LICENSE file in the root directory of this source tree.
|
||||
// */
|
||||
|
||||
// #import "IRWebView.h"
|
||||
|
||||
// #import <UIKit/UIKit.h>
|
||||
|
||||
// #import "RCTAutoInsetsProtocol.h"
|
||||
// #import "RCTConvert.h"
|
||||
// #import "RCTEventDispatcher.h"
|
||||
// #import "RCTLog.h"
|
||||
// #import "RCTUtils.h"
|
||||
// #import "RCTView.h"
|
||||
// #import "UIView+React.h"
|
||||
|
||||
// NSString *const RCTJSNavigationScheme = @"react-js-navigation";
|
||||
|
||||
// static NSString *const kPostMessageHost = @"postMessage";
|
||||
|
||||
// @interface IRWebView () <UIWebViewDelegate, RCTAutoInsetsProtocol>
|
||||
|
||||
// @property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
|
||||
// @property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
|
||||
// @property (nonatomic, copy) RCTDirectEventBlock onLoadingError;
|
||||
// @property (nonatomic, copy) RCTDirectEventBlock onShouldStartLoadWithRequest;
|
||||
// @property (nonatomic, copy) RCTDirectEventBlock onMessage;
|
||||
|
||||
// @end
|
||||
|
||||
// @implementation IRWebView
|
||||
// {
|
||||
// UIWebView *_webView;
|
||||
// NSString *_injectedJavaScript;
|
||||
// }
|
||||
|
||||
// - (void)dealloc
|
||||
// {
|
||||
// _webView.delegate = nil;
|
||||
// }
|
||||
|
||||
// - (instancetype)initWithFrame:(CGRect)frame
|
||||
// {
|
||||
// if ((self = [super initWithFrame:frame])) {
|
||||
// super.backgroundColor = [UIColor clearColor];
|
||||
// _automaticallyAdjustContentInsets = YES;
|
||||
// _contentInset = UIEdgeInsetsZero;
|
||||
// _webView = [[UIWebView alloc] initWithFrame:self.bounds];
|
||||
// _webView.delegate = self;
|
||||
// #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
|
||||
// if ([_webView.scrollView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
|
||||
// _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
// }
|
||||
// #endif
|
||||
// [self addSubview:_webView];
|
||||
// }
|
||||
// return self;
|
||||
// }
|
||||
|
||||
// RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
||||
|
||||
// - (void)goForward
|
||||
// {
|
||||
// [_webView goForward];
|
||||
// }
|
||||
|
||||
// - (void)goBack
|
||||
// {
|
||||
// [_webView goBack];
|
||||
// }
|
||||
|
||||
// - (void)reload
|
||||
// {
|
||||
// NSURLRequest *request = [RCTConvert NSURLRequest:self.source];
|
||||
// if (request.URL && !_webView.request.URL.absoluteString.length) {
|
||||
// [_webView loadRequest:request];
|
||||
// }
|
||||
// else {
|
||||
// [_webView reload];
|
||||
// }
|
||||
// }
|
||||
|
||||
// - (void)stopLoading
|
||||
// {
|
||||
// [_webView stopLoading];
|
||||
// }
|
||||
|
||||
// - (void)postMessage:(NSString *)message
|
||||
// {
|
||||
// NSDictionary *eventInitDict = @{
|
||||
// @"data": message,
|
||||
// };
|
||||
// NSString *source = [NSString
|
||||
// stringWithFormat:@"document.dispatchEvent(new MessageEvent('message', %@));",
|
||||
// RCTJSONStringify(eventInitDict, NULL)
|
||||
// ];
|
||||
// [_webView stringByEvaluatingJavaScriptFromString:source];
|
||||
// }
|
||||
|
||||
// - (void)injectJavaScript:(NSString *)script
|
||||
// {
|
||||
// [_webView stringByEvaluatingJavaScriptFromString:script];
|
||||
// }
|
||||
|
||||
// - (void)setSource:(NSDictionary *)source
|
||||
// {
|
||||
// if (![_source isEqualToDictionary:source]) {
|
||||
// _source = [source copy];
|
||||
|
||||
// // Check for a static html source first
|
||||
// NSString *html = [RCTConvert NSString:source[@"html"]];
|
||||
// if (html) {
|
||||
// NSURL *baseURL = [RCTConvert NSURL:source[@"baseUrl"]];
|
||||
// if (!baseURL) {
|
||||
// baseURL = [NSURL URLWithString:@"about:blank"];
|
||||
// }
|
||||
// [_webView loadHTMLString:html baseURL:baseURL];
|
||||
// return;
|
||||
// }
|
||||
|
||||
// NSURLRequest *request = [RCTConvert NSURLRequest:source];
|
||||
// // Because of the way React works, as pages redirect, we actually end up
|
||||
// // passing the redirect urls back here, so we ignore them if trying to load
|
||||
// // the same url. We'll expose a call to 'reload' to allow a user to load
|
||||
// // the existing page.
|
||||
// if ([request.URL isEqual:_webView.request.URL]) {
|
||||
// return;
|
||||
// }
|
||||
// if (!request.URL) {
|
||||
// // Clear the webview
|
||||
// [_webView loadHTMLString:@"" baseURL:nil];
|
||||
// return;
|
||||
// }
|
||||
// [_webView loadRequest:request];
|
||||
// }
|
||||
// }
|
||||
|
||||
// - (void)layoutSubviews
|
||||
// {
|
||||
// [super layoutSubviews];
|
||||
// _webView.frame = self.bounds;
|
||||
// }
|
||||
|
||||
// - (void)setContentInset:(UIEdgeInsets)contentInset
|
||||
// {
|
||||
// _contentInset = contentInset;
|
||||
// [RCTView autoAdjustInsetsForView:self
|
||||
// withScrollView:_webView.scrollView
|
||||
// updateOffset:NO];
|
||||
// }
|
||||
|
||||
// - (void)setScalesPageToFit:(BOOL)scalesPageToFit
|
||||
// {
|
||||
// if (_webView.scalesPageToFit != scalesPageToFit) {
|
||||
// _webView.scalesPageToFit = scalesPageToFit;
|
||||
// [_webView reload];
|
||||
// }
|
||||
// }
|
||||
|
||||
// - (BOOL)scalesPageToFit
|
||||
// {
|
||||
// return _webView.scalesPageToFit;
|
||||
// }
|
||||
|
||||
// - (void)setBackgroundColor:(UIColor *)backgroundColor
|
||||
// {
|
||||
// CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor);
|
||||
// self.opaque = _webView.opaque = (alpha == 1.0);
|
||||
// _webView.backgroundColor = backgroundColor;
|
||||
// }
|
||||
|
||||
// - (UIColor *)backgroundColor
|
||||
// {
|
||||
// return _webView.backgroundColor;
|
||||
// }
|
||||
|
||||
// - (NSMutableDictionary<NSString *, id> *)baseEvent
|
||||
// {
|
||||
// NSMutableDictionary<NSString *, id> *event = [[NSMutableDictionary alloc] initWithDictionary:@{
|
||||
// @"url": _webView.request.URL.absoluteString ?: @"",
|
||||
// @"loading" : @(_webView.loading),
|
||||
// @"title": [_webView stringByEvaluatingJavaScriptFromString:@"document.title"],
|
||||
// @"canGoBack": @(_webView.canGoBack),
|
||||
// @"canGoForward" : @(_webView.canGoForward),
|
||||
// }];
|
||||
|
||||
// return event;
|
||||
// }
|
||||
|
||||
// - (void)refreshContentInset
|
||||
// {
|
||||
// [RCTView autoAdjustInsetsForView:self
|
||||
// withScrollView:_webView.scrollView
|
||||
// updateOffset:YES];
|
||||
// }
|
||||
|
||||
// #pragma mark - UIWebViewDelegate methods
|
||||
|
||||
// - (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
|
||||
// navigationType:(UIWebViewNavigationType)navigationType
|
||||
// {
|
||||
// BOOL isJSNavigation = [request.URL.scheme isEqualToString:RCTJSNavigationScheme];
|
||||
|
||||
// static NSDictionary<NSNumber *, NSString *> *navigationTypes;
|
||||
// static dispatch_once_t onceToken;
|
||||
// dispatch_once(&onceToken, ^{
|
||||
// navigationTypes = @{
|
||||
// @(UIWebViewNavigationTypeLinkClicked): @"click",
|
||||
// @(UIWebViewNavigationTypeFormSubmitted): @"formsubmit",
|
||||
// @(UIWebViewNavigationTypeBackForward): @"backforward",
|
||||
// @(UIWebViewNavigationTypeReload): @"reload",
|
||||
// @(UIWebViewNavigationTypeFormResubmitted): @"formresubmit",
|
||||
// @(UIWebViewNavigationTypeOther): @"other",
|
||||
// };
|
||||
// });
|
||||
|
||||
// // skip this for the JS Navigation handler
|
||||
// if (!isJSNavigation && _onShouldStartLoadWithRequest) {
|
||||
// NSMutableDictionary<NSString *, id> *event = [self baseEvent];
|
||||
// [event addEntriesFromDictionary: @{
|
||||
// @"url": (request.URL).absoluteString,
|
||||
// @"navigationType": navigationTypes[@(navigationType)]
|
||||
// }];
|
||||
// if (![self.delegate webView:self
|
||||
// shouldStartLoadForRequest:event
|
||||
// withCallback:_onShouldStartLoadWithRequest]) {
|
||||
// return NO;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (_onLoadingStart) {
|
||||
// // We have this check to filter out iframe requests and whatnot
|
||||
// BOOL isTopFrame = [request.URL isEqual:request.mainDocumentURL];
|
||||
// if (isTopFrame) {
|
||||
// NSMutableDictionary<NSString *, id> *event = [self baseEvent];
|
||||
// [event addEntriesFromDictionary: @{
|
||||
// @"url": (request.URL).absoluteString,
|
||||
// @"navigationType": navigationTypes[@(navigationType)]
|
||||
// }];
|
||||
// _onLoadingStart(event);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (isJSNavigation && [request.URL.host isEqualToString:kPostMessageHost]) {
|
||||
// NSString *data = request.URL.query;
|
||||
// data = [data stringByReplacingOccurrencesOfString:@"+" withString:@" "];
|
||||
// data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
// NSMutableDictionary<NSString *, id> *event = [self baseEvent];
|
||||
// [event addEntriesFromDictionary: @{
|
||||
// @"data": data,
|
||||
// }];
|
||||
|
||||
// NSString *source = @"document.dispatchEvent(new MessageEvent('message:received'));";
|
||||
|
||||
// [_webView stringByEvaluatingJavaScriptFromString:source];
|
||||
|
||||
// _onMessage(event);
|
||||
// }
|
||||
|
||||
// // JS Navigation handler
|
||||
// return !isJSNavigation;
|
||||
// }
|
||||
|
||||
// - (void)webView:(__unused UIWebView *)webView didFailLoadWithError:(NSError *)error
|
||||
// {
|
||||
// if (_onLoadingError) {
|
||||
// if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled) {
|
||||
// // NSURLErrorCancelled is reported when a page has a redirect OR if you load
|
||||
// // a new URL in the WebView before the previous one came back. We can just
|
||||
// // ignore these since they aren't real errors.
|
||||
// // http://stackoverflow.com/questions/1024748/how-do-i-fix-nsurlerrordomain-error-999-in-iphone-3-0-os
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) {
|
||||
// // Error code 102 "Frame load interrupted" is raised by the UIWebView if
|
||||
// // its delegate returns FALSE from webView:shouldStartLoadWithRequest:navigationType
|
||||
// // when the URL is from an http redirect. This is a common pattern when
|
||||
// // implementing OAuth with a WebView.
|
||||
// return;
|
||||
// }
|
||||
|
||||
// NSMutableDictionary<NSString *, id> *event = [self baseEvent];
|
||||
// [event addEntriesFromDictionary:@{
|
||||
// @"domain": error.domain,
|
||||
// @"code": @(error.code),
|
||||
// @"description": error.localizedDescription,
|
||||
// }];
|
||||
// _onLoadingError(event);
|
||||
// }
|
||||
// }
|
||||
|
||||
// - (void)webViewDidFinishLoad:(UIWebView *)webView
|
||||
// {
|
||||
// if (_messagingEnabled) {
|
||||
// #if RCT_DEV
|
||||
// // See isNative in lodash
|
||||
// NSString *testPostMessageNative = @"String(window.postMessage) === String(Object.hasOwnProperty).replace('hasOwnProperty', 'postMessage')";
|
||||
// BOOL postMessageIsNative = [
|
||||
// [webView stringByEvaluatingJavaScriptFromString:testPostMessageNative]
|
||||
// isEqualToString:@"true"
|
||||
// ];
|
||||
// if (!postMessageIsNative) {
|
||||
// RCTLogError(@"Setting onMessage on a WebView overrides existing values of window.postMessage, but a previous value was defined");
|
||||
// }
|
||||
// #endif
|
||||
// NSString *source = [NSString stringWithFormat:
|
||||
// @"(function() {"
|
||||
// "window.originalPostMessage = window.postMessage;"
|
||||
|
||||
// "var messageQueue = [];"
|
||||
// "var messagePending = false;"
|
||||
|
||||
// "function processQueue() {"
|
||||
// "if (!messageQueue.length || messagePending) return;"
|
||||
// "messagePending = true;"
|
||||
// "window.location = '%@://%@?' + encodeURIComponent(messageQueue.shift());"
|
||||
// "}"
|
||||
|
||||
// "window.postMessage = function(data) {"
|
||||
// "messageQueue.push(String(data));"
|
||||
// "processQueue();"
|
||||
// "};"
|
||||
|
||||
// "document.addEventListener('message:received', function(e) {"
|
||||
// "messagePending = false;"
|
||||
// "processQueue();"
|
||||
// "});"
|
||||
// "})();", RCTJSNavigationScheme, kPostMessageHost
|
||||
// ];
|
||||
// [webView stringByEvaluatingJavaScriptFromString:source];
|
||||
// }
|
||||
// if (_injectedJavaScript != nil) {
|
||||
// NSString *jsEvaluationValue = [webView stringByEvaluatingJavaScriptFromString:_injectedJavaScript];
|
||||
|
||||
// NSMutableDictionary<NSString *, id> *event = [self baseEvent];
|
||||
// event[@"jsEvaluationValue"] = jsEvaluationValue;
|
||||
|
||||
// _onLoadingFinish(event);
|
||||
// }
|
||||
// // we only need the final 'finishLoad' call so only fire the event when we're actually done loading.
|
||||
// else if (_onLoadingFinish && !webView.loading && ![webView.request.URL.absoluteString isEqualToString:@"about:blank"]) {
|
||||
// _onLoadingFinish([self baseEvent]);
|
||||
// }
|
||||
// }
|
||||
|
||||
// @end
|
Loading…
x
Reference in New Issue
Block a user