Allow custom menu items for selection menu (#2101)

remove unused vars

use gesture handler

change callback name, pass selected text back

do not use deprecate setTarget

do not call super on methodSignatureForSelector twice

add checks for custom menu items and callback

make custom params optional

add custom menu items outside of initWithFrame

require key and label for menuItems

fix typo
This commit is contained in:
Scott Batson
2021-10-08 08:38:43 +02:00
committed by GitHub
parent af418ecae4
commit e1fc730eed
6 changed files with 172 additions and 0 deletions
+24
View File
@@ -1439,6 +1439,30 @@ Example:
```javascript
<WebView forceDarkOn={false} />
### `menuItems`
An array of custom menu item objects that will be appended to the UIMenu that appears when selecting text (will appear after 'Copy' and 'Share...'). Used in tandem with `onCustomMenuSelection`
Example:
```javascript
<WebView menuItems={[{ label: 'Tweet', key: 'tweet' }, { label: 'Save for later', key: 'saveForLater' }]} />
```
### `onCustomMenuSelection`
Function called when a custom menu item is selected. It receives a Native event, which includes three custom keys: `label`, `key` and `selectedText`.
```javascript
<WebView
menuItems={[{ label: 'Tweet', key: 'tweet', { label: 'Save for later', key: 'saveForLater' }]}
onCustomMenuSelection={(webViewEvent) => {
const { label } = webViewEvent.nativeEvent; // The name of the menu item, i.e. 'Tweet'
const { key } = webViewEvent.nativeEvent; // The key of the menu item, i.e. 'tweet'
const { selectedText } = webViewEvent.nativeEvent; // Text highlighted
}}
/>
```
### `basicAuthCredential`