Skip to content

Commit 4e0cf9c

Browse files
feat(ios): Add textInteractionEnabled prop (react-native-webview#2252)
1 parent e5dbc5d commit 4e0cf9c

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

apple/RNCWebView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ typedef enum RNCWebViewPermissionGrantType : NSUInteger {
9292
@property (nonatomic, assign) BOOL limitsNavigationsToAppBoundDomains;
9393
#endif
9494

95+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140500 /* iOS 14.5 */
96+
@property (nonatomic, assign) BOOL textInteractionEnabled;
97+
#endif
98+
9599
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 /* iOS 15 */
96100
@property (nonatomic, assign) RNCWebViewPermissionGrantType mediaCapturePermissionGrantType;
97101
#endif

apple/RNCWebView.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ - (WKWebViewConfiguration *)setUpWkWebViewConfig
335335
[prefs setValue:@TRUE forKey:@"javaScriptCanOpenWindowsAutomatically"];
336336
_prefsUsed = YES;
337337
}
338+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140500 /* iOS 14.5 */
339+
if (@available(iOS 14.5, *)) {
340+
if (!_textInteractionEnabled) {
341+
[prefs setValue:@FALSE forKey:@"textInteractionEnabled"];
342+
_prefsUsed = YES;
343+
}
344+
}
345+
#endif
338346
if (_prefsUsed) {
339347
wkWebViewConfig.preferences = prefs;
340348
}

apple/RNCWebViewManager.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ - (RCTUIView *)view
103103
RCT_EXPORT_VIEW_PROPERTY(limitsNavigationsToAppBoundDomains, BOOL)
104104
#endif
105105

106+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140500 /* iOS 14.5 */
107+
RCT_EXPORT_VIEW_PROPERTY(textInteractionEnabled, BOOL)
108+
#endif
109+
106110
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 /* iOS 15 */
107111
RCT_EXPORT_VIEW_PROPERTY(mediaCapturePermissionGrantType, RNCWebViewPermissionGrantType)
108112
#endif

docs/Reference.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ This document lays out the current public properties and methods for the React N
7777
- [`ignoreSilentHardwareSwitch`](Reference.md#ignoreSilentHardwareSwitch)
7878
- [`onFileDownload`](Reference.md#onFileDownload)
7979
- [`limitsNavigationsToAppBoundDomains`](Reference.md#limitsNavigationsToAppBoundDomains)
80+
- [`textInteractionEnabled`](Reference.md#textInteractionEnabled)
8081
- [`mediaCapturePermissionGrantType`](Reference.md#mediaCapturePermissionGrantType)
8182
- [`autoManageStatusBarEnabled`](Reference.md#autoManageStatusBarEnabled)
8283
- [`setSupportMultipleWindows`](Reference.md#setSupportMultipleWindows)
@@ -1377,6 +1378,24 @@ Example:
13771378

13781379
---
13791380

1381+
### `textInteractionEnabled`[](#props-index)<!-- Link generated with jump2header -->
1382+
1383+
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.
1384+
1385+
Defaults to true.
1386+
1387+
| Type | Required | Platform |
1388+
| ------- | -------- | -------- |
1389+
| boolean | No | iOS |
1390+
1391+
Example:
1392+
1393+
```jsx
1394+
<WebView textInteractionEnabled={false} />
1395+
```
1396+
1397+
---
1398+
13801399
### `mediaCapturePermissionGrantType`
13811400

13821401
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.

src/WebView.ios.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class WebView extends React.Component<IOSWebViewProps, State> {
6060
cacheEnabled: true,
6161
originWhitelist: defaultOriginWhitelist,
6262
useSharedProcessPool: true,
63+
textInteractionEnabled: true,
6364
};
6465

6566
static isFileUploadSupported = async () => {

src/WebViewTypes.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ export interface IOSNativeWebViewProps extends CommonNativeWebViewProps {
370370
injectedJavaScriptBeforeContentLoadedForMainFrameOnly?: boolean;
371371
onFileDownload?: (event: FileDownloadEvent) => void;
372372
limitsNavigationsToAppBoundDomains?: boolean;
373+
textInteractionEnabled?: boolean;
373374
mediaCapturePermissionGrantType?: MediaCapturePermissionGrantType;
374375
}
375376

@@ -672,6 +673,15 @@ export interface IOSWebViewProps extends WebViewSharedProps {
672673
*/
673674
limitsNavigationsToAppBoundDomains?: boolean;
674675

676+
/**
677+
* If false indicates to WebKit that a WKWebView will not interact with text, thus
678+
* not showing a text selection loop. Only applicable for iOS 14.5 or greater.
679+
*
680+
* Defaults to true.
681+
* @platform ios
682+
*/
683+
textInteractionEnabled?: boolean;
684+
675685
/**
676686
* This property specifies how to handle media capture permission requests.
677687
* Defaults to `prompt`, resulting in the user being prompted repeatedly.

0 commit comments

Comments
 (0)