Skip to content

Commit b00326e

Browse files
committed
Merge branch 'CRAlpha-master'
2 parents 6200a25 + 4f1b8ef commit b00326e

File tree

11 files changed

+1387
-1029
lines changed

11 files changed

+1387
-1029
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import WKWebView from 'react-native-wkwebview-reborn';
2929

3030
Try replacing your existing `WebView` with `WKWebView` and it should work in most cases.
3131

32-
If your React Native < 0.40, please use **0.x.x** versions.
32+
For React Native >= 0.57, use version 2.x; for React Native < 0.40, use version 0.x.
3333

3434
### Compatibility with UIWebView
3535

@@ -43,16 +43,16 @@ WKWebView aims to be a drop-in replacement for UIWebView. However, some legacy U
4343

4444
A callback to get the loading progress of WKWebView. Derived from [`estimatedProgress`](https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKWebView_Ref/#//apple_ref/occ/instp/WKWebView/estimatedProgress) property.
4545

46-
- **onNavigationResponse**
47-
48-
A callback to get response headers, http status code and http localized status code.
49-
5046
```js
5147
<WKWebView onProgress={(progress) => console.log(progress)} />
5248
```
5349

5450
`progress` is a double between 0 and 1.
5551

52+
- **onNavigationResponse**
53+
54+
A callback to get response headers, http status code and http localized status code.
55+
5656
- **openNewWindowInWebView**
5757

5858
If set to true, links with `target="_blank"` or `window.open` will be opened in the current webview, not in Safari. Default is false.
@@ -96,6 +96,10 @@ This property specifies how the safe area insets are used to modify the content
9696

9797
Enables focusing an input inside a webview and showing the keyboard *programatically*. **New in 1.20.0**
9898

99+
- **keyboardDismissMode**
100+
101+
Sets the manner in which the keyboard is dismissed when a drag begins in the scroll view. Possible values are "none", "on-drag" and "interactive". Default to "none".
102+
99103
- **injectJavaScript, injectJavaScriptForMainFrameOnly**
100104

101105
Add JavaScript at document start, see [WKUserScriptInjectionTimeAtDocumentStart](https://developer.apple.com/documentation/webkit/wkuserscriptinjectiontime/wkuserscriptinjectiontimeatdocumentstart?language=objc). **New in 1.20.0**
@@ -104,6 +108,10 @@ Add JavaScript at document start, see [WKUserScriptInjectionTimeAtDocumentStart]
104108

105109
Add JavaScript at document end. Since 1.20.0, the implementation has been changed to use WKUserScript.
106110

111+
- **allowsBackForwardNavigationGestures**
112+
113+
Enable horizontal swipe gestures will trigger back-forward navigations. Derived from [`allowsBackForwardNavigationGestures`](https://developer.apple.com/documentation/webkit/wkwebview/1414995-allowsbackforwardnavigationgestu) property.
114+
107115
#### Currently supported props are:
108116

109117
- automaticallyAdjustContentInsets

WKWebView.ios.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource'
1818
import deprecatedPropType from 'react-native/Libraries/Utilities/deprecatedPropType';
1919
import invariant from 'fbjs/lib/invariant';
2020
import keyMirror from 'fbjs/lib/keyMirror';
21-
const WKWebViewManager = NativeModules.WKWebViewManager;
21+
const WKWebViewManager = NativeModules.CRAWKWebViewManager;
2222

2323
var BGWASH = 'rgba(255,255,255,0.8)';
2424

@@ -267,6 +267,15 @@ class WKWebView extends React.Component {
267267
* A Boolean value that sets whether diagonal scrolling is allowed.
268268
*/
269269
directionalLockEnabled: PropTypes.bool,
270+
/*
271+
* The manner in which the keyboard is dismissed when a drag begins in the
272+
* scroll view.
273+
*/
274+
keyboardDismissMode: PropTypes.oneOf([
275+
'none', // Default
276+
'on-drag',
277+
'interactive', // iOS only
278+
]),
270279
};
271280

272281
state = {
@@ -299,7 +308,7 @@ class WKWebView extends React.Component {
299308
);
300309
} else if (this.state.viewState !== WebViewState.IDLE) {
301310
console.error(
302-
'RCTWKWebView invalid state encountered: ' + this.state.loading
311+
'CRAWKWebView invalid state encountered: ' + this.state.loading
303312
);
304313
}
305314

@@ -333,7 +342,7 @@ class WKWebView extends React.Component {
333342
const messagingEnabled = typeof this.props.onMessage === 'function';
334343

335344
const webView =
336-
<RCTWKWebView
345+
<CRAWKWebView
337346
ref={ref => { this.webview = ref; }}
338347
key="webViewKey"
339348
style={webViewStyles}
@@ -363,6 +372,7 @@ class WKWebView extends React.Component {
363372
pagingEnabled={this.props.pagingEnabled}
364373
directionalLockEnabled={this.props.directionalLockEnabled}
365374
onNavigationResponse={this._onNavigationResponse}
375+
keyboardDismissMode={this.props.keyboardDismissMode}
366376
/>;
367377

368378
return (
@@ -379,7 +389,7 @@ class WKWebView extends React.Component {
379389
goForward = () => {
380390
UIManager.dispatchViewManagerCommand(
381391
this.getWebViewHandle(),
382-
UIManager.RCTWKWebView.Commands.goForward,
392+
this.getCRAWKWebView().Commands.goForward,
383393
null
384394
);
385395
};
@@ -390,7 +400,7 @@ class WKWebView extends React.Component {
390400
goBack = () => {
391401
UIManager.dispatchViewManagerCommand(
392402
this.getWebViewHandle(),
393-
UIManager.RCTWKWebView.Commands.goBack,
403+
this.getCRAWKWebView().Commands.goBack,
394404
null
395405
);
396406
};
@@ -416,7 +426,7 @@ class WKWebView extends React.Component {
416426
this.setState({ viewState: WebViewState.LOADING });
417427
UIManager.dispatchViewManagerCommand(
418428
this.getWebViewHandle(),
419-
UIManager.RCTWKWebView.Commands.reload,
429+
this.getCRAWKWebView().Commands.reload,
420430
null
421431
);
422432
};
@@ -427,7 +437,7 @@ class WKWebView extends React.Component {
427437
stopLoading = () => {
428438
UIManager.dispatchViewManagerCommand(
429439
this.getWebViewHandle(),
430-
UIManager.RCTWKWebView.Commands.stopLoading,
440+
this.getCRAWKWebView().Commands.stopLoading,
431441
null
432442
)
433443
};
@@ -445,7 +455,7 @@ class WKWebView extends React.Component {
445455
postMessage = (data) => {
446456
UIManager.dispatchViewManagerCommand(
447457
this.getWebViewHandle(),
448-
UIManager.RCTWKWebView.Commands.postMessage,
458+
this.getCRAWKWebView().Commands.postMessage,
449459
[String(data)]
450460
);
451461
};
@@ -464,6 +474,14 @@ class WKWebView extends React.Component {
464474
}
465475
};
466476

477+
getCRAWKWebView = () => {
478+
return (
479+
UIManager.getViewManagerConfig ?
480+
UIManager.getViewManagerConfig('CRAWKWebView') :
481+
UIManager.CRAWKWebView
482+
);
483+
};
484+
467485
/**
468486
* Returns the native webview node.
469487
*/
@@ -526,7 +544,7 @@ class WKWebView extends React.Component {
526544
}
527545
}
528546

529-
const RCTWKWebView = requireNativeComponent('RCTWKWebView', WKWebView, {
547+
const CRAWKWebView = requireNativeComponent('CRAWKWebView', WKWebView, {
530548
nativeOnly: {
531549
onLoadingStart: true,
532550
onLoadingError: true,

example/.babelrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"presets": ["react-native"]
2+
"presets": [
3+
"module:metro-react-native-babel-preset"
4+
]
35
}

example/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
"test": "jest"
88
},
99
"dependencies": {
10-
"react": "16.2.0",
11-
"react-native": "0.53.2",
10+
"metro-react-native-babel-preset": "^0.48.0",
1211
"prop-types": "15.6.0",
12+
"react": "16.5.0",
13+
"react-native": "0.57",
1314
"react-native-wkwebview-reborn": "file:../"
1415
},
1516
"devDependencies": {
@@ -19,4 +20,4 @@
1920
"jest": {
2021
"preset": "react-native"
2122
}
22-
}
23+
}

0 commit comments

Comments
 (0)