Skip to content

Commit

Permalink
feat(ios): Add textInteractionEnabled prop (#2252)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjan-Zuidema authored Jan 19, 2022
1 parent e5dbc5d commit 4e0cf9c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apple/RNCWebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ typedef enum RNCWebViewPermissionGrantType : NSUInteger {
@property (nonatomic, assign) BOOL limitsNavigationsToAppBoundDomains;
#endif

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140500 /* iOS 14.5 */
@property (nonatomic, assign) BOOL textInteractionEnabled;
#endif

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 /* iOS 15 */
@property (nonatomic, assign) RNCWebViewPermissionGrantType mediaCapturePermissionGrantType;
#endif
Expand Down
8 changes: 8 additions & 0 deletions apple/RNCWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,14 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
[prefs setValue:@TRUE forKey:@"javaScriptCanOpenWindowsAutomatically"];
_prefsUsed = YES;
}
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140500 /* iOS 14.5 */
if (@available(iOS 14.5, *)) {
if (!_textInteractionEnabled) {
[prefs setValue:@FALSE forKey:@"textInteractionEnabled"];
_prefsUsed = YES;
}
}
#endif
if (_prefsUsed) {
wkWebViewConfig.preferences = prefs;
}
Expand Down
4 changes: 4 additions & 0 deletions apple/RNCWebViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ - (RCTUIView *)view
RCT_EXPORT_VIEW_PROPERTY(limitsNavigationsToAppBoundDomains, BOOL)
#endif

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140500 /* iOS 14.5 */
RCT_EXPORT_VIEW_PROPERTY(textInteractionEnabled, BOOL)
#endif

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 /* iOS 15 */
RCT_EXPORT_VIEW_PROPERTY(mediaCapturePermissionGrantType, RNCWebViewPermissionGrantType)
#endif
Expand Down
19 changes: 19 additions & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ This document lays out the current public properties and methods for the React N
- [`ignoreSilentHardwareSwitch`](Reference.md#ignoreSilentHardwareSwitch)
- [`onFileDownload`](Reference.md#onFileDownload)
- [`limitsNavigationsToAppBoundDomains`](Reference.md#limitsNavigationsToAppBoundDomains)
- [`textInteractionEnabled`](Reference.md#textInteractionEnabled)
- [`mediaCapturePermissionGrantType`](Reference.md#mediaCapturePermissionGrantType)
- [`autoManageStatusBarEnabled`](Reference.md#autoManageStatusBarEnabled)
- [`setSupportMultipleWindows`](Reference.md#setSupportMultipleWindows)
Expand Down Expand Up @@ -1377,6 +1378,24 @@ Example:

---

### `textInteractionEnabled`[](#props-index)<!-- Link generated with jump2header -->

If false indicates to WebKit that a WKWebView will not interact with text, thus not showing a text selection loop. Only applicable for iOS 14.5 or greater.

Defaults to true.

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

Example:

```jsx
<WebView textInteractionEnabled={false} />
```

---

### `mediaCapturePermissionGrantType`

This property specifies how to handle media capture permission requests. Defaults to `prompt`, resulting in the user being prompted repeatedly. Available on iOS 15 and later.
Expand Down
1 change: 1 addition & 0 deletions src/WebView.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class WebView extends React.Component<IOSWebViewProps, State> {
cacheEnabled: true,
originWhitelist: defaultOriginWhitelist,
useSharedProcessPool: true,
textInteractionEnabled: true,
};

static isFileUploadSupported = async () => {
Expand Down
10 changes: 10 additions & 0 deletions src/WebViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
onFileDownload?: (event: FileDownloadEvent) => void;
limitsNavigationsToAppBoundDomains?: boolean;
textInteractionEnabled?: boolean;
mediaCapturePermissionGrantType?: MediaCapturePermissionGrantType;
}

Expand Down Expand Up @@ -672,6 +673,15 @@ export interface IOSWebViewProps extends WebViewSharedProps {
*/
limitsNavigationsToAppBoundDomains?: boolean;

/**
* If false indicates to WebKit that a WKWebView will not interact with text, thus
* not showing a text selection loop. Only applicable for iOS 14.5 or greater.
*
* Defaults to true.
* @platform ios
*/
textInteractionEnabled?: boolean;

/**
* This property specifies how to handle media capture permission requests.
* Defaults to `prompt`, resulting in the user being prompted repeatedly.
Expand Down

0 comments on commit 4e0cf9c

Please sign in to comment.