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, strong) NSURL *URL;
|
||||
@property (nonatomic, copy) NSDictionary *source;
|
||||
@property (nonatomic, assign) UIEdgeInsets contentInset;
|
||||
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
|
||||
@property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "RCTAutoInsetsProtocol.h"
|
||||
#import "RCTConvert.h"
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTLog.h"
|
||||
#import "RCTUtils.h"
|
||||
|
@ -106,26 +107,34 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
|||
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
|
||||
// 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 ([URL isEqual:_webView.request.URL]) {
|
||||
return;
|
||||
}
|
||||
if (!URL) {
|
||||
// Clear the webview
|
||||
[_webView loadHTMLString:@"" baseURL:nil];
|
||||
return;
|
||||
}
|
||||
[_webView loadRequest:[NSURLRequest requestWithURL:URL]];
|
||||
}
|
||||
if (![_source isEqualToDictionary:source]) {
|
||||
_source = [source copy];
|
||||
|
||||
- (void)setHTML:(NSString *)HTML
|
||||
{
|
||||
[_webView loadHTMLString:HTML baseURL:nil];
|
||||
// Check for a static html source first
|
||||
NSString *html = [RCTConvert NSString:source[@"html"]];
|
||||
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
|
||||
|
|
|
@ -36,8 +36,7 @@ RCT_EXPORT_MODULE()
|
|||
return webView;
|
||||
}
|
||||
|
||||
RCT_REMAP_VIEW_PROPERTY(url, URL, NSURL)
|
||||
RCT_REMAP_VIEW_PROPERTY(html, HTML, NSString)
|
||||
RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary)
|
||||
RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL)
|
||||
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, _webView.scrollView.scrollEnabled, BOOL)
|
||||
RCT_REMAP_VIEW_PROPERTY(scalesPageToFit, _webView.scalesPageToFit, BOOL)
|
||||
|
|
Loading…
Reference in New Issue