15
15
#import < UIKit/UIKit.h>
16
16
17
17
#import " RCTAutoInsetsProtocol.h"
18
+ #import " RCTConvert.h"
18
19
#import " RCTEventDispatcher.h"
19
20
#import " RCTLog.h"
20
21
#import " RCTUtils.h"
@@ -106,26 +107,34 @@ - (NSURL *)URL
106
107
return _webView.request .URL ;
107
108
}
108
109
109
- - (void )setURL : ( NSURL *)URL
110
+ - (void )setSource : ( NSDictionary *)source
110
111
{
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
+ }
125
122
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
+ }
129
138
}
130
139
131
140
- (void )layoutSubviews
@@ -179,7 +188,7 @@ -(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
179
188
if (!hideKeyboardAccessoryView) {
180
189
return ;
181
190
}
182
-
191
+
183
192
UIView* subview;
184
193
for (UIView* view in _webView.scrollView .subviews ) {
185
194
if ([[view.class description ] hasPrefix: @" UIWeb" ])
@@ -195,10 +204,10 @@ -(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
195
204
{
196
205
newClass = objc_allocateClassPair (subview.class , [name cStringUsingEncoding: NSASCIIStringEncoding], 0 );
197
206
if (!newClass) return ;
198
-
207
+
199
208
Method method = class_getInstanceMethod ([_SwizzleHelper class ], @selector (inputAccessoryView ));
200
209
class_addMethod (newClass, @selector (inputAccessoryView ), method_getImplementation (method), method_getTypeEncoding (method));
201
-
210
+
202
211
objc_registerClassPair (newClass);
203
212
}
204
213
0 commit comments