Skip to content

Commit c61ac23

Browse files
[webview_flutter_wkwebview] Adds support for WKNavigationAction.navigationType (#6863)
* add navigation type to navigation action * version bump and export * remove import * ios unit test * lint warning * formatting * add readme change to CHANGELOG * remove unused method * undo mocks change * last mocks change * mention pigeon dependency
1 parent 54fc206 commit c61ac23

17 files changed

+1303
-1173
lines changed

packages/webview_flutter/webview_flutter_wkwebview/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 3.0.1
2+
3+
* Adds support for retrieving navigation type with internal class.
4+
* Updates README with details on contributing.
5+
* Updates pigeon dev dependency to `4.2.13`.
6+
17
## 3.0.0
28

39
* **BREAKING CHANGE** Updates platform implementation to `2.0.0` release of

packages/webview_flutter/webview_flutter_wkwebview/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,23 @@ The Apple WKWebView implementation of [`webview_flutter`][1].
77
This package is [endorsed][2], which means you can simply use `webview_flutter`
88
normally. This package will be automatically included in your app when you do.
99

10+
## Contributing
11+
12+
This package uses [pigeon][3] to generate the communication layer between Flutter and the host
13+
platform (iOS). The communication interface is defined in the `pigeons/web_kit.dart`
14+
file. After editing the communication interface regenerate the communication layer by running
15+
`flutter pub run pigeon --input pigeons/web_kit.dart`.
16+
17+
Besides [pigeon][3] this package also uses [mockito][4] to generate mock objects for testing
18+
purposes. To generate the mock objects run the following command:
19+
```bash
20+
flutter pub run build_runner build --delete-conflicting-outputs
21+
```
22+
23+
If you would like to contribute to the plugin, check out our [contribution guide][5].
24+
1025
[1]: https://pub.dev/packages/webview_flutter
1126
[2]: https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin
27+
[3]: https://pub.dev/packages/pigeon
28+
[4]: https://pub.dev/packages/mockito
29+
[5]: https://github.com/flutter/plugins/blob/main/CONTRIBUTING.md

packages/webview_flutter/webview_flutter_wkwebview/example/ios/RunnerTests/FWFDataConvertersTests.m

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ - (void)testFWFWKUserScriptFromScriptData {
5959
- (void)testFWFWKNavigationActionDataFromNavigationAction {
6060
WKNavigationAction *mockNavigationAction = OCMClassMock([WKNavigationAction class]);
6161

62+
OCMStub([mockNavigationAction navigationType]).andReturn(WKNavigationTypeReload);
63+
6264
NSURLRequest *request =
6365
[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.flutter.dev/"]];
6466
OCMStub([mockNavigationAction request]).andReturn(request);
@@ -70,6 +72,7 @@ - (void)testFWFWKNavigationActionDataFromNavigationAction {
7072
FWFWKNavigationActionData *data =
7173
FWFWKNavigationActionDataFromNavigationAction(mockNavigationAction);
7274
XCTAssertNotNil(data);
75+
XCTAssertEqual(data.navigationType, FWFWKNavigationTypeReload);
7376
}
7477

7578
- (void)testFWFNSUrlRequestDataFromNSURLRequest {

packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.h

+9
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,13 @@ extern FWFNSKeyValueChangeKeyEnumData *FWFNSKeyValueChangeKeyEnumDataFromNSKeyVa
151151
*/
152152
extern FWFWKScriptMessageData *FWFWKScriptMessageDataFromWKScriptMessage(WKScriptMessage *message);
153153

154+
/**
155+
* Converts a WKNavigationType to an FWFWKNavigationType.
156+
*
157+
* @param type The object containing information to create a FWFWKNavigationType
158+
*
159+
* @return A FWFWKNavigationType.
160+
*/
161+
extern FWFWKNavigationType FWFWKNavigationTypeFromWKNavigationType(WKNavigationType type);
162+
154163
NS_ASSUME_NONNULL_END

packages/webview_flutter/webview_flutter_wkwebview/ios/Classes/FWFDataConverters.m

+19-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ WKAudiovisualMediaTypes FWFWKAudiovisualMediaTypeFromEnumData(
162162
WKNavigationAction *action) {
163163
return [FWFWKNavigationActionData
164164
makeWithRequest:FWFNSUrlRequestDataFromNSURLRequest(action.request)
165-
targetFrame:FWFWKFrameInfoDataFromWKFrameInfo(action.targetFrame)];
165+
targetFrame:FWFWKFrameInfoDataFromWKFrameInfo(action.targetFrame)
166+
navigationType:FWFWKNavigationTypeFromWKNavigationType(action.navigationType)];
166167
}
167168

168169
FWFNSUrlRequestData *FWFNSUrlRequestDataFromNSURLRequest(NSURLRequest *request) {
@@ -218,3 +219,20 @@ WKNavigationActionPolicy FWFWKNavigationActionPolicyFromEnumData(
218219
FWFWKScriptMessageData *FWFWKScriptMessageDataFromWKScriptMessage(WKScriptMessage *message) {
219220
return [FWFWKScriptMessageData makeWithName:message.name body:message.body];
220221
}
222+
223+
FWFWKNavigationType FWFWKNavigationTypeFromWKNavigationType(WKNavigationType type) {
224+
switch (type) {
225+
case WKNavigationTypeLinkActivated:
226+
return FWFWKNavigationTypeLinkActivated;
227+
case WKNavigationTypeFormSubmitted:
228+
return FWFWKNavigationTypeFormResubmitted;
229+
case WKNavigationTypeBackForward:
230+
return FWFWKNavigationTypeBackForward;
231+
case WKNavigationTypeReload:
232+
return FWFWKNavigationTypeReload;
233+
case WKNavigationTypeFormResubmitted:
234+
return FWFWKNavigationTypeFormResubmitted;
235+
case WKNavigationTypeOther:
236+
return FWFWKNavigationTypeOther;
237+
}
238+
}

0 commit comments

Comments
 (0)