updated ios module to support react-native 20
This commit is contained in:
parent
f5436ea1a5
commit
f116c8d4ee
|
@ -34,7 +34,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
|
||||||
|
|
||||||
@property (nonatomic, weak) id<RCTWebViewBridgeDelegate> delegate;
|
@property (nonatomic, weak) id<RCTWebViewBridgeDelegate> delegate;
|
||||||
|
|
||||||
@property (nonatomic, strong) NSURL *URL;
|
@property (nonatomic, copy) NSDictionary *source;
|
||||||
@property (nonatomic, assign) UIEdgeInsets contentInset;
|
@property (nonatomic, assign) UIEdgeInsets contentInset;
|
||||||
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
|
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
|
||||||
@property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
|
@property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
#import "RCTAutoInsetsProtocol.h"
|
#import "RCTAutoInsetsProtocol.h"
|
||||||
|
#import "RCTConvert.h"
|
||||||
#import "RCTEventDispatcher.h"
|
#import "RCTEventDispatcher.h"
|
||||||
#import "RCTLog.h"
|
#import "RCTLog.h"
|
||||||
#import "RCTUtils.h"
|
#import "RCTUtils.h"
|
||||||
|
@ -106,26 +107,34 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
||||||
return _webView.request.URL;
|
return _webView.request.URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setURL:(NSURL *)URL
|
- (void)setSource:(NSDictionary *)source
|
||||||
{
|
{
|
||||||
// Because of the way React works, as pages redirect, we actually end up
|
if (![_source isEqualToDictionary:source]) {
|
||||||
// passing the redirect urls back here, so we ignore them if trying to load
|
_source = [source copy];
|
||||||
// the same url. We'll expose a call to 'reload' to allow a user to load
|
|
||||||
// the existing page.
|
|
||||||
if ([URL isEqual:_webView.request.URL]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!URL) {
|
|
||||||
// Clear the webview
|
|
||||||
[_webView loadHTMLString:@"" baseURL:nil];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
[_webView loadRequest:[NSURLRequest requestWithURL:URL]];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setHTML:(NSString *)HTML
|
// Check for a static html source first
|
||||||
{
|
NSString *html = [RCTConvert NSString:source[@"html"]];
|
||||||
[_webView loadHTMLString:HTML baseURL:nil];
|
if (html) {
|
||||||
|
NSURL *baseURL = [RCTConvert NSURL:source[@"baseUrl"]];
|
||||||
|
[_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
|
- (void)layoutSubviews
|
||||||
|
@ -179,7 +188,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
||||||
if (!hideKeyboardAccessoryView) {
|
if (!hideKeyboardAccessoryView) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIView* subview;
|
UIView* subview;
|
||||||
for (UIView* view in _webView.scrollView.subviews) {
|
for (UIView* view in _webView.scrollView.subviews) {
|
||||||
if([[view.class description] hasPrefix:@"UIWeb"])
|
if([[view.class description] hasPrefix:@"UIWeb"])
|
||||||
|
@ -195,10 +204,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
||||||
{
|
{
|
||||||
newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0);
|
newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0);
|
||||||
if(!newClass) return;
|
if(!newClass) return;
|
||||||
|
|
||||||
Method method = class_getInstanceMethod([_SwizzleHelper class], @selector(inputAccessoryView));
|
Method method = class_getInstanceMethod([_SwizzleHelper class], @selector(inputAccessoryView));
|
||||||
class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));
|
class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));
|
||||||
|
|
||||||
objc_registerClassPair(newClass);
|
objc_registerClassPair(newClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,7 @@ RCT_EXPORT_MODULE()
|
||||||
return webView;
|
return webView;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_REMAP_VIEW_PROPERTY(url, URL, NSURL)
|
RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary)
|
||||||
RCT_REMAP_VIEW_PROPERTY(html, HTML, NSString)
|
|
||||||
RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL)
|
RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL)
|
||||||
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, _webView.scrollView.scrollEnabled, BOOL)
|
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, _webView.scrollView.scrollEnabled, BOOL)
|
||||||
RCT_REMAP_VIEW_PROPERTY(scalesPageToFit, _webView.scalesPageToFit, BOOL)
|
RCT_REMAP_VIEW_PROPERTY(scalesPageToFit, _webView.scalesPageToFit, BOOL)
|
||||||
|
|
Loading…
Reference in New Issue