@@ -27,17 +27,30 @@ - (instancetype)initWithFrame:(CGRect)frame
27
27
{
28
28
if ((self = [super initWithFrame: frame])) {
29
29
super.backgroundColor = [UIColor clearColor ];
30
+ _bounces = YES ;
31
+ _scrollEnabled = YES ;
32
+ }
33
+ return self;
34
+ }
35
+
36
+ - (void )didMoveToWindow
37
+ {
38
+ if (self.window != nil ) {
30
39
WKWebViewConfiguration *wkWebViewConfig = [WKWebViewConfiguration new ];
31
40
wkWebViewConfig.userContentController = [WKUserContentController new ];
32
41
[wkWebViewConfig.userContentController addScriptMessageHandler: self name: MessageHanderName];
42
+ wkWebViewConfig.allowsInlineMediaPlayback = _allowsInlineMediaPlayback;
33
43
34
44
_webView = [[WKWebView alloc ] initWithFrame: self .bounds configuration: wkWebViewConfig];
35
45
_webView.scrollView .delegate = self;
36
46
_webView.UIDelegate = self;
37
47
_webView.navigationDelegate = self;
48
+ _webView.scrollView .scrollEnabled = _scrollEnabled;
49
+ _webView.scrollView .bounces = _bounces;
38
50
[self addSubview: _webView];
51
+
52
+ [self visitSource ];
39
53
}
40
- return self;
41
54
}
42
55
43
56
/* *
@@ -59,32 +72,39 @@ - (void)setSource:(NSDictionary *)source
59
72
if (![_source isEqualToDictionary: source]) {
60
73
_source = [source copy ];
61
74
62
- // Check for a static html source first
63
- NSString *html = [RCTConvert NSString: source[@" html" ]];
64
- if (html) {
65
- NSURL *baseURL = [RCTConvert NSURL: source[@" baseUrl" ]];
66
- if (!baseURL) {
67
- baseURL = [NSURL URLWithString: @" about:blank" ];
68
- }
69
- [_webView loadHTMLString: html baseURL: baseURL];
70
- return ;
75
+ if (_webView != nil ) {
76
+ [self visitSource ];
71
77
}
78
+ }
79
+ }
72
80
73
- NSURLRequest *request = [RCTConvert NSURLRequest: source];
74
- // Because of the way React works, as pages redirect, we actually end up
75
- // passing the redirect urls back here, so we ignore them if trying to load
76
- // the same url. We'll expose a call to 'reload' to allow a user to load
77
- // the existing page.
78
- if ([request.URL isEqual: _webView.URL]) {
79
- return ;
80
- }
81
- if (!request.URL ) {
82
- // Clear the webview
83
- [_webView loadHTMLString: @" " baseURL: nil ];
84
- return ;
81
+ - (void )visitSource
82
+ {
83
+ // Check for a static html source first
84
+ NSString *html = [RCTConvert NSString: _source[@" html" ]];
85
+ if (html) {
86
+ NSURL *baseURL = [RCTConvert NSURL: _source[@" baseUrl" ]];
87
+ if (!baseURL) {
88
+ baseURL = [NSURL URLWithString: @" about:blank" ];
85
89
}
86
- [_webView loadRequest: request];
90
+ [_webView loadHTMLString: html baseURL: baseURL];
91
+ return ;
87
92
}
93
+
94
+ NSURLRequest *request = [RCTConvert NSURLRequest: _source];
95
+ // Because of the way React works, as pages redirect, we actually end up
96
+ // passing the redirect urls back here, so we ignore them if trying to load
97
+ // the same url. We'll expose a call to 'reload' to allow a user to load
98
+ // the existing page.
99
+ if ([request.URL isEqual: _webView.URL]) {
100
+ return ;
101
+ }
102
+ if (!request.URL ) {
103
+ // Clear the webview
104
+ [_webView loadHTMLString: @" " baseURL: nil ];
105
+ return ;
106
+ }
107
+ [_webView loadRequest: request];
88
108
}
89
109
90
110
@@ -95,6 +115,7 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
95
115
96
116
- (void )setScrollEnabled : (BOOL )scrollEnabled
97
117
{
118
+ _scrollEnabled = scrollEnabled;
98
119
_webView.scrollView .scrollEnabled = scrollEnabled;
99
120
}
100
121
@@ -305,4 +326,10 @@ - (void)stopLoading
305
326
{
306
327
[_webView stopLoading ];
307
328
}
329
+
330
+ - (void )setBounces : (BOOL )bounces
331
+ {
332
+ _bounces = bounces;
333
+ _webView.scrollView .bounces = bounces;
334
+ }
308
335
@end
0 commit comments