Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[webview_flutter_wkwebview] Adds support for WKNavigationAction.navigationType #6863

Merged
merged 11 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.0.1

* Adds support for retrieving navigation type with internal class.
* Updates README with details on contributing.
* Updates pigeon dev dependency to `4.2.13`.

## 3.0.0

* **BREAKING CHANGE** Updates platform implementation to `2.0.0` release of
Expand Down
18 changes: 18 additions & 0 deletions packages/webview_flutter/webview_flutter_wkwebview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,23 @@ The Apple WKWebView implementation of [`webview_flutter`][1].
This package is [endorsed][2], which means you can simply use `webview_flutter`
normally. This package will be automatically included in your app when you do.

## Contributing

This package uses [pigeon][3] to generate the communication layer between Flutter and the host
platform (iOS). The communication interface is defined in the `pigeons/web_kit.dart`
file. After editing the communication interface regenerate the communication layer by running
`flutter pub run pigeon --input pigeons/web_kit.dart`.

Besides [pigeon][3] this package also uses [mockito][4] to generate mock objects for testing
purposes. To generate the mock objects run the following command:
```bash
flutter pub run build_runner build --delete-conflicting-outputs
```

If you would like to contribute to the plugin, check out our [contribution guide][5].

[1]: https://pub.dev/packages/webview_flutter
[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin
[3]: https://pub.dev/packages/pigeon
[4]: https://pub.dev/packages/mockito
[5]: https://github.com/flutter/plugins/blob/main/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ - (void)testFWFWKUserScriptFromScriptData {
- (void)testFWFWKNavigationActionDataFromNavigationAction {
WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]);

OCMStub([mockNavigationAction navigationType]).andReturn(WKNavigationTypeReload);

NSURLRequest *request =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev/"]];
OCMStub([mockNavigationAction request]).andReturn(request);
Expand All @@ -70,6 +72,7 @@ - (void)testFWFWKNavigationActionDataFromNavigationAction {
FWFWKNavigationActionData *data =
FWFWKNavigationActionDataFromNavigationAction(mockNavigationAction);
XCTAssertNotNil(data);
XCTAssertEqual(data.navigationType, FWFWKNavigationTypeReload);
}

- (void)testFWFNSUrlRequestDataFromNSURLRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,13 @@ extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyVa
*/
extern FWFWKScriptMessageData *FWFWKScriptMessageDataFromWKScriptMessage(WKScriptMessage *message);

/**
* Converts a WKNavigationType to an FWFWKNavigationType.
*
* @param type The object containing information to create a FWFWKNavigationType
*
* @return A FWFWKNavigationType.
*/
extern FWFWKNavigationType FWFWKNavigationTypeFromWKNavigationType(WKNavigationType type);

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData(
WKNavigationAction *action) {
return [FWFWKNavigationActionData
makeWithRequest:FWFNSUrlRequestDataFromNSURLRequest(action.request)
targetFrame:FWFWKFrameInfoDataFromWKFrameInfo(action.targetFrame)];
targetFrame:FWFWKFrameInfoDataFromWKFrameInfo(action.targetFrame)
navigationType:FWFWKNavigationTypeFromWKNavigationType(action.navigationType)];
}

FWFNSUrlRequestData *FWFNSUrlRequestDataFromNSURLRequest(NSURLRequest *request) {
Expand Down Expand Up @@ -218,3 +219,20 @@ WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(
FWFWKScriptMessageData *FWFWKScriptMessageDataFromWKScriptMessage(WKScriptMessage *message) {
return [FWFWKScriptMessageData makeWithName:message.name body:message.body];
}

FWFWKNavigationType FWFWKNavigationTypeFromWKNavigationType(WKNavigationType type) {
switch (type) {
case WKNavigationTypeLinkActivated:
return FWFWKNavigationTypeLinkActivated;
case WKNavigationTypeFormSubmitted:
return FWFWKNavigationTypeFormResubmitted;
case WKNavigationTypeBackForward:
return FWFWKNavigationTypeBackForward;
case WKNavigationTypeReload:
return FWFWKNavigationTypeReload;
case WKNavigationTypeFormResubmitted:
return FWFWKNavigationTypeFormResubmitted;
case WKNavigationTypeOther:
return FWFWKNavigationTypeOther;
}
}
Loading