Skip to content

Commit

Permalink
feat(ios): Cookie sync improvements (react-native-webview#2535)
Browse files Browse the repository at this point in the history
commit 70e84de
Author: semantic-release-bot <semantic-release-bot@martynus.net>
Date:   Wed Nov 23 01:04:51 2022 +0000

    chore(release): 11.24.0 [skip ci]

    # [11.24.0](react-native-webview/react-native-webview@v11.23.1...v11.24.0) (2022-11-23)

    ### Features

    * **ios:** Cookie sync improvements ([react-native-webview#2535](react-native-webview#2535)) ([4ac0d74](react-native-webview@4ac0d74))

commit 4ac0d74
Author: Matias Korhonen <matias.korhonen@kaikuhealth.com>
Date:   Wed Nov 23 03:03:21 2022 +0200

    feat(ios): Cookie sync improvements (react-native-webview#2535)

commit a5e2a9f
Author: Handschrift <privacy.mtehw@aleeas.com>
Date:   Wed Nov 23 00:11:43 2022 +0000

    chore(docs): Add information that custom menu items are only available for iOS (react-native-webview#2748)

commit d6af98f
Author: Caleb Clarke <TheAlmightyBob@users.noreply.github.com>
Date:   Wed Nov 9 12:39:52 2022 -0800

    chore(ci): Update React Native to fix Android build (react-native-webview#2734)

    See facebook/react-native#35210
  • Loading branch information
sunnylqm committed Nov 23, 2022
1 parent 8fd9118 commit d8c454b
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
30 changes: 19 additions & 11 deletions apple/RNCWebView.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ - (void)scrollWheel:(NSEvent *)theEvent {
@end
#endif // TARGET_OS_OSX

@interface RNCWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler,
@interface RNCWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, WKHTTPCookieStoreObserver,
#if !TARGET_OS_OSX
UIScrollViewDelegate,
#endif // !TARGET_OS_OSX
Expand Down Expand Up @@ -235,6 +235,9 @@ - (void)startLongPress:(UILongPressGestureRecognizer *)pressSender
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (@available(iOS 11.0, *)) {
[self.webView.configuration.websiteDataStore.httpCookieStore removeObserver:self];
}
}

- (void)tappedMenuItem:(NSString *)eventType
Expand Down Expand Up @@ -1351,23 +1354,26 @@ -(void)appWillResignActive
*/
- (void)webView:(WKWebView *)webView
didFinishNavigation:(WKNavigation *)navigation
{
if (_ignoreSilentHardwareSwitch) {
[self forceIgnoreSilentHardwareSwitch:true];
}

if (_onLoadingFinish) {
_onLoadingFinish([self baseEvent]);
}
}

- (void)cookiesDidChangeInCookieStore:(WKHTTPCookieStore *)cookieStore
{
if(_sharedCookiesEnabled && @available(iOS 11.0, *)) {
// Write all cookies from WKWebView back to sharedHTTPCookieStorage
[webView.configuration.websiteDataStore.httpCookieStore getAllCookies:^(NSArray* cookies) {
[cookieStore getAllCookies:^(NSArray* cookies) {
for (NSHTTPCookie *cookie in cookies) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie];
}
}];
}

if (_ignoreSilentHardwareSwitch) {
[self forceIgnoreSilentHardwareSwitch:true];
}

if (_onLoadingFinish) {
_onLoadingFinish([self baseEvent]);
}
}

- (void)injectJavaScript:(NSString *)script
Expand Down Expand Up @@ -1584,7 +1590,9 @@ - (void)resetupScripts:(WKWebViewConfiguration *)wkWebViewConfig {
if(!_incognito && !_cacheEnabled) {
wkWebViewConfig.websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
}
[self syncCookiesToWebView:nil];
[self syncCookiesToWebView:^{
[wkWebViewConfig.websiteDataStore.httpCookieStore addObserver:self];
}];
} else {
NSMutableString *script = [NSMutableString string];

Expand Down
8 changes: 8 additions & 0 deletions docs/Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,10 @@ Example:

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`

| Type | Required | Platform |
| ------------------------------------------------------------------ | -------- | -------- |
| array of objects: {label: string, key: string} | No | iOS |

Example:

```javascript
Expand All @@ -1553,6 +1557,10 @@ Example:

Function called when a custom menu item is selected. It receives a Native event, which includes three custom keys: `label`, `key` and `selectedText`.

| Type | Required | Platform |
| ------------------------------------------------------------------ | -------- | -------- |
| function | No | iOS |

```javascript
<WebView
menuItems={[{ label: 'Tweet', key: 'tweet' }, { label: 'Save for later', key: 'saveForLater' }]}
Expand Down
8 changes: 8 additions & 0 deletions docs/Reference.portuguese.md
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,10 @@ Exemplo:

Uma matriz de objetos de itens de menu personalizados que serão anexados ao UIMenu que aparece ao selecionar o texto (aparecerá após 'Copiar' e 'Compartilhar...'). Usado em conjunto com `onCustomMenuSelection`

| Tipo | Requerido | Plataforma |
| ------------------------------------------------------------------ | -------- | -------- |
| array of objects: {label: string, key: string} | Não | iOS |

Exemplo:

```javascript
Expand All @@ -1512,6 +1516,10 @@ Exemplo:

Função chamada quando um item de menu personalizado é selecionado. Ele recebe um evento Nativo, que inclui três chaves personalizadas: `label`, `key` e `selectedText`.

| Tipo | Requerido | Plataforma |
| ------------------------------------------------------------------ | -------- | -------- |
| function | Não | iOS |

```javascript
<WebView
menuItems={[{ label: 'Tweet', key: 'tweet' }, { label: 'Guardar para depois', key: 'saveForLater' }]}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"Thibault Malbranche <malbranche.thibault@gmail.com>"
],
"license": "MIT",
"version": "11.23.1",
"version": "11.24.0",
"homepage": "https://github.com/react-native-webview/react-native-webview#readme",
"scripts": {
"android": "react-native run-android",
Expand Down Expand Up @@ -60,7 +60,7 @@
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.67.0",
"react": "17.0.2",
"react-native": "0.68.2",
"react-native": "0.68.5",
"react-native-macos": "0.66.57",
"react-native-test-app": "1.5.0",
"react-native-windows": "0.68.4",
Expand Down
2 changes: 2 additions & 0 deletions src/WebViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ export interface IOSWebViewProps extends WebViewSharedProps {
/**
* An array of objects which will be added to the UIMenu controller when selecting text.
* These will appear after a long press to select text.
* @platform ios
*/
menuItems?: WebViewCustomMenuItems[];

Expand All @@ -759,6 +760,7 @@ export interface IOSWebViewProps extends WebViewSharedProps {
* It passes a WebViewEvent with a `nativeEvent`, where custom keys are passed:
* `customMenuKey`: the string of the menu item
* `selectedText`: the text selected on the document
* @platform ios
*/
onCustomMenuSelection?: (event: WebViewEvent) => void;
}
Expand Down
31 changes: 24 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11143,6 +11143,13 @@ promise@^8.0.3:
dependencies:
asap "~2.0.6"

promise@^8.2.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/promise/-/promise-8.3.0.tgz#8cb333d1edeb61ef23869fbb8a4ea0279ab60e0a"
integrity sha512-rZPNPKTOYVNEEKFaq1HqTgOwZD+4/YHS5ukLzQCypkj+OkYx7iv0mA91lJlpPPZ8vMau3IIGj5Qlwrx+8iiSmg==
dependencies:
asap "~2.0.6"

prompts@^2.0.1, prompts@^2.4.0, prompts@^2.4.1:
version "2.4.2"
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.2.tgz#7b57e73b3a48029ad10ebd44f74b01722a4cb069"
Expand Down Expand Up @@ -11352,7 +11359,7 @@ react-is@^16.13.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

react-native-codegen@*, react-native-codegen@^0.0.17:
react-native-codegen@*:
version "0.0.17"
resolved "https://registry.yarnpkg.com/react-native-codegen/-/react-native-codegen-0.0.17.tgz#83fb814d94061cbd46667f510d2ddba35ffb50ac"
integrity sha512-7GIEUmAemH9uWwB6iYXNNsPoPgH06pxzGRmdBzK98TgFBdYJZ7CBuZFPMe4jmHQTPOkQazKZ/w5O6/71JBixmw==
Expand All @@ -11372,6 +11379,16 @@ react-native-codegen@^0.0.13:
jscodeshift "^0.13.1"
nullthrows "^1.1.1"

react-native-codegen@^0.0.18:
version "0.0.18"
resolved "https://registry.yarnpkg.com/react-native-codegen/-/react-native-codegen-0.0.18.tgz#99d6623d65292e8ce3fdb1d133a358caaa2145e7"
integrity sha512-XPI9aVsFy3dvgDZvyGWrFnknNiyb22kg5nHgxa0vjWTH9ENLBgVRZt9A64xHZ8BYihH+gl0p/1JNOCIEUzRPBg==
dependencies:
"@babel/parser" "^7.14.0"
flow-parser "^0.121.0"
jscodeshift "^0.13.1"
nullthrows "^1.1.1"

react-native-codegen@^0.0.7:
version "0.0.7"
resolved "https://registry.yarnpkg.com/react-native-codegen/-/react-native-codegen-0.0.7.tgz#86651c5c5fec67a8077ef7f4e36f7ed459043e14"
Expand Down Expand Up @@ -11485,10 +11502,10 @@ react-native-windows@0.68.4:
whatwg-fetch "^3.0.0"
ws "^6.1.4"

react-native@0.68.2:
version "0.68.2"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.68.2.tgz#07547cd31bb9335a7fa4135cfbdc24e067142585"
integrity sha512-qNMz+mdIirCEmlrhapAtAG+SWVx6MAiSfCbFNhfHqiqu1xw1OKXdzIrjaBEPihRC2pcORCoCHduHGQe/Pz9Yuw==
react-native@0.68.5:
version "0.68.5"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.68.5.tgz#8ba7389e00b757c59b6ea23bf38303d52367d155"
integrity sha512-t3kiQ/gumFV+0r/NRSIGtYxanjY4da0utFqHgkMcRPJVwXFWC0Fr8YiOeRGYO1dp8EfrSsOjtfWic/inqVYlbQ==
dependencies:
"@jest/create-cache-key-function" "^27.0.1"
"@react-native-community/cli" "^7.0.3"
Expand All @@ -11510,9 +11527,9 @@ react-native@0.68.2:
metro-source-map "0.67.0"
nullthrows "^1.1.1"
pretty-format "^26.5.2"
promise "^8.0.3"
promise "^8.2.0"
react-devtools-core "^4.23.0"
react-native-codegen "^0.0.17"
react-native-codegen "^0.0.18"
react-native-gradle-plugin "^0.0.6"
react-refresh "^0.4.0"
react-shallow-renderer "16.14.1"
Expand Down

0 comments on commit d8c454b

Please sign in to comment.