Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Salakar committed Nov 28, 2018
2 parents 6d70dea + 48230e4 commit 9d2bba9
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 8 deletions.
23 changes: 23 additions & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ This document lays out the current public properties and methods for the React N
- [`allowFileAccess`](Reference.md#allowFileAccess)
- [`saveFormDataDisabled`](Reference.md#saveFormDataDisabled)
- [`enableCache`](Reference.md#enableCache)
- [`pagingEnabled`](Reference.md#pagingEnabled)
- [`allowsLinkPreview`](Reference.md#allowsLinkPreview)

## Methods Index

Expand Down Expand Up @@ -528,6 +530,27 @@ Sets whether WebView & WKWebView should use browser caching.
| ------- | -------- | ------- |
| boolean | No | true |

---

### `pagingEnabled`

If the value of this property is true, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls. The default value is false.

| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |

---

### `allowsLinkPreview`

A Boolean value that determines whether pressing on a link displays a preview of the destination for the link. In iOS this property is available on devices that support 3D Touch. In iOS 10 and later, the default value is true; before that, the default value is false.

| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | iOS |


## Methods

### `extraNativeComponentConfig()`
Expand Down
2 changes: 2 additions & 0 deletions ios/RNCWKWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
@property (nonatomic, assign) BOOL messagingEnabled;
@property (nonatomic, copy) NSString *injectedJavaScript;
@property (nonatomic, assign) BOOL scrollEnabled;
@property (nonatomic, assign) BOOL pagingEnabled;
@property (nonatomic, assign) CGFloat decelerationRate;
@property (nonatomic, assign) BOOL allowsInlineMediaPlayback;
@property (nonatomic, assign) BOOL bounces;
Expand All @@ -39,6 +40,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
@property (nonatomic, assign) BOOL allowsBackForwardNavigationGestures;
@property (nonatomic, copy) NSString *userAgent;
@property (nonatomic, assign) BOOL enableCache;
@property (nonatomic, assign) BOOL allowsLinkPreview;

- (void)postMessage:(NSString *)message;
- (void)injectJavaScript:(NSString *)script;
Expand Down
9 changes: 6 additions & 3 deletions ios/RNCWKWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ - (instancetype)initWithFrame:(CGRect)frame
_automaticallyAdjustContentInsets = YES;
_contentInset = UIEdgeInsetsZero;
}

// Workaround for a keyboard dismissal bug present in iOS 12
// https://openradar.appspot.com/radar?id=5018321736957952
if (@available(iOS 12.0, *)) {
Expand Down Expand Up @@ -114,9 +114,12 @@ - (void)didMoveToWindow
_webView.UIDelegate = self;
_webView.navigationDelegate = self;
_webView.scrollView.scrollEnabled = _scrollEnabled;
_webView.scrollView.pagingEnabled = _pagingEnabled;
_webView.scrollView.bounces = _bounces;
_webView.allowsLinkPreview = _allowsLinkPreview;
[_webView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil];
_webView.allowsBackForwardNavigationGestures = _allowsBackForwardNavigationGestures;

if (_userAgent) {
_webView.customUserAgent = _userAgent;
}
Expand All @@ -140,7 +143,7 @@ - (void)removeFromSuperview
[_webView removeFromSuperview];
_webView = nil;
}

[super removeFromSuperview];
}

Expand All @@ -149,7 +152,7 @@ -(void)keyboardWillHide
keyboardTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(keyboardDisplacementFix) userInfo:nil repeats:false];
[[NSRunLoop mainRunLoop] addTimer:keyboardTimer forMode:NSRunLoopCommonModes];
}

-(void)keyboardWillShow
{
if (keyboardTimer != nil) {
Expand Down
2 changes: 2 additions & 0 deletions ios/RNCWKWebViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsBackForwardNavigationGestures, BOOL)
RCT_EXPORT_VIEW_PROPERTY(pagingEnabled, BOOL)
RCT_EXPORT_VIEW_PROPERTY(userAgent, NSString)
RCT_EXPORT_VIEW_PROPERTY(enableCache, BOOL)
RCT_EXPORT_VIEW_PROPERTY(allowsLinkPreview, BOOL)

/**
* Expose methods to enable messaging the webview.
Expand Down
2 changes: 2 additions & 0 deletions js/WebView.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
injectedJavaScript={this.props.injectedJavaScript}
bounces={this.props.bounces}
scrollEnabled={this.props.scrollEnabled}
pagingEnabled={this.props.pagingEnabled}
decelerationRate={decelerationRate}
contentInset={this.props.contentInset}
automaticallyAdjustContentInsets={
Expand All @@ -291,6 +292,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
this.props.mediaPlaybackRequiresUserAction
}
dataDetectorTypes={this.props.dataDetectorTypes}
allowsLinkPreview={this.props.allowsLinkPreview}
{...nativeConfig.props}
/>
);
Expand Down
18 changes: 18 additions & 0 deletions js/WebViewTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ export type IOSWebViewProps = $ReadOnly<{|
*/
scrollEnabled?: ?boolean,

/**
* If the value of this property is true, the scroll view stops on multiples
* of the scroll view’s bounds when the user scrolls.
* The default value is false.
* @platform ios
*/
pagingEnabled?: ?boolean,

/**
* The amount by which the web view content is inset from the edges of
* the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
Expand Down Expand Up @@ -233,6 +241,16 @@ export type IOSWebViewProps = $ReadOnly<{|
* The custom user agent string.
*/
userAgent?: ?string,

/**
* A Boolean value that determines whether pressing on a link
* displays a preview of the destination for the link.
*
* This property is available on devices that support 3D Touch.
* In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
* @platform ios
*/
allowsLinkPreview?: ?boolean,
|}>;

export type AndroidWebViewProps = $ReadOnly<{|
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Thibault Malbranche <malbranche.thibault@gmail.com>"
],
"license": "MIT",
"version": "2.10.0",
"version": "2.13.0",
"homepage": "https://github.com/react-native-community/react-native-webview#readme",
"scripts": {
"test:ios:flow": "flow check",
Expand Down
33 changes: 29 additions & 4 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export interface WebViewNativeEvent {
readonly canGoForward: boolean;
}

export interface WebViewIOSLoadRequestEvent extends WebViewNativeEvent {
target: number;
lockIdentifier: number;
navigationType: "click" | "formsubmit" | "backforward" | "reload" | "formresubmit" | "other";
}

export interface WebViewProgressEvent extends WebViewNativeEvent {
readonly progress: number;
}
Expand Down Expand Up @@ -145,6 +151,14 @@ export interface IOSWebViewProps {
*/
scrollEnabled?: boolean;

/**
* If the value of this property is true, the scroll view stops on multiples
* of the scroll view’s bounds when the user scrolls.
* The default value is false.
* @platform ios
*/
pagingEnabled?: boolean,

/**
* The amount by which the web view content is inset from the edges of
* the scroll view. Defaults to {top: 0, left: 0, bottom: 0, right: 0}.
Expand Down Expand Up @@ -182,7 +196,7 @@ export interface IOSWebViewProps {
* to stop loading.
* @platform ios
*/
onShouldStartLoadWithRequest?: (event: WebViewNativeEvent) => any;
onShouldStartLoadWithRequest?: (event: WebViewIOSLoadRequestEvent) => any;

/**
* Boolean that determines whether HTML5 videos play inline or use the
Expand All @@ -202,7 +216,17 @@ export interface IOSWebViewProps {
/**
* If true, this will be able horizontal swipe gestures when using the WKWebView. The default value is `false`.
*/
allowsBackForwardNavigationGestures?: boolean
allowsBackForwardNavigationGestures?: boolean;

/**
* A Boolean value that determines whether pressing on a link
* displays a preview of the destination for the link.
*
* This property is available on devices that support 3D Touch.
* In iOS 10 and later, the default value is `true`; before that, the default value is `false`.
* @platform ios
*/
allowsLinkPreview?: boolean;
}

export interface AndroidWebViewProps {
Expand Down Expand Up @@ -374,7 +398,7 @@ export interface WebViewSharedProps extends ViewProps, IOSWebViewProps, AndroidW
* Boolean value that forces the `WebView` to show the loading view
* on the first load.
*/
startInLoadingState?: string;
startInLoadingState?: boolean;

/**
* Set this to provide JavaScript that will be injected into the web page
Expand Down Expand Up @@ -421,5 +445,6 @@ export class WebView extends Component<WebViewSharedProps> {
public goBack: () => void;
public reload: () => void;
public stopLoading: () => void;
public injectJavaScript: (js: string) => void
public postMessage: (msg: string) => void;
public injectJavaScript: (js: string) => void;
}

0 comments on commit 9d2bba9

Please sign in to comment.