# Use a platform API

How to get from a property or method in Apple's or Android's documentation to the key, value or `call` string this package takes. The package doesn't document each platform setting: the platform's own page does.

## 1\. Find the root

A root is the native object the setting or method belongs to. The class name in the platform's documentation tells you which one.

| Root | iOS class | Takes |
| --- | --- | --- |
| `configuration` | [`WKWebViewConfiguration`](<https://developer.apple.com/documentation/webkit/wkwebviewconfiguration>) | settings, `get` |
| `preferences` | [`WKPreferences`](<https://developer.apple.com/documentation/webkit/wkpreferences>) | settings, `get`, `call` |
| `webpagePreferences` | [`WKWebpagePreferences`](<https://developer.apple.com/documentation/webkit/wkwebpagepreferences>) | settings, `get`, `call` |
| `webView` | [`WKWebView`](<https://developer.apple.com/documentation/webkit/wkwebview>) | settings, `get`, `call` |
| `scrollView` | [`UIScrollView`](<https://developer.apple.com/documentation/uikit/uiscrollview>) | settings, `get`, `call` |
| `websiteDataStore` | [`WKWebsiteDataStore`](<https://developer.apple.com/documentation/webkit/wkwebsitedatastore>) | `get`, `call` |
| `httpCookieStore` | [`WKHTTPCookieStore`](<https://developer.apple.com/documentation/webkit/wkhttpcookiestore>) | `get`, `call` |

`configuration` is read once, when the WebView is created: a change [recreates the WebView](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/type-aliases/IOSSettings/#configuration>), and a `call` on it changes nothing.

| Root | Android class | Takes |
| --- | --- | --- |
| `settings` | [`WebSettings`](<https://developer.android.com/reference/android/webkit/WebSettings>), then [`WebSettingsCompat`](<https://developer.android.com/reference/androidx/webkit/WebSettingsCompat>) | settings, `get`, `call` |
| `webView` | [`WebView`](<https://developer.android.com/reference/android/webkit/WebView>) and its inherited `View` setters, then [`WebViewCompat`](<https://developer.android.com/reference/androidx/webkit/WebViewCompat>), then `CookieManager`'s `acceptThirdPartyCookies` | settings, `get`, `call` |
| `cookieManager` | [`CookieManager`](<https://developer.android.com/reference/android/webkit/CookieManager>) | `get`, `call` |
| `webStorage` | [`WebStorage`](<https://developer.android.com/reference/android/webkit/WebStorage>) | `get`, `call` |

## 2\. Write a setting

On iOS the key is the property's name. On Android it is the setter's name without `set`.

| The platform's documentation | The prop |
| --- | --- |
| `WKWebView`, `allowsLinkPreview` | `ios={{ webView: { allowsLinkPreview: false } }}` |
| `UIScrollView`, `bounces` | `ios={{ scrollView: { bounces: false } }}` |
| `UIScrollView`, `contentOffset`, a `CGPoint` | `ios={{ scrollView: { contentOffset: { x: 0, y: 80 } } }}` |
| `WebSettings`, `setBuiltInZoomControls(boolean)` | `android={{ settings: { builtInZoomControls: false } }}` |
| `WebSettings`, `setTextZoom(int)` | `android={{ settings: { textZoom: 130 } }}` |

Keys the SDKs list appear in autocomplete, so a misspelled one doesn't compile. A key they lack, such as one a newer SDK added, goes under the root's `other`: `webView: { other: { someNewerProperty: true } }`, with the property's real name in place of `someNewerProperty`.

A boolean, number or string is passed as it is. An enum or option set is a number. [`IOSConstants`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/namespaces/IOSConstants/>) and [`AndroidConstants`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/namespaces/AndroidConstants/>) name the values of the classes they list; for another class's, such as `View`'s `overScrollMode`, use the number the platform's documentation gives. [`IOSSettings`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/type-aliases/IOSSettings/>) and [`AndroidSettings`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/type-aliases/AndroidSettings/>) list the other value types, the package's defaults for each root, and when a change applies.

```tsx
import { AndroidConstants, IOSConstants, WebView } from 'react-native-minimal-webview';

<WebView
  source={{ uri: 'https://example.com' }}
  style={{ flex: 1 }}
  ios={{
    // WKWebViewConfiguration.mediaTypesRequiringUserActionForPlayback, a WKAudiovisualMediaTypes
    configuration: {
      mediaTypesRequiringUserActionForPlayback: IOSConstants.AudiovisualMediaTypes.none,
    },
  }}
  android={{
    // WebSettings.setMixedContentMode(int)
    settings: { mixedContentMode: AndroidConstants.WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE },
  }}
/>;
```

## 3\. Read a value

A `get` or `call` string names one platform's member. Both platforms have a `webView` root, with different properties and methods, so pick the string by `Platform.OS`.

[`get`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/type-aliases/WebViewRef/#get>) takes `root.key`. On iOS the key is the property's name, on Android the getter's name without `get` or `is`: `WebSettings.getTextZoom()` is `get('settings.textZoom')`.

## 4\. Call a method

[`call`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/type-aliases/WebViewRef/#call>) takes `root.method` and the arguments in order.

On Android the method is the Java method's name: `WebView.clearCache(boolean)` is `call('webView.clearCache', [true])`.

On iOS it is the Objective-C selector, which Apple's page shows once you switch its language from Swift to Objective-C. The selector is every argument label of the declaration, each with its colon, joined:

| Objective-C declaration | The call |
| --- | --- |
| `- (void)flashScrollIndicators;` | `call('scrollView.flashScrollIndicators')` |
| `- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated;` | `call('scrollView.setContentOffset:animated:', [{ x: 0, y: 0 }, true])` |
| `- (void)getAllCookies:(void (^)(NSArray<NSHTTPCookie *> *))completionHandler;` | `call('httpCookieStore.getAllCookies:')` |

A method with no argument has no colon. A trailing completion handler keeps its label in the selector but has no entry in the arguments: the call resolves with what it reports, for the WebKit methods whose handlers [`call`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/type-aliases/WebViewRef/#call>) can await (one in the package's SDK headers that reports an object, an error or an integer). On Android a trailing `ValueCallback` works the same way.

The Swift name doesn't work, and often differs: Swift's `takeSnapshot(with:completionHandler:)` is the selector `takeSnapshotWithConfiguration:completionHandler:`.

[`call`](<https://rasmuskard.github.io/react-native-minimal-webview/typescript/react-native-minimal-webview/type-aliases/WebViewRef/#call>) lists how each argument type is written (a struct, an `NSDate`, an `NSSet`, a cookie), what a result converts to, and the methods the core keeps to itself. Unlike a setting, a call can crash the app: on iOS with an object argument of the wrong class, on Android with a `null` listener or callback other than the trailing `ValueCallback`.

## When this isn't enough

A method that takes another object, a delegate or client callback, and anything that keeps native state need a [native hook](<https://rasmuskard.github.io/react-native-minimal-webview/guides/native-hooks/index.md#when-to-write-one>).
