Skip to content

Commit f116c8d

Browse files
committed
updated ios module to support react-native 20
1 parent f5436ea commit f116c8d

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

ios/RCTWebViewBridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
3434

3535
@property (nonatomic, weak) id<RCTWebViewBridgeDelegate> delegate;
3636

37-
@property (nonatomic, strong) NSURL *URL;
37+
@property (nonatomic, copy) NSDictionary *source;
3838
@property (nonatomic, assign) UIEdgeInsets contentInset;
3939
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
4040
@property (nonatomic, assign) BOOL hideKeyboardAccessoryView;

ios/RCTWebViewBridge.m

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#import <UIKit/UIKit.h>
1616

1717
#import "RCTAutoInsetsProtocol.h"
18+
#import "RCTConvert.h"
1819
#import "RCTEventDispatcher.h"
1920
#import "RCTLog.h"
2021
#import "RCTUtils.h"
@@ -106,26 +107,34 @@ - (NSURL *)URL
106107
return _webView.request.URL;
107108
}
108109

109-
- (void)setURL:(NSURL *)URL
110+
- (void)setSource:(NSDictionary *)source
110111
{
111-
// Because of the way React works, as pages redirect, we actually end up
112-
// passing the redirect urls back here, so we ignore them if trying to load
113-
// the same url. We'll expose a call to 'reload' to allow a user to load
114-
// the existing page.
115-
if ([URL isEqual:_webView.request.URL]) {
116-
return;
117-
}
118-
if (!URL) {
119-
// Clear the webview
120-
[_webView loadHTMLString:@"" baseURL:nil];
121-
return;
122-
}
123-
[_webView loadRequest:[NSURLRequest requestWithURL:URL]];
124-
}
112+
if (![_source isEqualToDictionary:source]) {
113+
_source = [source copy];
114+
115+
// Check for a static html source first
116+
NSString *html = [RCTConvert NSString:source[@"html"]];
117+
if (html) {
118+
NSURL *baseURL = [RCTConvert NSURL:source[@"baseUrl"]];
119+
[_webView loadHTMLString:html baseURL:baseURL];
120+
return;
121+
}
125122

126-
- (void)setHTML:(NSString *)HTML
127-
{
128-
[_webView loadHTMLString:HTML baseURL:nil];
123+
NSURLRequest *request = [RCTConvert NSURLRequest:source];
124+
// Because of the way React works, as pages redirect, we actually end up
125+
// passing the redirect urls back here, so we ignore them if trying to load
126+
// the same url. We'll expose a call to 'reload' to allow a user to load
127+
// the existing page.
128+
if ([request.URL isEqual:_webView.request.URL]) {
129+
return;
130+
}
131+
if (!request.URL) {
132+
// Clear the webview
133+
[_webView loadHTMLString:@"" baseURL:nil];
134+
return;
135+
}
136+
[_webView loadRequest:request];
137+
}
129138
}
130139

131140
- (void)layoutSubviews
@@ -179,7 +188,7 @@ -(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
179188
if (!hideKeyboardAccessoryView) {
180189
return;
181190
}
182-
191+
183192
UIView* subview;
184193
for (UIView* view in _webView.scrollView.subviews) {
185194
if([[view.class description] hasPrefix:@"UIWeb"])
@@ -195,10 +204,10 @@ -(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
195204
{
196205
newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0);
197206
if(!newClass) return;
198-
207+
199208
Method method = class_getInstanceMethod([_SwizzleHelper class], @selector(inputAccessoryView));
200209
class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));
201-
210+
202211
objc_registerClassPair(newClass);
203212
}
204213

ios/RCTWebViewBridgeManager.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ - (UIView *)view
3636
return webView;
3737
}
3838

39-
RCT_REMAP_VIEW_PROPERTY(url, URL, NSURL)
40-
RCT_REMAP_VIEW_PROPERTY(html, HTML, NSString)
39+
RCT_EXPORT_VIEW_PROPERTY(source, NSDictionary)
4140
RCT_REMAP_VIEW_PROPERTY(bounces, _webView.scrollView.bounces, BOOL)
4241
RCT_REMAP_VIEW_PROPERTY(scrollEnabled, _webView.scrollView.scrollEnabled, BOOL)
4342
RCT_REMAP_VIEW_PROPERTY(scalesPageToFit, _webView.scalesPageToFit, BOOL)

0 commit comments

Comments
 (0)